Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
use pkginfo to query and dump metadata of Python Package
  • Loading branch information
Jianhui Harold committed Mar 29, 2020
commit f4d5b6a3227b91bda39f5c1cc7d5d08824d2362f
4 changes: 2 additions & 2 deletions azdev/operations/extensions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def update_extension_index(extensions):
ext_dir = tempfile.mkdtemp(dir=extensions_dir)
whl_cache_dir = tempfile.mkdtemp()
whl_cache = {}
ext_file = get_whl_from_url(ext_path, extension_name, whl_cache_dir, whl_cache)
ext_file = get_whl_from_url(ext_path, extension_name + '.whl', whl_cache_dir, whl_cache)

with open(index_path, 'r') as infile:
curr_index = json.loads(infile.read())
Expand All @@ -229,7 +229,7 @@ def update_extension_index(extensions):
'downloadUrl': ext_path,
'sha256Digest': _get_sha256sum(ext_file),
'filename': ext_path.split('/')[-1],
'metadata': get_ext_metadata(ext_dir, ext_file, extension_name)
'metadata': get_ext_metadata(ext_dir, ext_file)
}

if extension_name not in curr_index['extensions'].keys():
Expand Down
28 changes: 17 additions & 11 deletions azdev/operations/extensions/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import re
import zipfile

from pkginfo import Wheel
from knack.util import CLIError

from azdev.utilities import EXTENSION_PREFIX
Expand Down Expand Up @@ -43,28 +44,33 @@ def _get_azext_metadata(ext_dir):
return azext_metadata


def get_ext_metadata(ext_dir, ext_file, ext_name):
# Modification of https://github.com/Azure/azure-cli/blob/dev/src/azure-cli-core/azure/cli/core/extension.py#L89
WHL_METADATA_FILENAME = 'metadata.json'
def get_ext_metadata(ext_dir, ext_file):
zip_ref = zipfile.ZipFile(ext_file, 'r')
zip_ref.extractall(ext_dir)
zip_ref.close()
metadata = {}
dist_info_dirs = [f for f in os.listdir(ext_dir) if f.endswith('.dist-info')]
azext_metadata = _get_azext_metadata(ext_dir)
if azext_metadata:
metadata.update(azext_metadata)
for dist_info_dirname in dist_info_dirs:
parsed_dist_info_dir = WHEEL_INFO_RE(dist_info_dirname)
if parsed_dist_info_dir and parsed_dist_info_dir.groupdict().get('name') == ext_name.replace('-', '_'):
whl_metadata_filepath = os.path.join(ext_dir, dist_info_dirname, WHL_METADATA_FILENAME)
if os.path.isfile(whl_metadata_filepath):
with open(whl_metadata_filepath) as f:
metadata.update(json.load(f))

try:
ext_wheel = Wheel(ext_file)

t = vars(ext_wheel)
del t['filename']
del t['description'] # del as line too long

metadata.update(vars(ext_wheel))
except ValueError:
raise CLIError('{} is not a valid wheel'.format(ext_file))

return metadata


def get_whl_from_url(url, filename, tmp_dir, whl_cache=None):
print('-' * 20, 'get_whl_from_url', '-' * 20)
print(filename)

if not whl_cache:
whl_cache = {}
if url in whl_cache:
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@
'requests',
'sphinx==1.6.7',
'tox',
'wheel==0.30.0',
'wheel>=0.30.0',
'azure-storage-blob>=1.3.1,<2.0.0',
'pkginfo>=1.5.0.1',
],
extras_require={
":python_version<'3.0'": ['pylint==1.9.2', 'futures'],
Expand Down