Skip to content
Snippets Groups Projects
Commit 1a5c7f3f authored by André Anjos's avatar André Anjos :speech_balloon:
Browse files

[scripts/create] Implement --pip-extras option to allow the user to install...

[scripts/create] Implement --pip-extras option to allow the user to install extra pip-installable packages on every created environment
parent 021bae58
No related branches found
No related tags found
1 merge request!194Allows extra pip-installable packages to be installed in every newly created environment
...@@ -3,10 +3,12 @@ ...@@ -3,10 +3,12 @@
import os import os
import sys import sys
import subprocess
import click import click
import yaml import yaml
from ..config import read_config
from ..bootstrap import set_environment from ..bootstrap import set_environment
from ..build import conda_create from ..build import conda_create
from ..build import make_conda_config from ..build import make_conda_config
...@@ -23,6 +25,14 @@ from . import bdt ...@@ -23,6 +25,14 @@ from . import bdt
logger = get_logger(__name__) logger = get_logger(__name__)
def _uniq(seq):
"""Fast order preserving uniq() function for Python lists"""
seen = set()
seen_add = seen.add
return [x for x in seq if not (x in seen or seen_add(x))]
@click.command( @click.command(
epilog=""" epilog="""
Examples: Examples:
...@@ -55,8 +65,23 @@ Examples: ...@@ -55,8 +65,23 @@ Examples:
enable debug printing. Equivalent conda commands you can execute on the enable debug printing. Equivalent conda commands you can execute on the
shell will be printed: shell will be printed:
$ bdt create -vvv --dry-run myenv $ bdt create -vvv --dry-run myenv
5. You can use the option `--pip-extras` to force the installation of extra
Python packages that are useful in your development environment. By default
we do not install anything, but you may configure this via this flag, or
through the configuration file option `create/pip_extras` to do so, as
explained in our Setup subsection of the Installation manual. To use this
flag on the command-line, specify one pip-installable package each time:
$ bdt create -vvv --pip-extras=ipdb --pip-extras=mr.developer myenv
Using this option **adds** to what is available in the configuration file.
So, if your configuration file already contains ``ipdb`` and you wish to
install ``mr.developer`` as a plus, then just specify
``--pip-extras=mr.developer``.
""" """
) )
@click.argument("name") @click.argument("name")
...@@ -143,6 +168,15 @@ Examples: ...@@ -143,6 +168,15 @@ Examples:
"(combine with the verbosity flags - e.g. ``-vvv``) to enable " "(combine with the verbosity flags - e.g. ``-vvv``) to enable "
"printing to help you understand what will be done", "printing to help you understand what will be done",
) )
@click.option(
"-x",
"--pip-extras",
multiple=True,
default=[],
help="Using pip, installs this additional list of dependencies to "
"created environments. Pip installation happens after the base conda "
"install (defaults, if any, are listed in ~/.bdtrc)",
)
@verbosity_option() @verbosity_option()
@bdt.raise_on_error @bdt.raise_on_error
def create( def create(
...@@ -159,6 +193,7 @@ def create( ...@@ -159,6 +193,7 @@ def create(
private, private,
stable, stable,
dry_run, dry_run,
pip_extras,
): ):
"""Creates a development environment for a recipe. """Creates a development environment for a recipe.
...@@ -231,4 +266,18 @@ def create( ...@@ -231,4 +266,18 @@ def create(
# when creating a local development environment, remove the always_yes option # when creating a local development environment, remove the always_yes option
del condarc_options["always_yes"] del condarc_options["always_yes"]
conda_create(conda, name, overwrite, condarc_options, deps, dry_run, use_local) conda_create(conda, name, overwrite, condarc_options, deps, dry_run, use_local)
echo_normal('Execute on your shell: "conda activate %s"' % name)
# part 2: pip-install everything listed in pip-extras
# mix-in stuff from ~/.bdtrc and command-line
config = read_config()
pip_extras_config = []
if "create" in config:
pip_extras_config = config["create"].get("pip_extras", "").split()
pip_extras = _uniq(pip_extras_config + list(pip_extras))
logger.info("Pip-installing: %s", pip_extras)
cmd = [conda, "run", "--live-stream", "--name", name, "pip", "install"]
cmd += pip_extras
subprocess.run(cmd, check=True, bufsize=1)
echo_normal(f">>> Execute on your shell: \"conda activate {name}\"")
...@@ -34,6 +34,7 @@ installed, you can use these tools within the created environment like this: ...@@ -34,6 +34,7 @@ installed, you can use these tools within the created environment like this:
(bdt) $ bdt --help (bdt) $ bdt --help
.. _bob.devtools.install.setup:
Setup Setup
===== =====
...@@ -74,7 +75,21 @@ that server inside the file ``~/.bdtrc``. Here is a skeleton: ...@@ -74,7 +75,21 @@ that server inside the file ``~/.bdtrc``. Here is a skeleton:
password = password password = password
You may obtain these parameters from our internal page explaining the `WebDAV You may obtain these parameters from our internal page explaining the `WebDAV
configuration`_. You shoul also set ``chmod 600`` to this file for obvious configuration`_. For security reasons, you should also set ``chmod 600`` to
security reasons. this file.
To increment your development environments created with ``bdt create`` using
pip-installable packages, create a section named ``create`` in the file
``~/.bdtrc`` with the following contents, e.g.:
.. code-block:: ini
[create]
pip_extras = ipdb
mr.developer
Then, by default, ``bdt create`` will automatically pip install ``ipdb`` and
``mr.developer`` at environment creation time. You may reset this list to your
liking.
.. include:: links.rst .. include:: links.rst
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment