From a0949b1102018288dc0d801d120f64bcc16559a4 Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Sun, 21 Jun 2015 09:24:27 +0800 Subject: [PATCH 1/3] Added Python Compile Rule --- tests/rules/test_python_compile.py | 17 +++++++++++++++++ thefuck/rules/python_compile.py | 15 +++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 tests/rules/test_python_compile.py create mode 100644 thefuck/rules/python_compile.py diff --git a/tests/rules/test_python_compile.py b/tests/rules/test_python_compile.py new file mode 100644 index 0000000..d7bf988 --- /dev/null +++ b/tests/rules/test_python_compile.py @@ -0,0 +1,17 @@ +import pytest +from thefuck.rules.python_compile import match, get_new_command +from tests.utils import Command + + +@pytest.mark.parametrize('command', [ + Command(script='python foo'), + Command(script='python bar')]) +def test_match(command): + assert match(command, None) + + +@pytest.mark.parametrize('command, new_command', [ + (Command('python foo'), 'python foo.py'), + (Command('python bar'), 'python bar.py')]) +def test_get_new_command(command, new_command): + assert get_new_command(command, None) == new_command diff --git a/thefuck/rules/python_compile.py b/thefuck/rules/python_compile.py new file mode 100644 index 0000000..39adcaf --- /dev/null +++ b/thefuck/rules/python_compile.py @@ -0,0 +1,15 @@ +# Appends .py when compiling python files +# +# Example: +# > python foo +# error: python: can't open file 'foo': [Errno 2] No such file or directory + +# +# + +def match(command, settings): + return (command.script.startswith ('python ') + and not command.script.endswith('.py')) + +def get_new_command(command, settings): + return command.script + '.py' From 897b847975945757e719589f4bc5364bfeb796cd Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Sun, 21 Jun 2015 09:25:20 +0800 Subject: [PATCH 2/3] Added rule --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 22b5c2e..9feb5fc 100644 --- a/README.md +++ b/README.md @@ -181,6 +181,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `open` – prepends `http` to address passed to `open`; * `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; +* `python_compile` – appends missing `.py` when compiling Python files; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' * `rm_dir` – adds `-rf` when you trying to remove directory; * `sl_ls` – changes `sl` to `ls`; From af3e1a555f1874923edffa88f62a76132d9cba12 Mon Sep 17 00:00:00 2001 From: Cami Diez Date: Sun, 21 Jun 2015 09:27:03 +0800 Subject: [PATCH 3/3] Edited python compile rule --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9feb5fc..c70683b 100644 --- a/README.md +++ b/README.md @@ -181,7 +181,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `open` – prepends `http` to address passed to `open`; * `pip_unknown_command` – fixes wrong pip commands, for example `pip instatl/pip install`; * `python_command` – prepends `python` when you trying to run not executable/without `./` python script; -* `python_compile` – appends missing `.py` when compiling Python files; +* `python_compile` – appends missing `.py` when compiling and running Python files; * `quotation_marks` – fixes uneven usage of `'` and `"` when containing args' * `rm_dir` – adds `-rf` when you trying to remove directory; * `sl_ls` – changes `sl` to `ls`;