def _list_command_paths(self, parent): ctx = click_get_current_context_safe() res = { parent.path + "." + cmd for cmd in super(Group, parent).list_commands(ctx) } return res
def load_plugins(self): for plugin in set(self.plugin_source.list_plugins()) - self.plugin_cache: try: before = datetime.now() mod = self.plugin_source.load_plugin(plugin) if hasattr(mod, 'load_plugin'): mod.load_plugin() after = datetime.now() spent_time = (after-before).total_seconds() LOGGER.develop("Plugin {} loaded in {} seconds".format(plugin, spent_time)) threshold = 0.1 if spent_time > threshold: LOGGER.debug( "Plugin {} took more than {} seconds to load ({})." " You might consider disabling the plugin when you don't use it." " Or contribute to its dev to make it load faster.".format( plugin, threshold, spent_time, ) ) except Exception as e: ctx = click_get_current_context_safe() if ctx is None or not ctx.resilient_parsing: plugin_name = plugin.replace("_", "/") LOGGER.warning( "Error when loading plugin {}" " (if the plugin is no more useful," " consider uninstalling the plugins {}): {}".format( plugin_name, plugin_name, e, )) on_command_loading_error() self.plugin_cache.add(plugin)
def load_plugins(): plugindirs = [] if config.local_profile and config.local_profile.pluginsdir: plugindirs.append(config.local_profile.pluginsdir) if config.global_profile.pluginsdir: plugindirs.append(config.global_profile.pluginsdir) for recipe in config.all_enabled_recipes: plugindirs.append(recipe.pluginsdir) plugindirs.extend(config.plugindirs) global plugins if plugins is None: plugins = plugin_base.make_plugin_source(searchpath=plugindirs) disabled_plugins = { plugin.replace("/", "_") for plugin in config.get_settings('plugins').get( "disabled_plugins", []) } plugins.persist = True for plugin in set( plugins.list_plugins()) - disabled_plugins - plugins_cache: try: before = datetime.now() mod = plugins.load_plugin(plugin) if hasattr(mod, 'load_plugin'): mod.load_plugin() after = datetime.now() spent_time = (after - before).total_seconds() LOGGER.develop("Plugin {} loaded in {} seconds".format( plugin, spent_time)) threshold = 0.1 if spent_time > threshold: LOGGER.debug( "Plugin {} took more than {} seconds to load ({})." " You might consider disabling the plugin when you don't use it." " Or contribute to its dev to make it load faster.".format( plugin, threshold, spent_time, )) except Exception as e: ctx = click_get_current_context_safe() if ctx is None or not ctx.resilient_parsing: plugin_name = plugin.replace("_", "/") LOGGER.warning( "Error when loading plugin {}" " (if the plugin is no more useful," " consider uninstalling the plugins {}): {}".format( plugin_name, plugin_name, e, )) on_command_loading_error() plugins_cache.add(plugin) for hook in afterloads: if hook not in afterloads_cache: hook() afterloads_cache.add(hook)
def migrate_profiles(): ctx = click_get_current_context_safe() for profile in config.root_profiles + list(config.all_recipes): if profile is not None: profile.migrate_if_needed( config.persist_migration and not ( ctx is not None and ctx.resilient_parsing ) )
def get_ctx(path, side_effects=False, resilient_parsing=None): if resilient_parsing is None: ctx = click_get_current_context_safe() resilient_parsing = (ctx is not None and ctx.resilient_parsing) or False key = tuple(path) if key not in get_ctx_cache: if side_effects: res = resolve_context_with_side_effects(path, resilient_parsing=resilient_parsing) else: with temp_config(): res = resolve_context_with_side_effects(path, resilient_parsing=resilient_parsing) assert res is not None, "Could not interpret the command {}".format(".".join(path)) get_ctx_cache[key] = res else: res = get_ctx_cache[key] return res
def _get_command(self, path, parent): path = path.split(".") cmd_name = path[-1] ctx = click_get_current_context_safe() return super(Group, parent).get_command(ctx, cmd_name)