diff --git a/src/azure-cli-core/azure/cli/core/extension/__init__.py b/src/azure-cli-core/azure/cli/core/extension/__init__.py index 237bab30bc1..8ccc77645e5 100644 --- a/src/azure-cli-core/azure/cli/core/extension/__init__.py +++ b/src/azure-cli-core/azure/cli/core/extension/__init__.py @@ -7,9 +7,11 @@ import traceback import json import re +import sys +import pkginfo from azure.cli.core._config import GLOBAL_CONFIG_DIR, ENV_VAR_PREFIX - +from distutils.sysconfig import get_python_lib from knack.config import CLIConfig from knack.log import get_logger @@ -19,6 +21,7 @@ EXTENSIONS_DIR = os.path.expanduser(_CUSTOM_EXT_DIR) if _CUSTOM_EXT_DIR else os.path.join(GLOBAL_CONFIG_DIR, 'cliextensions') DEV_EXTENSION_SOURCES = _DEV_EXTENSION_SOURCES.split(',') if _DEV_EXTENSION_SOURCES else [] +EXTENSIONS_SYS_DIR = os.path.join(get_python_lib(), 'azure-cli-extensions') if sys.platform.startswith('linux') else "" EXTENSIONS_MOD_PREFIX = 'azext_' @@ -34,7 +37,7 @@ WHEEL_INFO_RE = re.compile( r"""^(?P(?P.+?)(-(?P\d.+?))?) ((-(?P\d.*?))?-(?P.+?)-(?P.+?)-(?P.+?) - \.whl|\.dist-info)$""", + \.whl|\.dist-info|\.egg-info)$""", re.VERBOSE).match logger = get_logger(__name__) @@ -151,9 +154,14 @@ def get_metadata(self): if os.path.isfile(whl_metadata_filepath): with open(whl_metadata_filepath) as f: metadata.update(json.loads(f.read())) + elif os.path.isfile(os.path.join(dist_info_dirname, 'PKG-INFO')): + metadata.update(pkginfo.Develop(dist_info_dirname).__dict__) return metadata + def __eq__(self, other): + return other.name == self.name + @staticmethod def get_azext_metadata(ext_dir): azext_metadata = None @@ -177,6 +185,14 @@ def get_all(): pattern = os.path.join(ext_path, '*.*-info') if os.path.isdir(ext_path) and glob(pattern): exts.append(WheelExtension(ext_name, ext_path)) + if os.path.isdir(EXTENSIONS_SYS_DIR): + for ext_name in os.listdir(EXTENSIONS_SYS_DIR): + ext_path = os.path.join(EXTENSIONS_SYS_DIR, ext_name) + pattern = os.path.join(ext_path, '*.*-info') + if os.path.isdir(ext_path) and glob(pattern): + ext = WheelExtension(ext_name, ext_path) + if ext not in exts: + exts.append(ext) return exts diff --git a/src/azure-cli-core/setup.py b/src/azure-cli-core/setup.py index 66d91c49f56..67dc116f142 100644 --- a/src/azure-cli-core/setup.py +++ b/src/azure-cli-core/setup.py @@ -60,6 +60,7 @@ 'msrest>=0.4.4', 'msrestazure>=0.6.2', 'paramiko>=2.0.8,<3.0.0', + 'pkginfo', 'PyJWT', 'pyopenssl>=17.1.0', # https://github.com/pyca/pyopenssl/pull/612 'pyyaml~=5.2',