Skip to content

Commit

Permalink
Allow to install extensions in the system path via packages (Azure#12367
Browse files Browse the repository at this point in the history
)
  • Loading branch information
bluca authored Mar 27, 2020
1 parent 44c8c0a commit 4dfb0f8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/azure-cli-core/azure/cli/core/extension/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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_'

Expand All @@ -34,7 +37,7 @@
WHEEL_INFO_RE = re.compile(
r"""^(?P<namever>(?P<name>.+?)(-(?P<ver>\d.+?))?)
((-(?P<build>\d.*?))?-(?P<pyver>.+?)-(?P<abi>.+?)-(?P<plat>.+?)
\.whl|\.dist-info)$""",
\.whl|\.dist-info|\.egg-info)$""",
re.VERBOSE).match

logger = get_logger(__name__)
Expand Down Expand Up @@ -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
Expand All @@ -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


Expand Down
1 change: 1 addition & 0 deletions src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down

0 comments on commit 4dfb0f8

Please sign in to comment.