From 5a4504d85c967e8796d0057c3eb2d823270b0894 Mon Sep 17 00:00:00 2001 From: Derek Bekoe Date: Tue, 17 Oct 2017 09:40:56 -0700 Subject: [PATCH] Remove packaged release patches (#4688) * Remove packaged release patches Removes the following patches: 1. The packaged installs do not support `az component` so we patch this module with appropriate messages. 2. The CLI has a feature that checks PyPI for a command module if it's not installed and the user attempts to run it. This patch disables this as components cannot be installed in packaged installs. * Fix style --- packaged_releases/README.md | 13 -------- .../patches/patch_component_custom.py | 33 ------------------- packaged_releases/patches/patch_pkg_util.py | 7 ---- .../azure/cli/core/_pkg_util.py | 28 ---------------- src/azure-cli-core/azure/cli/core/parser.py | 16 --------- .../cli/command_modules/component/custom.py | 8 +++++ tools/automation/release/packaged.py | 5 --- 7 files changed, 8 insertions(+), 102 deletions(-) delete mode 100644 packaged_releases/patches/patch_component_custom.py delete mode 100644 packaged_releases/patches/patch_pkg_util.py delete mode 100644 src/azure-cli-core/azure/cli/core/_pkg_util.py diff --git a/packaged_releases/README.md b/packaged_releases/README.md index af6f437ba..148f0189b 100644 --- a/packaged_releases/README.md +++ b/packaged_releases/README.md @@ -74,16 +74,3 @@ Follow the instructions in the `debian`, `docker`, `windows`, `rpm` and `homebre --------------------- Modify the packaged release history with release notes on this release and create a PR for this change. - - ------------- - - -Info on Patches ---------------- -The `patch_*` files in the `patches` subdirectory are useful when creating the patches in the Homebrew formula. - -Currently, two patches are applied: -1. The packaged installs do not support `az component` so we patch this module with appropriate messages. -2. The CLI has a feature that checks PyPI for a command module if it's not installed and the user attempts to run it. This patch disables this as components cannot be installed in packaged installs. - diff --git a/packaged_releases/patches/patch_component_custom.py b/packaged_releases/patches/patch_component_custom.py deleted file mode 100644 index 39e283987..000000000 --- a/packaged_releases/patches/patch_component_custom.py +++ /dev/null @@ -1,33 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -from azure.cli.core.util import CLIError - -MSG_TMPL = """ -az component and subcommands are not available with the current Azure CLI installation. -If installed with apt-get, please use 'apt-get update' to update this installation. -If installed with Docker, please use 'docker pull' to update this installation. -If installed with Windows MSI, download the new MSI to update this installation. -{} -""" - -def _raise_error(msg): - raise CLIError(MSG_TMPL.format(msg)) - -def list_components(): - """ List the installed components """ - _raise_error("Use 'az --version' to list component versions.") - -def list_available_components(): - """ List publicly available components that can be installed """ - _raise_error("No additional components available.") - -def remove(component_name): - """ Remove a component """ - _raise_error("Components cannot be removed.") - -def update(private=False, pre=False, link=None, additional_components=None, allow_third_party=False): - """ Update the CLI and all installed components """ - _raise_error("Components cannot be updated.") diff --git a/packaged_releases/patches/patch_pkg_util.py b/packaged_releases/patches/patch_pkg_util.py deleted file mode 100644 index e73b7bc13..000000000 --- a/packaged_releases/patches/patch_pkg_util.py +++ /dev/null @@ -1,7 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -def handle_module_not_installed(_): - pass diff --git a/src/azure-cli-core/azure/cli/core/_pkg_util.py b/src/azure-cli-core/azure/cli/core/_pkg_util.py deleted file mode 100644 index c57374eaa..000000000 --- a/src/azure-cli-core/azure/cli/core/_pkg_util.py +++ /dev/null @@ -1,28 +0,0 @@ -# -------------------------------------------------------------------------------------------- -# Copyright (c) Microsoft Corporation. All rights reserved. -# Licensed under the MIT License. See License.txt in the project root for license information. -# -------------------------------------------------------------------------------------------- - -# Each package management system should patch this file with their own implementations of these. - -from azure.cli.core.util import COMPONENT_PREFIX -import azure.cli.core.azlogging as azlogging - -logger = azlogging.get_az_logger(__name__) - - -def handle_module_not_installed(module_name): - try: - import xmlrpclib - except ImportError: - import xmlrpc.client as xmlrpclib # pylint: disable=import-error - query = {'author': 'Microsoft Corporation', 'author_email': 'azpycli'} - logger.debug("Checking PyPI for modules using query '%s'", query) - client = xmlrpclib.ServerProxy('https://pypi.python.org/pypi') - pypi_hits = client.search(query) - logger.debug("Found %d result(s)", len(pypi_hits)) - for hit in pypi_hits: - if hit['name'] == '{}{}'.format(COMPONENT_PREFIX, module_name): - logger.debug("Found module that matches '%s' - %s", module_name, hit) - logger.warning("Install the '%s' module with 'az component update --add %s'", - module_name, module_name) diff --git a/src/azure-cli-core/azure/cli/core/parser.py b/src/azure-cli-core/azure/cli/core/parser.py index d1fc181b7..a6fe8702d 100644 --- a/src/azure-cli-core/azure/cli/core/parser.py +++ b/src/azure-cli-core/azure/cli/core/parser.py @@ -11,7 +11,6 @@ import argcomplete import azure.cli.core.telemetry as telemetry import azure.cli.core._help as _help from azure.cli.core.util import CLIError -from azure.cli.core._pkg_util import handle_module_not_installed import azure.cli.core.azlogging as azlogging @@ -145,27 +144,12 @@ class AzCliCommandParser(argparse.ArgumentParser): self.subparsers[tuple(path[0:length])] = parent_subparser return parent_subparser - def _handle_command_package_error(self, err_msg): # pylint: disable=no-self-use - if err_msg and err_msg.startswith('argument _command_package: invalid choice:'): - import re - try: - possible_module = re.search("argument _command_package: invalid choice: '(.+?)'", - err_msg).group(1) - handle_module_not_installed(possible_module) - except AttributeError: - # regular expression pattern match failed so unable to retrieve - # module name - pass - except Exception as e: # pylint: disable=broad-except - logger.debug('Unable to handle module not installed: %s', str(e)) - def validation_error(self, message): telemetry.set_user_fault('validation error') return super(AzCliCommandParser, self).error(message) def error(self, message): telemetry.set_user_fault('parse error: {}'.format(message)) - self._handle_command_package_error(message) args = {'prog': self.prog, 'message': message} logger.error('%(prog)s: error: %(message)s', args) self.print_usage(sys.stderr) diff --git a/src/command_modules/azure-cli-component/azure/cli/command_modules/component/custom.py b/src/command_modules/azure-cli-component/azure/cli/command_modules/component/custom.py index dddee736e..516e476ab 100644 --- a/src/command_modules/azure-cli-component/azure/cli/command_modules/component/custom.py +++ b/src/command_modules/azure-cli-component/azure/cli/command_modules/component/custom.py @@ -9,6 +9,7 @@ from six import StringIO from azure.cli.core.util import CLIError from azure.cli.core._config import az_config import azure.cli.core.azlogging as azlogging +from azure.cli.core.prompting import prompt_y_n, NoTTYException logger = azlogging.get_az_logger(__name__) @@ -18,6 +19,13 @@ COMPONENT_PREFIX = 'azure-cli-' def _deprecate_warning(): logger.warning("The 'component' commands will be deprecated in the future.") + logger.warning("az component and subcommands may not work unless the CLI is installed with pip.") + try: + ans = prompt_y_n("Are you sure you want to continue?", default='n') + if not ans: + raise CLIError('Operation cancelled.') + except NoTTYException: + pass def _verify_not_dev(): diff --git a/tools/automation/release/packaged.py b/tools/automation/release/packaged.py index b55fe7f24..a3c1d9d70 100644 --- a/tools/automation/release/packaged.py +++ b/tools/automation/release/packaged.py @@ -38,11 +38,6 @@ class Patch(object): # pylint: disable=too-few-public-methods PATCHES = [ - Patch(os.path.join('packaged_releases', 'patches', 'patch_pkg_util.py'), - os.path.join('src', 'azure-cli-core', 'azure', 'cli', 'core', '_pkg_util.py')), - Patch(os.path.join('packaged_releases', 'patches', 'patch_component_custom.py'), - os.path.join('src', 'command_modules', 'azure-cli-component', 'azure', 'cli', - 'command_modules', 'component', 'custom.py')) ]