diff --git a/src/command_modules/azure-cli-extension/HISTORY.rst b/src/command_modules/azure-cli-extension/HISTORY.rst index 8d0e38befa2..2e18b60ef73 100644 --- a/src/command_modules/azure-cli-extension/HISTORY.rst +++ b/src/command_modules/azure-cli-extension/HISTORY.rst @@ -2,9 +2,10 @@ Release History =============== + 0.0.9 ++++++ -Added support for --extra-index-url argument to az extension add and update commands. +Added support for --pip-extra-index-urls argument to az extension add and update commands. 0.0.8 ++++++ diff --git a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/__init__.py b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/__init__.py index 361efff40ed..fc4aae8f0e7 100644 --- a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/__init__.py +++ b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/__init__.py @@ -60,7 +60,7 @@ def load_arguments(self, command): # Extra URLs of package indexes to use. This should point to a repository compliant # with PEP 503 (the simple repository API) or a local directory laid out in the same format. # Similar to the equivalent flag in pip install. - c.argument('extra_index_urls', options_list=['--extra-index-url'], nargs='+', + c.argument('pip_extra_index_urls', options_list=['--pip-extra-index-urls'], nargs='+', help=argparse.SUPPRESS) with self.argument_context('extension add') as c: diff --git a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/custom.py b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/custom.py index cd5fe910e30..21e3b6d340b 100644 --- a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/custom.py +++ b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/custom.py @@ -86,7 +86,7 @@ def _validate_whl_extension(ext_file): _validate_whl_cli_compat(azext_metadata) -def _add_whl_ext(source, ext_sha256=None, extra_index_urls=None): # pylint: disable=too-many-statements +def _add_whl_ext(source, ext_sha256=None, pip_extra_index_urls=None): # pylint: disable=too-many-statements if not source.endswith('.whl'): raise ValueError('Unknown extension type. Only Python wheels are supported.') url_parse_result = urlparse(source) @@ -139,8 +139,9 @@ def _add_whl_ext(source, ext_sha256=None, extra_index_urls=None): # pylint: dis extension_path = get_extension_path(extension_name) pip_args = ['install', '--target', extension_path, ext_file] - if extra_index_urls: - pip_args = pip_args + ['--extra-index-url'] + extra_index_urls + if pip_extra_index_urls: + for extra_index_url in pip_extra_index_urls: + pip_args = pip_args + ['--extra-index-url', extra_index_url] logger.debug('Executing pip with args: %s', pip_args) with HomebrewPipPatch(): @@ -164,7 +165,7 @@ def is_valid_sha256sum(a_file, expected_sum): return expected_sum == computed_hash, computed_hash -def add_extension(source=None, extension_name=None, index_url=None, yes=None, extra_index_urls=None): # pylint: disable=unused-argument +def add_extension(source=None, extension_name=None, index_url=None, yes=None, pip_extra_index_urls=None): # pylint: disable=unused-argument ext_sha256 = None if extension_name: if extension_exists(extension_name): @@ -174,7 +175,7 @@ def add_extension(source=None, extension_name=None, index_url=None, yes=None, ex except NoExtensionCandidatesError as err: logger.debug(err) raise CLIError("No matching extensions for '{}'. Use --debug for more information.".format(extension_name)) - _add_whl_ext(source, ext_sha256=ext_sha256, extra_index_urls=extra_index_urls) + _add_whl_ext(source, ext_sha256=ext_sha256, pip_extra_index_urls=pip_extra_index_urls) def remove_extension(extension_name): @@ -201,7 +202,7 @@ def show_extension(extension_name): raise CLIError(e) -def update_extension(extension_name, index_url=None, extra_index_urls=None): +def update_extension(extension_name, index_url=None, pip_extra_index_urls=None): try: ext = get_extension(extension_name) cur_version = ext.get_version() @@ -219,7 +220,7 @@ def update_extension(extension_name, index_url=None, extra_index_urls=None): shutil.rmtree(extension_path) # Install newer version try: - _add_whl_ext(download_url, ext_sha256=ext_sha256, extra_index_urls=extra_index_urls) + _add_whl_ext(download_url, ext_sha256=ext_sha256, pip_extra_index_urls=pip_extra_index_urls) logger.debug('Deleting backup of old extension at %s', backup_dir) shutil.rmtree(backup_dir) except Exception as err: diff --git a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/tests/latest/test_extension_commands.py b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/tests/latest/test_extension_commands.py index b62845c73e6..9ee0a234690 100644 --- a/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/tests/latest/test_extension_commands.py +++ b/src/command_modules/azure-cli-extension/azure/cli/command_modules/extension/tests/latest/test_extension_commands.py @@ -190,9 +190,9 @@ def test_add_list_show_remove_extension_extra_index_url(self): Tests extension addition while specifying --extra-index-url parameter. :return: """ - test_index = 'https://testpypi.python.org/simple' + extra_index_urls = ['https://testpypi.python.org/simple', 'https://pypi.python.org/simple'] - add_extension(source=MY_EXT_SOURCE, extra_index_urls=[test_index]) + add_extension(source=MY_EXT_SOURCE, pip_extra_index_urls=extra_index_urls) actual = list_extensions() self.assertEqual(len(actual), 1) ext = show_extension(MY_EXT_NAME) @@ -206,14 +206,15 @@ def test_update_extension_extra_index_url(self): Tests extension update while specifying --extra-index-url parameter. :return: """ - test_index = 'https://testpypi.python.org/simple' - add_extension(source=MY_EXT_SOURCE, extra_index_urls=[test_index]) + extra_index_urls = ['https://testpypi.python.org/simple', 'https://pypi.python.org/simple'] + + add_extension(source=MY_EXT_SOURCE, pip_extra_index_urls=extra_index_urls) ext = show_extension(MY_EXT_NAME) self.assertEqual(ext[OUT_KEY_VERSION], '0.0.3+dev') newer_extension = _get_test_data_file('myfirstcliextension-0.0.4+dev-py2.py3-none-any.whl') computed_extension_sha256 = _compute_file_hash(newer_extension) with mock.patch('azure.cli.command_modules.extension.custom.resolve_from_index', return_value=(newer_extension, computed_extension_sha256)): - update_extension(MY_EXT_NAME, extra_index_urls=[test_index]) + update_extension(MY_EXT_NAME, pip_extra_index_urls=extra_index_urls) ext = show_extension(MY_EXT_NAME) self.assertEqual(ext[OUT_KEY_VERSION], '0.0.4+dev')