-
Notifications
You must be signed in to change notification settings - Fork 3.4k
{EventHubs} az eventhubs --help: Args-guided AAZ command tree loading for eventhubs module
#33008
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,17 @@ | |
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
| from azure.cli.core import AzCommandsLoader | ||
| from azure.cli.core import AzCommandsLoader, get_logger | ||
|
|
||
| # pylint: disable=unused-import | ||
|
|
||
| from ._help import helps | ||
|
|
||
| logger = get_logger(__name__) | ||
|
|
||
| _OPTIMIZED_LOADING_CONFIG_SECTION = 'eventhubs' | ||
| _OPTIMIZED_LOADING_CONFIG_KEY = 'optimized_loading' | ||
|
|
||
|
|
||
| class EventhubCommandsLoader(AzCommandsLoader): | ||
|
|
||
|
|
@@ -26,17 +31,35 @@ def __init__(self, cli_ctx=None): | |
|
|
||
| def load_command_table(self, args): | ||
| from azure.cli.command_modules.eventhubs.commands import load_command_table | ||
| from azure.cli.core.aaz import load_aaz_command_table | ||
| from azure.cli.core.aaz import load_aaz_command_table_optimized | ||
|
|
||
| use_optimized = self.cli_ctx.config.getboolean( | ||
| _OPTIMIZED_LOADING_CONFIG_SECTION, _OPTIMIZED_LOADING_CONFIG_KEY, fallback=True) | ||
|
|
||
| # When optimized loading is disabled, still use the optimized loader but | ||
| # pass args=None to force a full load (no trimming). The gutted __init__.py | ||
| # files are incompatible with the old load_aaz_command_table loader, so we | ||
| # cannot fall back to it. | ||
| effective_args = args if use_optimized else None | ||
|
|
||
| if use_optimized and args and args[0:1] == ['eventhubs']: | ||
| logger.warning( | ||
| "The eventhubs module is using optimized command loading for improved performance. " | ||
| "If you encounter any issues, you can disable this by running: " | ||
| "az config set %s.%s=false", | ||
| _OPTIMIZED_LOADING_CONFIG_SECTION, _OPTIMIZED_LOADING_CONFIG_KEY) | ||
|
Comment on lines
+45
to
+50
|
||
|
|
||
| try: | ||
| from . import aaz | ||
| except ImportError: | ||
| aaz = None | ||
| if aaz: | ||
| load_aaz_command_table( | ||
| load_aaz_command_table_optimized( | ||
| loader=self, | ||
| aaz_pkg_name=aaz.__name__, | ||
| args=args | ||
| args=effective_args | ||
| ) | ||
|
|
||
| load_command_table(self, args) | ||
| return self.command_table | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_try_import_module currently catches ImportError as well as ModuleNotFoundError and silently returns None. This can mask real import-time failures inside existing modules (e.g., a bug or missing dependency within a command module) and result in commands/groups silently not being registered. Consider only swallowing ModuleNotFoundError (or checking the missing module name), and letting other ImportErrors propagate or at least logging them at debug level with the exception details.