From 2b08d631d5ac5dc7df5d3d7ba99a3df00c4b4d0e Mon Sep 17 00:00:00 2001 From: zhrua Date: Mon, 27 Mar 2023 15:53:03 +0800 Subject: [PATCH] check only once whether artifact extension exists --- .../azure/ai/ml/_internal/entities/_artifact_cache.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/_artifact_cache.py b/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/_artifact_cache.py index 6fbfc41eb079..684862ac1996 100644 --- a/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/_artifact_cache.py +++ b/sdk/ml/azure-ai-ml/azure/ai/ml/_internal/entities/_artifact_cache.py @@ -45,11 +45,11 @@ def __new__(cls): with cls._instance_lock: if cls._instance is None: cls._instance = object.__new__(cls) + cls.check_artifact_extension() return cls._instance - def __init__(self, cache_directory=None): - self._cache_directory = cache_directory or self.DEFAULT_DISK_CACHE_DIRECTORY - Path(self._cache_directory).mkdir(exist_ok=True, parents=True) + @staticmethod + def check_artifact_extension(): # check az extension azure-devops installed. Install it if not installed. process = subprocess.Popen( "az artifacts --help --yes", @@ -63,6 +63,10 @@ def __init__(self, cache_directory=None): "Auto-installation failed. Please install azure-devops " "extension by 'az extension add --name azure-devops'." ) + + def __init__(self, cache_directory=None): + self._cache_directory = cache_directory or self.DEFAULT_DISK_CACHE_DIRECTORY + Path(self._cache_directory).mkdir(exist_ok=True, parents=True) self._artifacts_tool_path = None self._download_locks = defaultdict(Lock)