Skip to content
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

A bug fix in the extra-index-url argument for az extension add and update commands. #5491

Merged
merged 9 commits into from Feb 6, 2018
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
3 changes: 2 additions & 1 deletion src/command_modules/azure-cli-extension/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
++++++
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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():
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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()
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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')

Expand Down