discover.utils.venv_utils module
Utility functions to create virtual environments and execute commands in them
- Author:
Dominik Schiller <dominik.schiller@uni-a.de>
- Date:
06.09.2023
- discover.utils.venv_utils.get_module_run_cmd(env_path, module, args=None, kwargs=None)[source]
Generate a command to run a Python module within a virtual environment.
- Parameters:
env_path (Path) – Path to the virtual environment.
module (str) – Python module name.
args (list, optional) – List of arguments to pass to the module.
kwargs (dict, optional) – Dictionary of keyword arguments to pass to the module.
- Returns:
Run command.
- Return type:
str
Example
>>> get_module_run_cmd(Path('/path/to/venv'), 'mymodule', ['arg1', 'arg2'], {'--flag': 'value'}) 'source /path/to/venv/bin/activate && python -m mymodule arg1 arg2 --flag value'
- discover.utils.venv_utils.get_python_script_run_cmd(env_path, script, args=None, kwargs=None)[source]
Generate a command to run a Python script within a virtual environment.
- Parameters:
env_path (Path) – Path to the virtual environment.
script (Path) – Path to the Python script.
args (list, optional) – List of arguments to pass to the script.
kwargs (dict, optional) – Dictionary of keyword arguments to pass to the script.
- Returns:
Run command.
- Return type:
str
Example
>>> get_python_script_run_cmd(Path('/path/to/venv'), Path('/path/to/script.py'), ['arg1', 'arg2'], {'--flag': 'value'}) 'source /path/to/venv/bin/activate && python /path/to/script.py arg1 arg2 --flag value'
- discover.utils.venv_utils.get_shell_script_run_cmd(env_path, script, args=None, kwargs=None)[source]
Generate a command to run a console script within a virtual environment. The path to the script musst be set in the path environment variable of the console session.
- Parameters:
env_path (Path) – Path to the virtual environment.
script (Path) – Path to the Python script.
args (list, optional) – List of arguments to pass to the script.
kwargs (dict, optional) – Dictionary of keyword arguments to pass to the script.
- Returns:
Run command.
- Return type:
str
Example
>>> get_python_script_run_cmd(Path('/path/to/venv'), Path('/path/to/script.py'), ['arg1', 'arg2'], {'--flag': 'value'}) 'source /path/to/venv/bin/activate && python /path/to/script.py arg1 arg2 --flag value'
- discover.utils.venv_utils.venv_dir_from_mod(module_dir)[source]
Returns the path to a virtual environment directory matchin a provided module directory.
- Parameters:
module_dir (Path) – Path to the module directory.
- Returns:
Virtual environment directory.
- Return type:
Path
- Raises:
ValueError – If the NOVA_CACHE_DIR environment variable is not set.
Example
>>> venv_dir_from_mod(Path('/path/to/my_module')) Path('/path/to/venvs/my_module')