Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if there is extension containing C code (non-pure Python), will the get_python_lib() work?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my Debian box cpython libraries are in dist-packages too, so I'm not expecting issues:

>>> from distutils.sysconfig import get_python_lib
>>> get_python_lib()
'/usr/lib/python3/dist-packages'
$ find /usr/lib/python3/dist-packages/ -name *.so -type f | wc -l
241

Also, what we are after is the azure-cli-extensions directory where we store the symlinks - the symlinks themselves can point to anywhere

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 @@ -33,7 +36,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 @@ -136,9 +139,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 @@ -162,6 +170,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 @@ -61,6 +61,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',
Expand Down