1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-22 12:58:33 +00:00

Log rule import times

This commit is contained in:
mcarton 2015-08-26 19:14:03 +02:00
parent 7be71a0121
commit 2b750bac8b

View File

@ -1,16 +1,18 @@
import sys from . import conf, logs
from .utils import eager
from imp import load_source from imp import load_source
from pathlib import Path from pathlib import Path
from . import conf, types, logs from thefuck.types import CorrectedCommand, Rule
from .utils import eager import sys
def load_rule(rule, settings): def load_rule(rule, settings):
"""Imports rule module and returns it.""" """Imports rule module and returns it."""
name = rule.name[:-3] name = rule.name[:-3]
with logs.debug_time(u'Importing rule: {};'.format(name), settings):
rule_module = load_source(name, str(rule)) rule_module = load_source(name, str(rule))
priority = getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY) priority = getattr(rule_module, 'priority', conf.DEFAULT_PRIORITY)
return types.Rule(name, rule_module.match, return Rule(name, rule_module.match,
rule_module.get_new_command, rule_module.get_new_command,
getattr(rule_module, 'enabled_by_default', True), getattr(rule_module, 'enabled_by_default', True),
getattr(rule_module, 'side_effect', None), getattr(rule_module, 'side_effect', None),
@ -59,9 +61,9 @@ def make_corrected_commands(command, rules, settings):
for rule in rules: for rule in rules:
new_commands = rule.get_new_command(command, settings) new_commands = rule.get_new_command(command, settings)
if not isinstance(new_commands, list): if not isinstance(new_commands, list):
new_commands = [new_commands] new_commands = (new_commands,)
for n, new_command in enumerate(new_commands): for n, new_command in enumerate(new_commands):
yield types.CorrectedCommand(script=new_command, yield CorrectedCommand(script=new_command,
side_effect=rule.side_effect, side_effect=rule.side_effect,
priority=(n + 1) * rule.priority) priority=(n + 1) * rule.priority)