def _update_command_table_from_modules(args): '''Loads command table(s) When `module_name` is specified, only commands from that module will be loaded. If the module is not found, all commands are loaded. ''' installed_command_modules = [] try: mods_ns_pkg = import_module('azure.cli.command_modules') installed_command_modules = [modname for _, modname, _ in pkgutil.iter_modules(mods_ns_pkg.__path__) if modname not in BLACKLISTED_MODS] except ImportError: pass logger.debug('Installed command modules %s', installed_command_modules) cumulative_elapsed_time = 0 for mod in [m for m in installed_command_modules if m not in BLACKLISTED_MODS]: try: start_time = timeit.default_timer() module_command_table = _load_module_command_loader(self, args, mod) self.command_table.update(module_command_table) cmd_to_mod_map.update({cmd: mod for cmd in list(module_command_table.keys())}) elapsed_time = timeit.default_timer() - start_time logger.debug("Loaded module '%s' in %.3f seconds.", mod, elapsed_time) cumulative_elapsed_time += elapsed_time except Exception as ex: # pylint: disable=broad-except # Changing this error message requires updating CI script that checks for failed # module loading. import azure.cli.core.telemetry as telemetry logger.error("Error loading command module '%s'", mod) telemetry.set_exception(exception=ex, fault_type='module-load-error-' + mod, summary='Error loading module: {}'.format(mod)) logger.debug(traceback.format_exc()) logger.debug("Loaded all modules in %.3f seconds. " "(note: there's always an overhead with the first module loaded)", cumulative_elapsed_time)
def _update_command_table_from_modules(args, command_modules=None): """Loads command tables from modules and merge into the main command table. :param args: Arguments of the command. :param list command_modules: Command modules to load, in the format like ['resource', 'profile']. If None, will do module discovery and load all modules. If [], only ALWAYS_LOADED_MODULES will be loaded. Otherwise, the list will be extended using ALWAYS_LOADED_MODULES. """ # As command modules are built-in, the existence of modules in ALWAYS_LOADED_MODULES is NOT checked if command_modules is not None: command_modules.extend(ALWAYS_LOADED_MODULES) else: # Perform module discovery command_modules = [] try: mods_ns_pkg = import_module('azure.cli.command_modules') command_modules = [modname for _, modname, _ in pkgutil.iter_modules(mods_ns_pkg.__path__)] logger.debug('Discovered command modules: %s', command_modules) except ImportError as e: logger.warning(e) count = 0 cumulative_elapsed_time = 0 cumulative_group_count = 0 cumulative_command_count = 0 logger.debug("Loading command modules:") logger.debug(self.header_mod) for mod in [m for m in command_modules if m not in BLOCKED_MODS]: try: start_time = timeit.default_timer() module_command_table, module_group_table = _load_module_command_loader(self, args, mod) for cmd in module_command_table.values(): cmd.command_source = mod self.command_table.update(module_command_table) self.command_group_table.update(module_group_table) elapsed_time = timeit.default_timer() - start_time logger.debug(self.item_format_string, mod, elapsed_time, len(module_group_table), len(module_command_table)) count += 1 cumulative_elapsed_time += elapsed_time cumulative_group_count += len(module_group_table) cumulative_command_count += len(module_command_table) except Exception as ex: # pylint: disable=broad-except # Changing this error message requires updating CI script that checks for failed # module loading. import azure.cli.core.telemetry as telemetry logger.error("Error loading command module '%s': %s", mod, ex) telemetry.set_exception(exception=ex, fault_type='module-load-error-' + mod, summary='Error loading module: {}'.format(mod)) logger.debug(traceback.format_exc()) # Summary line logger.debug(self.item_format_string, "Total ({})".format(count), cumulative_elapsed_time, cumulative_group_count, cumulative_command_count)
def _update_command_table_from_modules(args): '''Loads command table(s) When `module_name` is specified, only commands from that module will be loaded. If the module is not found, all commands are loaded. ''' installed_command_modules = [] try: mods_ns_pkg = import_module('azure.cli.command_modules') installed_command_modules = [modname for _, modname, _ in pkgutil.iter_modules(mods_ns_pkg.__path__) if modname not in BLACKLISTED_MODS] except ImportError as e: logger.warning(e) logger.debug('Installed command modules %s', installed_command_modules) cumulative_elapsed_time = 0 for mod in [m for m in installed_command_modules if m not in BLACKLISTED_MODS]: try: start_time = timeit.default_timer() module_command_table, module_group_table = _load_module_command_loader(self, args, mod) for cmd in module_command_table.values(): cmd.command_source = mod self.command_table.update(module_command_table) self.command_group_table.update(module_group_table) elapsed_time = timeit.default_timer() - start_time logger.debug("Loaded module '%s' in %.3f seconds.", mod, elapsed_time) cumulative_elapsed_time += elapsed_time except Exception as ex: # pylint: disable=broad-except # Changing this error message requires updating CI script that checks for failed # module loading. import azure.cli.core.telemetry as telemetry logger.error("Error loading command module '%s'", mod) telemetry.set_exception(exception=ex, fault_type='module-load-error-' + mod, summary='Error loading module: {}'.format(mod)) logger.debug(traceback.format_exc()) logger.debug("Loaded all modules in %.3f seconds. " "(note: there's always an overhead with the first module loaded)", cumulative_elapsed_time)