Commons Submodule¶
Shortcuts to defining tasks and environments.
It’s not uncommon for tasks to share a similar parent directory or structure. Likewise, environments almost always share the same parent directory or structure. The commons module makes well-founded assumptions about these structures to improve readability.
-
dequindre.commons.
common_conda_env
(common_prefix: str, common_suffix: str = None) → Callable¶ Quickly construct a path to a common conda environment
conda follows the structure: /path/to/conda/envs/{{my_env}}/bin/python
Parameters: - common_prefix (str) – The file path before the environment name.
- common_suffix (str, optional) – The file path after the environment name.
Returns: Function to shorten env specification
Example
>>> >>> from dequindre.commons import common_conda_env >>> with common_conda_env('/path/to/conda/envs') as env: ... python27 = env('python27') ... python36 = env('python36') ... >>> python27 '/path/to/conda/envs/python27/bin/python'
-
dequindre.commons.
common_pipenv
(common_prefix: str = '.', common_suffix: str = None) → Callable¶ Quickly construct a path to a common pipenv environment
pipenv follows the structure: /path/to/{{my_env}}/Scripts/python
Parameters: - common_prefix (str) – The file path before the environment name.
- common_suffix (str, optional) – The file path after the environment name.
Returns: Function to shorten env specification
Example
>>> >>> from dequindre.commons import common_pipenv >>> with common_pipenv('/path/to/tea-envs') as env: ... python27 = env('python27') ... python36 = env('python36') ... >>> python27 '/path/to/tea-envs/python27/Scripts/python'
-
dequindre.commons.
common_task
(loc_pattern: str, common_env: str = 'python')¶ Create tasks with a common parent path and environment.
Lots of tasks will use the same environment or same directory. These commons reduce duplicate code.
Parameters: - loc_pattern (str) – {}-formatted parent path.
- common_env (str, optional) – environment.
Example
>>> from dequindre.commons import common_task >>> with common_task('./tea-tasks/{}/main.py') as T: ... boil_water = T('boil_water') ... steep_tea = T('steep_tea') ... drink_tea = T('drink_tea') >>> boil_water Task(./tea-tasks/boil_water/main.py)
-
dequindre.commons.
common_venv
(common_prefix: str = '.', common_suffix: str = None) → Callable¶ Quickly construct a path to a common virtualenv environment
venv follows the structure: /path/to/{{my_env}}/Scripts/python
Parameters: - common_prefix (str) – The file path before the environment name.
- common_suffix (str, optional) – The file path after the environment name.
Returns: Function to shorten env specification
Example
>>> >>> from dequindre.commons import common_venv >>> with common_venv('./tea-envs') as env: ... python27 = env('python27') ... python36 = env('python36') ... >>> python27 './tea-envs/python27/Scripts/python'