From 441e5a73b2dd4e6f48b79752262ab0533094f3a4 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Fri, 19 Apr 2024 23:48:10 +0300 Subject: [PATCH] Fix conda env should not be cached if installing into base conda or conda existing env exists --- clearml_agent/helper/package/conda_api.py | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/clearml_agent/helper/package/conda_api.py b/clearml_agent/helper/package/conda_api.py index 3f1f233..8fa297d 100644 --- a/clearml_agent/helper/package/conda_api.py +++ b/clearml_agent/helper/package/conda_api.py @@ -208,7 +208,6 @@ class CondaAPI(PackageManager): except Exception as ex: print("WARNING: Failed using base conda environment, reverting to new environment: {}".format(ex)) - command = Argv( self.conda, "create", @@ -273,7 +272,7 @@ class CondaAPI(PackageManager): Conda seems to load "vcruntime140.dll" from all its environment on startup. This means environment have to be deleted using 'conda env remove'. If necessary, conda can be fooled into deleting a partially-deleted environment by creating an empty file - in '\conda-meta\history' (value found in 'conda.gateways.disk.test.PREFIX_MAGIC_FILE'). + in '\\conda-meta\\history' (value found in 'conda.gateways.disk.test.PREFIX_MAGIC_FILE'). Otherwise, it complains that said directory is not a conda environment. See: https://github.com/conda/conda/issues/7682 @@ -801,6 +800,25 @@ class CondaAPI(PackageManager): return conda_env return base_conda_env + def add_cached_venv(self, *args, **kwargs): + """ + Copy the local venv folder into the venv cache (keys are based on the requirements+python+docker). + """ + # do not cache if this is a base conda environment + if self.conda_env_as_base_docker or self.use_conda_base_env: + return + return super().add_cached_venv(*args, **kwargs) + + def get_cached_venv(self, *args, **kwargs): + """ + Copy a cached copy of the venv (based on the requirements) into destination_folder. + Return None if failed or cached entry does not exist + """ + # do not cache if this is a base conda environment + if self.conda_env_as_base_docker or self.use_conda_base_env: + return + return super().get_cached_venv(*args, **kwargs) + # enable hashing with cmp=False because pdb fails on un-hashable exceptions exception = attrs(str=True, cmp=False)