From aca549f703e30874fa7d82433d666a774fac2ddd Mon Sep 17 00:00:00 2001 From: Thierry RAMORASOAVINA Date: Wed, 14 Aug 2024 19:27:09 +0200 Subject: [PATCH] Add safeguard in `runner:_infer_env_bin_dir_for_conda_based_installations` for unexpected folders hierarchy --- khiops/core/internals/runner.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/khiops/core/internals/runner.py b/khiops/core/internals/runner.py index e15b8f37..031561d1 100644 --- a/khiops/core/internals/runner.py +++ b/khiops/core/internals/runner.py @@ -218,11 +218,17 @@ def _infer_env_bin_dir_for_conda_based_installations(): assert reference_file is not None # Windows: Match %CONDA_PREFIX%\Lib\site-packages\khiops\__init__.py if platform.platform() == "Windows": - conda_env_dir = Path(reference_file).parents[3] + if len(Path(reference_file).parents) >= 4: + conda_env_dir = Path(reference_file).parents[3] + else: + conda_env_dir = Path(reference_file).parents[0] # Linux/macOS: # Match $CONDA_PREFIX/[Ll]ib/python3.X/site-packages/khiops/__init__.py else: - conda_env_dir = Path(reference_file).parents[4] + if len(Path(reference_file).parents) >= 5: + conda_env_dir = Path(reference_file).parents[4] + else: + conda_env_dir = Path(reference_file).parents[0] env_bin_dir = os.path.join(conda_env_dir.as_posix(), "bin") return env_bin_dir