run_in_conda_env_cli#
- run_in_conda_env_cli(cli_path: str, inputs: dict, logger_name: str, tools_path: str, conda_env_name: str = '', extend_env: dict = {}, shell: bool = True) tuple[int, Any][source]#
Run the given command line with the given inputs in a new conda environment.
Scope: run a complicated tool with heavy deps from inside a conda environment ccontaining arcpy
To be used in the .pyt file.
- Parameters:
cli_path (str) – Path to CLI file.
inputs (dict) – Inputs of the function wrapped by the CLI as a dictionary
logger_name (str) – Logger name
tools_path (str) – Path to the tools
conda_env_name (str) – Name of the conda environment where to run the executable. Set it to “self” to force the subprocess to run in the current environment.
extend_env (dict) – Dict to extend environment in the sub-process. extend_env is merged with the parent process environment by overriding it if necessary.
shell (bool) – Run subprocess in a shell if True.
- Returns:
Return value and outputs of the function
- Return type:
Examples
>>> def main_arcgis(parameters, messages, tools_path): >>> from sertit.arcpy import run_in_conda_env_cli >>> from my_tool import LOGGER_NAME, my_backend_cli >>> >>> inputs = { >>> "aoi_path": "aoi.shp", >>> "input": "input.tif", >>> "resolution": 10, >>> } >>> >>> retval, output_path = run_in_conda_env_cli( >>> cli_path=my_backend_cli.__file__, >>> inputs=inputs, >>> logger_name=LOGGER_NAME, >>> tools_path=tools_path, >>> ) >>> >>> if retval == 0: >>> logger.info("RasterFillHoles was a success.") >>> else: >>> logger.error("Subprocess RasterFillHoles failed.")