зеркало из https://github.com/microsoft/azure-cli.git
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
This commit is contained in:
Родитель
cbe394bcdd
Коммит
5a4504d85c
|
@ -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.
|
||||
|
||||
|
|
|
@ -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.")
|
|
@ -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
|
|
@ -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)
|
|
@ -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)
|
||||
|
|
|
@ -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():
|
||||
|
|
|
@ -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'))
|
||||
]
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче