Skip to content

Commit 78af72c

Browse files
authored
add extension show (#456)
* add extension show * fix extension index name
1 parent 8f5eb98 commit 78af72c

File tree

8 files changed

+68
-3
lines changed

8 files changed

+68
-3
lines changed

HISTORY.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
33
Release History
44
===============
5+
0.1.71
6+
++++++
7+
* `azdev extension show`: Show detailed extension info that installed in your development environment.
8+
* `azdev extension cal-next-version`: Fix last stable version parser from index.json.
9+
510
0.1.70
611
++++++
712
* Fix cmdcov issue(#455): remove tested_command.txt reference.

azdev/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@
44
# license information.
55
# -----------------------------------------------------------------------------
66

7-
__VERSION__ = '0.1.70'
7+
__VERSION__ = '0.1.71'

azdev/commands.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def operation_group(name):
6767
g.command('publish', 'publish_extensions')
6868
g.command('update-index', 'update_extension_index')
6969
g.command('cal-next-version', 'cal_next_version')
70+
g.command('show', 'show_extension')
7071

7172
with CommandGroup(self, 'extension repo', operation_group('extensions')) as g:
7273
g.command('add', 'add_extension_repo')

azdev/help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,9 @@
258258
short-summary: List what extensions are currently visible to your development environment.
259259
"""
260260

261+
helps['extension show'] = """
262+
short-summary: Show detailed extension info that installed in your development environment.
263+
"""
261264

262265
helps['extension publish'] = """
263266
short-summary: Build and publish an extension to a storage account.

azdev/operations/extensions/__init__.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,36 @@ def list_extensions():
138138
return results
139139

140140

141+
def show_extension(mod_name):
142+
ext_paths = get_ext_repo_paths()
143+
ext_mod_paths = [os.path.join(ext, "src", mod_name) for ext in ext_paths]
144+
mod_install_path = find_files(ext_mod_paths, '*.*-info')
145+
146+
if not mod_install_path:
147+
raise CLIError('extension not installed using azdev: {}'.format(mod_name))
148+
149+
if len(mod_install_path) > 1:
150+
raise CLIError('extension {} duplicated, please specify extension name'.format(mod_name))
151+
152+
mod_install_dir = os.path.dirname(mod_install_path[0])
153+
long_name = os.path.basename(mod_install_dir)
154+
assert long_name == mod_name
155+
mod_info = {
156+
"name": mod_name,
157+
"path": mod_install_dir
158+
}
159+
# extract pkg name from egg-info or dist-info folders
160+
logger.debug("Extracting pkg info from %s...", mod_install_path[0])
161+
meta_files = ["PKG-INFO", "METADATA"]
162+
pkg_info_path = [os.path.join(mod_install_path[0], meta) for meta in meta_files
163+
if os.path.isfile(os.path.join(mod_install_path[0], meta))]
164+
from .util import get_pkg_info_from_pkg_metafile
165+
for pkg_info_file in pkg_info_path:
166+
pkg_info = get_pkg_info_from_pkg_metafile(pkg_info_file)
167+
mod_info.update(pkg_info)
168+
return mod_info
169+
170+
141171
def _get_sha256sum(a_file):
142172
import hashlib
143173
sha256 = hashlib.sha256()

azdev/operations/extensions/util.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,16 @@ def get_whl_from_url(url, filename, tmp_dir, whl_cache=None):
8181
f.write(chunk)
8282
whl_cache[url] = ext_file
8383
return ext_file
84+
85+
86+
def get_pkg_info_from_pkg_metafile(pkg_info_file):
87+
mod_info = {}
88+
with open(pkg_info_file, "r", encoding="utf-8") as f:
89+
for line in f:
90+
if line.startswith("Name:"):
91+
pkg_name = line.split(":")[-1].strip()
92+
mod_info["pkg_name"] = pkg_name
93+
if line.startswith("Version:"):
94+
pkg_version = line.split(":")[-1].strip()
95+
mod_info["pkg_version"] = pkg_version
96+
return mod_info

azdev/operations/extensions/version_upgrade.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# https://github.com/Azure/azure-cli/blob/release/doc/extensions/versioning_guidelines.md
1010

1111
from packaging.version import parse
12+
from knack.util import CLIError
1213
from azure_cli_diff_tool.utils import DiffLevel
1314
from azdev.operations.constant import (PREVIEW_INIT_SUFFIX, VERSION_MAJOR_TAG, VERSION_MINOR_TAG,
1415
VERSION_PATCH_TAG, VERSION_STABLE_TAG, VERSION_PREVIEW_TAG, VERSION_PRE_TAG,
@@ -70,6 +71,8 @@ def __init__(self, module_name, current_version, is_preview, is_experimental,
7071
self.init_version_pre_tag()
7172
self.next_version = ModuleVersion(self.version)
7273
self.last_stable_major = float('inf')
74+
self.pkg_name = self.module_name
75+
self.parse_pkg_name()
7376
self.parse_last_stable_major()
7477

7578
def norm_versions(self):
@@ -179,15 +182,22 @@ def find_max_version(version_datas):
179182
has_stable = True
180183
return has_stable, max_stable_major
181184

185+
def parse_pkg_name(self):
186+
from azdev.operations.extensions import show_extension
187+
try:
188+
self.pkg_name = show_extension(self.module_name)["pkg_name"]
189+
except CLIError:
190+
pass
191+
182192
def parse_last_stable_major(self):
183193
import requests
184194
try:
185195
response = requests.get(CLI_EXTENSION_INDEX_URL)
186196
extension_data = response.json()
187-
if self.module_name not in extension_data["extensions"]:
197+
if self.pkg_name not in extension_data["extensions"]:
188198
return
189199
has_stable, max_stable_major = self.find_max_version(
190-
extension_data["extensions"][self.module_name])
200+
extension_data["extensions"][self.pkg_name])
191201
if has_stable:
192202
self.last_stable_major = max_stable_major
193203
else:

azdev/params.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,9 @@ def load_arguments(self, _):
178178
c.argument('next_version_pre_tag', help='next version is stable or preview, if not provided, use current stable/preview tag')
179179
c.argument('next_version_segment_tag', help='used to modify actual major/minor/patch/pre, if provided, increment version as provided')
180180

181+
with ArgumentsContext(self, 'extension show') as c:
182+
c.argument('mod_name', required=True, help='installed extension module name')
183+
181184
with ArgumentsContext(self, 'cli create') as c:
182185
c.positional('mod_name', help='Name of the module to create.')
183186

0 commit comments

Comments
 (0)