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

{Core} Use knack 0.8.0rc2 #16301

Merged
merged 9 commits into from
Dec 30, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 12 additions & 0 deletions src/azure-cli-core/azure/cli/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ def __init__(self, **kwargs):

self.progress_controller = None

_configure_knack()

def refresh_request_id(self):
"""Assign a new random GUID as x-ms-client-request-id

Expand Down Expand Up @@ -851,3 +853,13 @@ def get_default_cli():
logging_cls=AzCliLogging,
output_cls=AzOutputProducer,
help_cls=AzCliHelp)


def _configure_knack():
"""Override consts defined in knack to make them Azure CLI-specific."""
from knack.util import status_tag_messages
ref_message = "Reference and support levels: https://aka.ms/CLI_refstatus"
# Override the preview message
status_tag_messages['preview'] = "{} is in preview and under development. " + ref_message
# Override the experimental message
status_tag_messages['experimental'] = "{} is experimental and under development. " + ref_message
32 changes: 29 additions & 3 deletions src/azure-cli-core/azure/cli/core/azlogging.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

- Level: Based on the verbosity option given by users, the logging levels for root and CLI parent loggers are:

CLI Parent Root
'azure' parent Root
Console File Console File
omitted Warning Debug Critical Debug
--verbose Info Debug Critical Debug
Expand All @@ -30,7 +30,7 @@
from azure.cli.core.commands.events import EVENT_INVOKER_PRE_CMD_TBL_TRUNCATE

from knack.events import EVENT_CLI_POST_EXECUTE
from knack.log import CLILogging, get_logger
from knack.log import CLILogging
from knack.util import ensure_dir


Expand All @@ -42,13 +42,22 @@ class AzCliLogging(CLILogging):
_COMMAND_METADATA_LOGGER = 'az_command_data_logger'

def __init__(self, name, cli_ctx=None):
super(AzCliLogging, self).__init__(name, cli_ctx)
super(AzCliLogging, self).__init__(name, cli_ctx, cli_logger_name="azure")
self.command_log_dir = os.path.join(cli_ctx.config.config_dir, 'commands')
self.command_logger_handler = None
self.command_metadata_logger = None
self.cli_ctx.register_event(EVENT_INVOKER_PRE_CMD_TBL_TRUNCATE, AzCliLogging.init_command_file_logging)
self.cli_ctx.register_event(EVENT_CLI_POST_EXECUTE, AzCliLogging.deinit_cmd_metadata_logging)

import knack.log
knack.log.get_logger = get_logger

def configure(self, args):
super(AzCliLogging, self).configure(args)
from knack.log import CliLogLevel
if self.log_level == CliLogLevel.DEBUG:
logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel(logging.CRITICAL)

def get_command_log_dir(self):
return self.command_log_dir

Expand Down Expand Up @@ -204,3 +213,20 @@ def __enter__(self):
def __exit__(self, exc_type, exc_val, exc_tb):
if self.hdlr:
self.logger.removeHandler(self.hdlr)


def get_logger(module_name=None):
"""Override knack.log.get_logger to prefix 'azext_' with 'azure.cli.', so that logs
printed by 'azext_*' modules falls into the 'azure' logger.

For example:
azext_account.generated.custom => azure.cli.azext_account.generated.custom
"""
if module_name:
logger_name = module_name
if logger_name.startswith('azext_'):
logger_name = "azure.cli." + module_name
else:
# Any get_logger invocation without a logger name goes to 'azure.cli'
logger_name = 'azure.cli'
return logging.getLogger(logger_name)
6 changes: 3 additions & 3 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def _resolve_preview_and_deprecation_warnings(self, cmd, parsed_args):
deprecate_kwargs['object_type'] = 'command'
del deprecate_kwargs['_get_tag']
del deprecate_kwargs['_get_message']
deprecations.append(ImplicitDeprecated(**deprecate_kwargs))
deprecations.append(ImplicitDeprecated(cli_ctx=self.cli_ctx, **deprecate_kwargs))

previews = [] + getattr(parsed_args, '_argument_previews', [])
if cmd.preview_info:
Expand All @@ -771,7 +771,7 @@ def _resolve_preview_and_deprecation_warnings(self, cmd, parsed_args):
preview_kwargs['object_type'] = 'command'
del preview_kwargs['_get_tag']
del preview_kwargs['_get_message']
previews.append(ImplicitPreviewItem(**preview_kwargs))
previews.append(ImplicitPreviewItem(cli_ctx=self.cli_ctx,**preview_kwargs))

experimentals = [] + getattr(parsed_args, '_argument_experimentals', [])
if cmd.experimental_info:
Expand All @@ -789,7 +789,7 @@ def _resolve_preview_and_deprecation_warnings(self, cmd, parsed_args):
experimental_kwargs['object_type'] = 'command'
del experimental_kwargs['_get_tag']
del experimental_kwargs['_get_message']
experimentals.append(ImplicitExperimentalItem(**experimental_kwargs))
experimentals.append(ImplicitExperimentalItem(cli_ctx=self.cli_ctx, **experimental_kwargs))

if not self.cli_ctx.only_show_errors:
for d in deprecations:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ def _prepare_client_kwargs_track2(cli_ctx):
client_kwargs['logging_enable'] = True

# Disable ARMHttpLoggingPolicy which logs only allowed headers
from azure.core.pipeline.policies import SansIOHTTPPolicy
client_kwargs['http_logging_policy'] = SansIOHTTPPolicy()
# from azure.core.pipeline.policies import SansIOHTTPPolicy
# client_kwargs['http_logging_policy'] = SansIOHTTPPolicy()

# Prepare User-Agent header, used by UserAgentPolicy
client_kwargs['user_agent'] = get_az_user_agent()
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
'colorama~=0.4.1',
'humanfriendly>=4.7,<9.0',
'jmespath',
'knack==0.7.2',
'knack==0.8.0rc1',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use ~=0.8.0rc1 but 0.8.1 won't fit (it should).

>>> from packaging.specifiers import SpecifierSet
>>> "0.8.1" in SpecifierSet("~=0.8.0rc1")
False

This behavior contradicts PEP 440, and this bug is mentioned at pypa/packaging#100.

'msal~=1.0.0',
'msal-extensions~=0.1.3',
'msrestazure>=0.6.3',
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Darwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ isodate==0.6.0
Jinja2==2.10.1
jmespath==0.9.5
jsmin==2.2.2
knack==0.7.2
knack==0.8.0rc1
MarkupSafe==1.1.1
mock==4.0.2
msrest==0.6.18
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.Linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ isodate==0.6.0
Jinja2==2.10.1
jmespath==0.9.5
jsmin==2.2.2
knack==0.7.2
knack==0.8.0rc1
MarkupSafe==1.1.1
mock==4.0.2
msrest==0.6.18
Expand Down
2 changes: 1 addition & 1 deletion src/azure-cli/requirements.py3.windows.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ isodate==0.6.0
Jinja2==2.10.1
jmespath==0.9.5
jsmin==2.2.2
knack==0.7.2
knack==0.8.0rc1
MarkupSafe==1.1.1
mock==4.0.2
msrest==0.6.18
Expand Down