From 2b750bac8b2cffa17963832f13836e02be46a215 Mon Sep 17 00:00:00 2001 From: mcarton Date: Wed, 26 Aug 2015 19:14:03 +0200 Subject: [PATCH] Log rule import times --- thefuck/corrector.py | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/thefuck/corrector.py b/thefuck/corrector.py index 41713582..b7647e40 100644 --- a/thefuck/corrector.py +++ b/thefuck/corrector.py @@ -1,21 +1,23 @@ -import sys +from . import conf, logs +from .utils import eager from imp import load_source from pathlib import Path -from . import conf, types, logs -from .utils import eager +from thefuck.types import CorrectedCommand, Rule +import sys def load_rule(rule, settings): """Imports rule module and returns it.""" name = rule.name[:-3] - rule_module = load_source(name, str(rule)) - priority = getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY) - return types.Rule(name, rule_module.match, - rule_module.get_new_command, - getattr(rule_module, 'enabled_by_default', True), - getattr(rule_module, 'side_effect', None), - settings.priority.get(name, priority), - getattr(rule_module, 'requires_output', True)) + with logs.debug_time(u'Importing rule: {};'.format(name), settings): + rule_module = load_source(name, str(rule)) + priority = getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY) + return Rule(name, rule_module.match, + rule_module.get_new_command, + getattr(rule_module, 'enabled_by_default', True), + getattr(rule_module, 'side_effect', None), + settings.priority.get(name, priority), + getattr(rule_module, 'requires_output', True)) def get_loaded_rules(rules, settings): @@ -59,11 +61,11 @@ def make_corrected_commands(command, rules, settings): for rule in rules: new_commands = rule.get_new_command(command, settings) if not isinstance(new_commands, list): - new_commands = [new_commands] + new_commands = (new_commands,) for n, new_command in enumerate(new_commands): - yield types.CorrectedCommand(script=new_command, - side_effect=rule.side_effect, - priority=(n + 1) * rule.priority) + yield CorrectedCommand(script=new_command, + side_effect=rule.side_effect, + priority=(n + 1) * rule.priority) def remove_duplicates(corrected_commands):