From 764a30501d6ee46500597970478d263aa15dda80 Mon Sep 17 00:00:00 2001 From: Amir MOHAMMADI <amir.mohammadi@idiap.ch> Date: Thu, 23 Jun 2022 15:10:17 +0200 Subject: [PATCH] Ask for conda env name explicitly in bdt dev install This makes sure that no package gets installed in the user folders of users --- bob/devtools/scripts/development.py | 60 ++++++++++++++++++++--------- doc/development.rst | 12 +++--- 2 files changed, 48 insertions(+), 24 deletions(-) diff --git a/bob/devtools/scripts/development.py b/bob/devtools/scripts/development.py index f11affaa..f923934e 100644 --- a/bob/devtools/scripts/development.py +++ b/bob/devtools/scripts/development.py @@ -4,33 +4,51 @@ from click_plugins import with_plugins from pkg_resources import iter_entry_points -@click.command(epilog="See bdt dev --help") +@click.command(epilog="See bdt dev --help for examples of this command.") +@click.option( + "-n", + "--env-name", + help="Name of the conda environment to use", + required=True, +) @click.argument( "folders", nargs=-1, type=click.Path(exists=True, file_okay=False, dir_okay=True), ) -def install(folders): - """runs pip install -vvv --no-build-isolation --no-dependencies --editable <folder>""" +def install(env_name, folders): + """runs: + + pip install -vvv --no-build-isolation --no-dependencies --editable <folder> + + inside the specified conda environment""" import subprocess for folder in folders: # call pip + cmd = [ + "conda", + "run", + "-n", + env_name, + "pip", + "install", + "-vvv", + "--no-build-isolation", + "--no-dependencies", + "--editable", + folder, + ] + cmd = " ".join(cmd) subprocess.check_call( - [ - "pip", - "install", - "-vvv", - "--no-build-isolation", - "--no-dependencies", - "--editable", - folder, - ] + cmd, + shell=True, ) + click.echo("Installed package using the command:", cmd) -@click.command(epilog="See bdt dev --help") +@click.command(epilog="See bdt dev --help for examples of this command.") @click.argument("names", nargs=-1) @click.option("--use-https/--use-ssh", is_flag=True, default=False) @click.option( @@ -38,7 +56,7 @@ def install(folders): ) @click.pass_context def checkout(ctx, names, use_https, subfolder): - """git clones a Bob package.""" + """git clones a Bob package and installs the pre-commit hook if required.""" import os import subprocess @@ -67,9 +85,15 @@ def checkout(ctx, names, use_https, subfolder): click.echo( "Installing pre-commit hooks. Make sure you have pre-commit installed." ) - subprocess.check_call(["pre-commit", "install"], cwd=dest) + try: + subprocess.check_call(["pre-commit", "install"], cwd=dest) + except subprocess.CalledProcessError: + click.echo( + "pre-commit installation failed. Please install pre-commit manually." + ) +# the group command must be at the end of this file for plugins to work. @with_plugins(iter_entry_points("bdt.dev.cli")) @click.group( epilog="""Examples: @@ -79,19 +103,19 @@ def checkout(ctx, names, use_https, subfolder): bdt dev checkout bob.bio.face cd bob.bio.face bdt dev create --python 3.9 bobbioface -bdt dev install . +bdt dev install -n bobbioface . \b # later on, checkout and develop more packages bdt dev checkout --subfolder src bob.bio.base -bdt dev install src/bob.bio.base +bdt dev install -n bobbioface src/bob.bio.base \b # develop a new project bdt dev new -vv bob/bob.newpackage "John Doe" "joe@example.com" # edit the conda/meta.yaml and requirements.txt files to add your dependencies bdt dev create --python 3.9 bobnewpackage -bdt install .""" +bdt install -n bobnewpackage .""" ) def dev(): """Development scripts""" diff --git a/doc/development.rst b/doc/development.rst index 4b4b4eb3..57a2e92f 100644 --- a/doc/development.rst +++ b/doc/development.rst @@ -47,7 +47,7 @@ assume you have ``bob.devtools`` installed on a conda environment named ``bdt`` .. code-block:: sh - $ bdt dev install . # calls pip with correct arguments + $ bdt dev install -n dev . # calls pip with correct arguments $ python for example: @@ -179,7 +179,7 @@ The last step is to install the package: $ cd bob.io.base #if that is not the case $ conda activate dev #if that is not the case - $ bdt dev install . + $ bdt dev install -n dev . To run the test suite: @@ -240,7 +240,7 @@ and install ``bob.extension`` as following: .. code-block:: sh $ bdt dev checkout --use-ssh --subfolder src bob.extension - $ bdt dev install src/bob.extension + $ bdt dev install -n dev src/bob.extension .. _bob.devtools.create_package: @@ -269,7 +269,7 @@ start developing your package. $ cd bob.project.awesome $ bdt dev create --stable -vv awesome-project #here we used the stable channels to make the conda environment. $ conda activate awesome-project - $ bdt dev install . + $ bdt dev install -n awesome-project . Developing existing bob packages along with your new package @@ -283,7 +283,7 @@ You need to checkout and install these packages: .. code-block:: sh $ bdt dev checkout --use-ssh --subfolder src bob.extension bob.io.base - $ bdt dev install src/bob.extension src/bob.io.base # the order of installing dependencies matters! + $ bdt dev install -n awesome-project src/bob.extension src/bob.io.base # the order of installing dependencies matters! When you build your new package, it is customary to checkout the dependent packages (in this example ``bob.extension`` and ``bob.io.base``) in the ``src`` @@ -298,6 +298,6 @@ your environment. You can find these dependencies by checking .. code-block:: sh $ mamba install gcc_linux-64 gxx_linux-64 libblitz - $ bdt dev install src/bob.extension src/bob.io.base # the order of installing dependencies matters! + $ bdt dev install -n awesome-project src/bob.extension src/bob.io.base # the order of installing dependencies matters! .. include:: links.rst -- GitLab