Skip to content

Commit 27af048

Browse files
authored
azure: use knack directly instead of azure-cli-core (#4147)
1 parent 5d85692 commit 27af048

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

dvc/remote/azure.py

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import os
23
import threading
34
from datetime import datetime, timedelta
45

@@ -17,38 +18,45 @@ class AzureRemoteTree(BaseRemoteTree):
1718
PATH_CLS = CloudURLInfo
1819
REQUIRES = {
1920
"azure-storage-blob": "azure.storage.blob",
20-
"azure-cli-core": "azure.cli.core",
21+
"knack": "knack",
2122
}
2223
PARAM_CHECKSUM = "etag"
2324
COPY_POLL_SECONDS = 5
2425
LIST_OBJECT_PAGE_SIZE = 5000
2526

2627
def __init__(self, repo, config):
27-
from azure.cli.core import get_default_cli
28-
2928
super().__init__(repo, config)
3029

31-
# NOTE: az_config takes care of env vars
32-
az_config = get_default_cli().config
33-
3430
url = config.get("url", "azure://")
3531
self.path_info = self.PATH_CLS(url)
3632

3733
if not self.path_info.bucket:
38-
container = az_config.get("storage", "container_name", None)
34+
container = self._az_config.get("storage", "container_name", None)
3935
self.path_info = self.PATH_CLS(f"azure://{container}")
4036

4137
self._conn_kwargs = {
42-
opt: config.get(opt) or az_config.get("storage", opt, None)
38+
opt: config.get(opt) or self._az_config.get("storage", opt, None)
4339
for opt in ["connection_string", "sas_token"]
4440
}
45-
self._conn_kwargs["account_name"] = az_config.get(
41+
self._conn_kwargs["account_name"] = self._az_config.get(
4642
"storage", "account", None
4743
)
48-
self._conn_kwargs["account_key"] = az_config.get(
44+
self._conn_kwargs["account_key"] = self._az_config.get(
4945
"storage", "key", None
5046
)
5147

48+
@cached_property
49+
def _az_config(self):
50+
# NOTE: ideally we would've used get_default_cli().config from
51+
# azure.cli.core, but azure-cli-core has a lot of conflicts with other
52+
# dependencies. So instead we are just use knack directly
53+
from knack.config import CLIConfig
54+
55+
config_dir = os.getenv(
56+
"AZURE_CONFIG_DIR", os.path.expanduser(os.path.join("~", ".azure"))
57+
)
58+
return CLIConfig(config_dir=config_dir, config_env_var_prefix="AZURE")
59+
5260
@wrap_prop(threading.Lock())
5361
@cached_property
5462
def blob_service(self):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def run(self):
8787
gs = ["google-cloud-storage==1.19.0"]
8888
gdrive = ["pydrive2>=1.4.14"]
8989
s3 = ["boto3>=1.9.201"]
90-
azure = ["azure-storage-blob==2.1.0", "azure-cli-core>=2.0.70"]
90+
azure = ["azure-storage-blob==2.1.0", "knack"]
9191
oss = ["oss2==2.6.1"]
9292
ssh = ["paramiko>=2.5.0"]
9393
hdfs = ["pyarrow>=0.17.0"]

0 commit comments

Comments
 (0)