diff --git a/.travis.yml b/.travis.yml index 3f8a64eb..b124bb3a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,8 @@ language: python python: - "3.4" + - "3.3" + - "2.7" install: - python setup.py develop - pip install -r requirements.txt diff --git a/README.md b/README.md index b597ad33..9858b3cf 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ Did you mean this? Install `The Fuck`: ```bash -sudo pip3 install thefuck +sudo pip install thefuck ``` And add to `.bashrc` or `.zshrc`: @@ -66,8 +66,8 @@ alias fuck='$(thefuck $(fc -ln -1))' Install `The Fuck` for development: ```bash -pip3 install -r requirements.txt -python3 setup.py develop +pip install -r requirements.txt +python setup.py develop ``` Run tests: diff --git a/requirements.txt b/requirements.txt index e079f8a6..625bed64 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,2 @@ pytest +mock diff --git a/setup.py b/setup.py index a95ba457..a90af29b 100644 --- a/setup.py +++ b/setup.py @@ -11,5 +11,6 @@ setup(name='thefuck', packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), include_package_data=True, zip_safe=False, + install_requires=['pathlib'], entry_points={'console_scripts': [ 'thefuck = thefuck.main:main']}) diff --git a/tests/rules/test_no_command.py b/tests/rules/test_no_command.py index 6af1a32f..1de466a6 100644 --- a/tests/rules/test_no_command.py +++ b/tests/rules/test_no_command.py @@ -1,6 +1,6 @@ -from unittest.mock import patch, Mock -import pytest from subprocess import PIPE +from mock import patch, Mock +import pytest from thefuck.rules.no_command import match, get_new_command from thefuck.main import Command diff --git a/tests/test_main.py b/tests/test_main.py index 656acd1f..c4db3557 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,6 +1,6 @@ -from unittest.mock import patch, Mock from subprocess import PIPE from pathlib import PosixPath, Path +from mock import patch, Mock from thefuck import main diff --git a/thefuck/__init__.py b/thefuck/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/thefuck/main.py b/thefuck/main.py index 1f48faf7..91d5974b 100644 --- a/thefuck/main.py +++ b/thefuck/main.py @@ -10,7 +10,7 @@ Command = namedtuple('Command', ('script', 'stdout', 'stderr')) Rule = namedtuple('Rule', ('match', 'get_new_command')) -def setup_user_dir() -> Path: +def setup_user_dir(): """Returns user config dir, create it when it doesn't exists.""" user_dir = Path(expanduser('~/.thefuck')) if not user_dir.is_dir(): @@ -20,7 +20,7 @@ def setup_user_dir() -> Path: return user_dir -def get_settings(user_dir: Path): +def get_settings(user_dir): """Returns prepared settings module.""" settings = load_source('settings', str(user_dir.joinpath('settings.py'))) @@ -29,7 +29,7 @@ def get_settings(user_dir: Path): return settings -def is_rule_enabled(settings, rule: Path) -> bool: +def is_rule_enabled(settings, rule): """Returns `True` when rule mentioned in `rules` or `rules` isn't defined. @@ -37,23 +37,23 @@ def is_rule_enabled(settings, rule: Path) -> bool: return settings.rules is None or rule.name[:-3] in settings.rules -def load_rule(rule: Path) -> Rule: +def load_rule(rule): """Imports rule module and returns it.""" rule_module = load_source(rule.name[:-3], str(rule)) return Rule(rule_module.match, rule_module.get_new_command) -def get_rules(user_dir: Path, settings) -> [Rule]: +def get_rules(user_dir, settings): """Returns all enabled rules.""" bundled = Path(__file__).parent\ .joinpath('rules')\ .glob('*.py') user = user_dir.joinpath('rules').glob('*.py') return [load_rule(rule) for rule in list(bundled) + list(user) - if is_rule_enabled(settings, rule)] + if rule.name != '__init__.py' and is_rule_enabled(settings, rule)] -def get_command(args: [str]) -> Command: +def get_command(args): """Creates command from `args` and executes it.""" script = ' '.join(args[1:]) result = Popen(script, shell=True, stdout=PIPE, stderr=PIPE) @@ -61,14 +61,14 @@ def get_command(args: [str]) -> Command: result.stderr.read().decode()) -def get_matched_rule(command: Command, rules: [Rule], settings) -> Rule: +def get_matched_rule(command, rules, settings): """Returns first matched rule for command.""" for rule in rules: if rule.match(command, settings): return rule -def run_rule(rule: Rule, command: Command, settings): +def run_rule(rule, command, settings): """Runs command from rule for passed command.""" new_command = rule.get_new_command(command, settings) print(new_command) diff --git a/thefuck/rules/__init__.py b/thefuck/rules/__init__.py new file mode 100644 index 00000000..e69de29b