From 745316c6c91b32644c35fd37ddd1f52982f0eeed Mon Sep 17 00:00:00 2001
From: Laurent COLBOIS <laurent.colbois@idiap.ch>
Date: Tue, 28 Jun 2022 10:29:11 +0200
Subject: [PATCH] Add entry point and doc

---
 .../{install_deps.py => dependencies.py}      | 23 +++++++++++-------
 bob/devtools/scripts/development.py           |  7 +++++-
 doc/development.rst                           | 24 +++++++++++++++++++
 setup.py                                      |  1 +
 4 files changed, 45 insertions(+), 10 deletions(-)
 rename bob/devtools/scripts/{install_deps.py => dependencies.py} (65%)

diff --git a/bob/devtools/scripts/install_deps.py b/bob/devtools/scripts/dependencies.py
similarity index 65%
rename from bob/devtools/scripts/install_deps.py
rename to bob/devtools/scripts/dependencies.py
index ac266ddc..72ee3edc 100644
--- a/bob/devtools/scripts/install_deps.py
+++ b/bob/devtools/scripts/dependencies.py
@@ -4,24 +4,26 @@ import click
 
 @click.command(
     epilog="""Example:
-  1. Creates an environment called `myenv' containing all external bob dependencies:
 
-python bob/devtools/scripts/install_deps.py  myenv
+    Creates an environment called `myenv' based on Python 3.8 and containing all external bob dependencies:
 
-2. The version of python to solve with can be provided as option:
-
-python bob/devtools/scripts/install_deps.py  myenv --python=3.8
 
+    bdt dev dependencies --python 3.8 myenv
 """
 )
 @click.argument("env_name", nargs=1)
 @click.option("--python", required=True, help="Python version to pin, e.g. 3.8")
-def install_deps(env_name, python):
+def dependencies(env_name, python):
+    """Creates an environment with all external bob dependencies."""
     import subprocess
 
+    import pkg_resources
+
     from bob.devtools.build import load_packages_from_conda_build_config
 
-    conda_config_path = "bob/devtools/data/conda_build_config.yaml"
+    conda_config_path = pkg_resources.resource_filename(
+        "bob.devtools", "data/conda_build_config.yaml"
+    )
 
     packages, package_names_map = load_packages_from_conda_build_config(
         conda_config_path, {"channels": []}, with_pins=True
@@ -40,7 +42,10 @@ def install_deps(env_name, python):
                 env_name,
                 f"python={python}",
             ]
-            + packages,
+            + packages
+            + [
+                "compilers"
+            ],  # Install conda-forge compilers for compiled pacakges
             check=True,
         )
     except subprocess.CalledProcessError as e:
@@ -49,4 +54,4 @@ def install_deps(env_name, python):
 
 
 if __name__ == "__main__":
-    install_deps()
+    dependencies()
diff --git a/bob/devtools/scripts/development.py b/bob/devtools/scripts/development.py
index ec9676a7..eab9b528 100644
--- a/bob/devtools/scripts/development.py
+++ b/bob/devtools/scripts/development.py
@@ -118,7 +118,12 @@ bdt dev install -n bobbioface src/bob.bio.base
 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 -n bobnewpackage ."""
+bdt install -n bobnewpackage .
+
+\b
+# create an environment with all external bob dependencies
+bdt dev dependencies --python 3.9 my_env
+"""
 )
 def dev():
     """Development scripts"""
diff --git a/doc/development.rst b/doc/development.rst
index 57a2e92f..0894abf1 100644
--- a/doc/development.rst
+++ b/doc/development.rst
@@ -36,12 +36,23 @@ assume you have ``bob.devtools`` installed on a conda environment named ``bdt``
    $ bdt dev create -vv dev
    $ conda activate dev
 
+If you know that you plan to develop many packages (or even every Bob package), you can
+also instead create an environment that contains the integrality of external dependencies.
+This avoids the need to run ``bdt dev create`` for many packages. You will need to pick a Python version:
+
+.. code-block:: sh
+
+   $ bdt dev dependencies --python 3.9 dev
+   $ conda activate dev
+
 .. note::
 
    ``bdt`` might try to install the cuda version of deep learning packages. If
    you don't have cuda drivers installed and face errors such as ``nothing
    provides __cuda``, you might need to run: ``export CONDA_OVERRIDE_CUDA=11.6``
    where instead of ``11.6`` you should put the latest version of cuda.
+   You can also use this trick if you actually want to ensure ``bdt`` will
+   install the cuda version of deep learning packages.
 
 * Build the package using pip:
 
@@ -243,6 +254,19 @@ and install ``bob.extension`` as following:
     $ bdt dev install -n dev src/bob.extension
 
 
+If you want to develop many packages, or even all Bob packages at once, you can proceed a bit
+differently. First, create an environment containing all external Bob dependencies.
+
+.. code-block:: sh
+
+    $ bdt dev dependencies --python 3.9 bob_deps
+    $ conda activate bob_deps
+    $ mkdir -pv bob_beta/src
+    $ cd bob_beta/src
+    $ bdt dev checkout --use-ssh bob.extension bob.io.base bob.pipelines # ... checkout all packages you need
+    $ bdt dev install bob.extension bob.io.base bob.pipelines # ... install all packages you need
+
+
 .. _bob.devtools.create_package:
 
 Local development of a new package
diff --git a/setup.py b/setup.py
index f85badbc..db4557da 100644
--- a/setup.py
+++ b/setup.py
@@ -112,6 +112,7 @@ setup(
             "create = bob.devtools.scripts.create:create",
             "install = bob.devtools.scripts.development:install",
             "checkout = bob.devtools.scripts.development:checkout",
+            "dependencies = bob.devtools.scripts.dependencies:dependencies",
         ],
     },
     classifiers=[
-- 
GitLab