run_in_conda_env

Contents

run_in_conda_env#

run_in_conda_env(executable: list[str], logger_name: str = 'sertit_utils', conda_env_name: str | None = None, python_path: str = '', extend_env: dict = {}, shell=True)[source]#

This function runs an executable thanks to conda run in a python subprocess. It uses the subcommand conda run to run the executable in a conda environment. If conda_env_name is None, it chooses an environment in the following order (it stops at the first one found): - arcgispro-eo-backend - arcgispro-eo-backend-testing - self

Where self is the current environment. If self is given, a subprocess is launched anyway with the same python interpreter.

This function is designed to solve ArcGis limits by running an executable files in another conda environment and thus solves a lot of issues.

The extend_env argument allows one to add environment variable in the child subprocess. For example, if parent_env = { “PYTHON_PATH”: “/path/to/python_lib,/another_path/to/python_lib”, “VAR”: “True” } and extend_env = {“PYTHON_PATH”: “/child_path/to/python_lib,/another_path/to/python_lib”} Then, child_env = {“PYTHON_PATH”: “/child_path/to/python_lib,/another_path/to/python_lib”, “VAR”: “True”}

The child_env took the whole PYTHON_PATH variable from extend_env and the variable VAR from the parent_env.

Parameters:
  • executable – Executable name, with additional arguments to be passed to the executable on invocation.

  • logger_name – The logger name to use.

  • conda_env_name – Name of the conda environment where to run the executable. Set it to “self” to force the subprocess to run in the current environment.

  • python_path – Set the PYTHON_PATH variable in the child subprocess.

  • extend_env – Dict to extend environment in the sub-process. extend_env is merged with the parent process environment by overriding it if necessary.

  • shell – Run subprocess in a shell if True.

Returns: