-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Extension] support .egg-info to store wheel type extension metadata #13286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
c001cf9
b3ed72f
65cf627
28d6ecd
e06aa80
cbfc649
a4731e1
d146a3e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| import tempfile | ||
| import zipfile | ||
| import tarfile | ||
| import shutil | ||
| import unittest | ||
|
|
||
| from azure.cli.core.extension import DevExtension | ||
| from azure.cli.core.extension.tests.latest import ExtensionTypeTestMixin, get_test_data_file | ||
|
|
||
|
|
||
| class TestWheelTypeExtensionMetadata(ExtensionTypeTestMixin): | ||
|
|
||
| def test_reading_wheel_type_extension_from_develop_mode(self): | ||
| """ | ||
| Test develop type extension. | ||
| For scenario that user are developing extension via azdev | ||
| """ | ||
|
|
||
| source_code_packaged = get_test_data_file('hello-0.1.0.tar.gz') | ||
|
|
||
| with tarfile.open(source_code_packaged, 'r:gz') as tar: | ||
| tar.extractall(self.ext_dir) | ||
|
|
||
| ext_name, ext_version = 'hello', '0.1.0' | ||
|
|
||
| ext_extension = DevExtension(ext_name, os.path.join(self.ext_dir, ext_name + '-' + ext_version)) | ||
| metadata = ext_extension.get_metadata() # able to read metadata from source code | ||
|
|
||
| # assert Python metadata | ||
| self.assertEqual(metadata['name'], ext_name) | ||
| self.assertEqual(metadata['version'], ext_version) | ||
| self.assertEqual(metadata['author'], 'Microsoft Corporation') | ||
| self.assertNotIn('metadata.json', os.listdir(os.path.join(self.ext_dir, ext_name + '-' + ext_version))) | ||
|
|
||
| # assert Azure CLI extended metadata | ||
| self.assertTrue(metadata['azext.isPreview']) | ||
| self.assertTrue(metadata['azext.isExperimental']) | ||
| self.assertEqual(metadata['azext.minCliCoreVersion'], '2.0.67') | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| import os | ||
| import tempfile | ||
| import zipfile | ||
| import tarfile | ||
| import shutil | ||
| import unittest | ||
|
|
||
| from azure.cli.core.extension import WheelExtension | ||
| from azure.cli.core.extension.tests.latest import ExtensionTypeTestMixin, get_test_data_file | ||
|
|
||
|
|
||
| class TestWheelTypeExtensionMetadata(ExtensionTypeTestMixin): | ||
|
|
||
| def test_reading_wheel_type_0_30_0_extension_metadata(self): | ||
| """ | ||
| Test wheel==0.30.0 containing metadata.json and we can handle it properly. | ||
| For scenario like 'az extenion add'. | ||
| """ | ||
|
|
||
| # this wheel contains metadata.json and METADATA | ||
| wheel_0_30_0_packed = get_test_data_file('wheel_0_30_0_packed_extension-0.1.0-py3-none-any.whl') | ||
|
|
||
| zf = zipfile.ZipFile(wheel_0_30_0_packed) | ||
| zf.extractall(self.ext_dir) | ||
|
|
||
| ext_name, ext_version = 'hello', '0.1.0' | ||
|
|
||
| whl_extension = WheelExtension(ext_name, self.ext_dir) | ||
| metadata = whl_extension.get_metadata() # able to read metadata from wheel==0.30.0 built extension | ||
|
|
||
| # wheel type extension generates .dist-info | ||
| dist_info = ext_name + '-' + ext_version + '.dist-info' | ||
|
|
||
| # assert Python metadata | ||
| self.assertEqual(metadata['name'], ext_name) | ||
| self.assertEqual(metadata['version'], ext_version) | ||
| self.assertEqual(metadata['author'], 'Microsoft Corporation') | ||
| self.assertIn('metadata.json', os.listdir(os.path.join(self.ext_dir, dist_info))) | ||
|
|
||
| # assert Azure CLI extended metadata | ||
| self.assertTrue(metadata['azext.isPreview']) | ||
| self.assertTrue(metadata['azext.isExperimental']) | ||
| self.assertEqual(metadata['azext.minCliCoreVersion'], '2.0.67') | ||
|
|
||
| def test_reading_wheel_type_0_31_0_extension_metadata(self): | ||
| """ | ||
| Test wheel>=0.31.0 not containing metadata.json but we can still handle it properly. | ||
| For scenario like 'az extenion add'. | ||
| """ | ||
|
|
||
| # this wheel contains METADATA only | ||
| wheel_0_31_0_packed = get_test_data_file('wheel_0_31_0_packed_extension-0.1.0-py3-none-any.whl') | ||
|
|
||
| zf = zipfile.ZipFile(wheel_0_31_0_packed) | ||
| zf.extractall(self.ext_dir) | ||
|
|
||
| ext_name, ext_version = 'hello', '0.1.0' | ||
|
|
||
| whl_extension = WheelExtension(ext_name, self.ext_dir) | ||
| metadata = whl_extension.get_metadata() # able to read metadata from wheel==0.30.0 built extension | ||
|
|
||
| # wheel type extension generates .dist-info | ||
| dist_info = ext_name + '-' + ext_version + '.dist-info' | ||
|
|
||
| # assert Python metadata | ||
| self.assertEqual(metadata['name'], ext_name) | ||
| self.assertEqual(metadata['version'], ext_version) | ||
| self.assertEqual(metadata['author'], 'Microsoft Corporation') | ||
| self.assertNotIn('metadata.json', os.listdir(os.path.join(self.ext_dir, dist_info))) | ||
|
|
||
| # assert Azure CLI extended metadata | ||
| self.assertTrue(metadata['azext.isPreview']) | ||
| self.assertTrue(metadata['azext.isExperimental']) | ||
| self.assertEqual(metadata['azext.minCliCoreVersion'], '2.0.67') | ||
|
|
||
| def test_reading_wheel_type_extension_from_develop_mode(self): | ||
| """ | ||
| Test wheel type extension but installing from source code. | ||
| For scenario that user are developing extension via 'pip install -e' directlly | ||
| and load it from _CUSTOM_EXT_DIR or GLOBAL_CONFIG_DIR | ||
| """ | ||
|
|
||
| source_code_packaged = get_test_data_file('hello-0.1.0.tar.gz') | ||
|
|
||
| with tarfile.open(source_code_packaged, 'r:gz') as tar: | ||
| tar.extractall(self.ext_dir) | ||
|
|
||
| ext_name, ext_version = 'hello', '0.1.0' | ||
|
|
||
| ext_extension = WheelExtension(ext_name, os.path.join(self.ext_dir, ext_name + '-' + ext_version)) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not use DevExtension?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is to test WheelExtension class not DevExtension. |
||
| metadata = ext_extension.get_metadata() # able to read metadata from source code even in wheel type extension | ||
|
|
||
| # assert Python metadata | ||
| self.assertEqual(metadata['name'], ext_name) | ||
| self.assertEqual(metadata['version'], ext_version) | ||
| self.assertEqual(metadata['author'], 'Microsoft Corporation') | ||
| self.assertNotIn('metadata.json', os.listdir(os.path.join(self.ext_dir, ext_name + '-' + ext_version))) | ||
|
|
||
| # assert Azure CLI extended metadata | ||
| self.assertTrue(metadata['azext.isPreview']) | ||
| self.assertTrue(metadata['azext.isExperimental']) | ||
| self.assertEqual(metadata['azext.minCliCoreVersion'], '2.0.67') | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember these two tags are not supposed to be both True in the future. @zhoxing-ms for confirmation.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, according to the previous design of @jiasli for
isExperimental, an error will be reported if bothisPreviewandisExperimentalare True. @jiasli Please help to see if my understanding is correct~Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for sharing this, I just learnt that.
I think the class
WheelExtensionandDevExtensionis to represent data model not validation. Validation should be a higher level business.This PR is about to test reading the metadata correctly, not validation for
isExperimentalandisPreviewunless we decide to make validation here.Please @jiasli make sure that the concern above has been made in CLI.