mirror of
https://github.com/nvbn/thefuck.git
synced 2025-01-31 10:11:14 +00:00
Merge branch 'flake8' of https://github.com/josephfrazier/thefuck into josephfrazier-flake8
# Conflicts: # thefuck/system/unix.py # thefuck/system/win32.py
This commit is contained in:
commit
725ef271b1
@ -42,6 +42,7 @@ install:
|
||||
- python setup.py develop
|
||||
- rm -rf build
|
||||
script:
|
||||
- flake8
|
||||
- export COVERAGE_PYTHON_VERSION=python-${TRAVIS_PYTHON_VERSION:0:1}
|
||||
- export RUN_TESTS="coverage run --source=thefuck,tests -m py.test -v --capture=sys tests"
|
||||
- if [[ $TRAVIS_PYTHON_VERSION == 3.6 && $TRAVIS_OS_NAME != "osx" ]]; then $RUN_TESTS --enable-functional; fi
|
||||
|
@ -388,6 +388,12 @@ pip install -r requirements.txt
|
||||
python setup.py develop
|
||||
```
|
||||
|
||||
Run code style checks:
|
||||
|
||||
```bash
|
||||
flake8
|
||||
```
|
||||
|
||||
Run unit tests:
|
||||
|
||||
```bash
|
||||
|
@ -20,4 +20,5 @@ install:
|
||||
- "%PYTHON%/Scripts/pip.exe install -U -r requirements.txt"
|
||||
|
||||
test_script:
|
||||
- "%PYTHON%/python.exe -m flake8"
|
||||
- "%PYTHON%/Scripts/py.test.exe -sv"
|
||||
|
@ -1,4 +1,5 @@
|
||||
pip
|
||||
flake8
|
||||
pytest
|
||||
mock
|
||||
pytest-mock
|
||||
|
@ -8,13 +8,13 @@ def stderr():
|
||||
return ("Error: Could not symlink bin/gcp\n"
|
||||
"Target /usr/local/bin/gcp\n"
|
||||
"already exists. You may want to remove it:\n"
|
||||
"rm '/usr/local/bin/gcp'\n"
|
||||
" rm '/usr/local/bin/gcp'\n"
|
||||
"\n"
|
||||
"To force the link and overwrite all conflicting files:\n"
|
||||
"brew link --overwrite coreutils\n"
|
||||
" brew link --overwrite coreutils\n"
|
||||
"\n"
|
||||
"To list all files that would be deleted:\n"
|
||||
"brew link --overwrite --dry-run coreutils\n")
|
||||
" brew link --overwrite --dry-run coreutils\n")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@ -29,7 +29,7 @@ def test_match(stderr, script):
|
||||
|
||||
@pytest.mark.parametrize('script', ['brew link coreutils'])
|
||||
def test_not_match(script):
|
||||
stderr=''
|
||||
stderr = ''
|
||||
assert not match(Command(script=script, stderr=stderr))
|
||||
|
||||
|
||||
|
@ -22,7 +22,7 @@ def test_match(stdout, script):
|
||||
|
||||
@pytest.mark.parametrize('script', ['brew remove gnuplot'])
|
||||
def test_not_match(script):
|
||||
stdout='Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n'
|
||||
stdout = 'Uninstalling /usr/local/Cellar/gnuplot/5.0.4_1... (44 files, 2.3M)\n'
|
||||
assert not match(Command(script=script, stdout=stdout))
|
||||
|
||||
|
||||
|
@ -21,8 +21,8 @@ def test_match(brew_unknown_cmd):
|
||||
|
||||
|
||||
def test_get_new_command(brew_unknown_cmd, brew_unknown_cmd2):
|
||||
assert get_new_command(Command('brew inst', stderr=brew_unknown_cmd)) \
|
||||
== ['brew list', 'brew install', 'brew uninstall']
|
||||
assert (get_new_command(Command('brew inst', stderr=brew_unknown_cmd))
|
||||
== ['brew list', 'brew install', 'brew uninstall'])
|
||||
|
||||
cmds = get_new_command(Command('brew instaa', stderr=brew_unknown_cmd2))
|
||||
assert 'brew install' in cmds
|
||||
|
@ -48,9 +48,9 @@ def test_match(composer_not_command, composer_not_command_one_of_this):
|
||||
|
||||
|
||||
def test_get_new_command(composer_not_command, composer_not_command_one_of_this):
|
||||
assert get_new_command(Command('composer udpate',
|
||||
stderr=composer_not_command)) \
|
||||
== 'composer update'
|
||||
assert get_new_command(
|
||||
Command('composer pdate', stderr=composer_not_command_one_of_this)) \
|
||||
== 'composer selfupdate'
|
||||
assert (get_new_command(Command('composer udpate',
|
||||
stderr=composer_not_command))
|
||||
== 'composer update')
|
||||
assert (get_new_command(Command('composer pdate',
|
||||
stderr=composer_not_command_one_of_this))
|
||||
== 'composer selfupdate')
|
||||
|
@ -2,7 +2,7 @@ import os
|
||||
import pytest
|
||||
import tarfile
|
||||
from thefuck.rules.dirty_untar import match, get_new_command, side_effect, \
|
||||
tar_extensions
|
||||
tar_extensions # noqa: E126
|
||||
from tests.utils import Command
|
||||
|
||||
|
||||
@ -33,6 +33,7 @@ def tar_error(tmpdir):
|
||||
|
||||
return fixture
|
||||
|
||||
|
||||
parametrize_extensions = pytest.mark.parametrize('ext', tar_extensions)
|
||||
|
||||
# (filename as typed by the user, unquoted filename, quoted filename as per shells.quote)
|
||||
|
@ -37,7 +37,7 @@ south.exceptions.GhostMigrations:
|
||||
! I'm not trusting myself; either fix this yourself by fiddling
|
||||
! with the south_migrationhistory table, or pass --delete-ghost-migrations
|
||||
! to South to have it delete ALL of these records (this may not be good).
|
||||
'''
|
||||
''' # noqa
|
||||
|
||||
|
||||
def test_match(stderr):
|
||||
|
@ -39,5 +39,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Command('./manage.py migrate auth')) \
|
||||
== './manage.py migrate auth --merge'
|
||||
assert (get_new_command(Command('./manage.py migrate auth'))
|
||||
== './manage.py migrate auth --merge')
|
||||
|
@ -45,5 +45,5 @@ def test_not_match(command):
|
||||
'fab prepare_extension:version=2016 deploy:beta=true -H the.fuck'),
|
||||
])
|
||||
def test_get_new_command(script, result):
|
||||
command = Command(script, stdout,stderr)
|
||||
command = Command(script, stdout, stderr)
|
||||
assert get_new_command(command) == result
|
||||
|
@ -18,5 +18,5 @@ def test_match():
|
||||
|
||||
def test_get_new_command():
|
||||
""" Replace the Alt+Space character by a simple space """
|
||||
assert get_new_command(Command(u'ps -ef | grep foo'))\
|
||||
== 'ps -ef | grep foo'
|
||||
assert (get_new_command(Command(u'ps -ef | grep foo'))
|
||||
== 'ps -ef | grep foo')
|
||||
|
@ -191,7 +191,7 @@ E NameError: name 'mocker' is not defined
|
||||
|
||||
/home/thefuck/tests/rules/test_fix_file.py:218: NameError
|
||||
""", ''),
|
||||
)
|
||||
) # noqa
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
@ -227,10 +227,6 @@ def test_get_new_command(mocker, monkeypatch, test):
|
||||
mocker.patch('os.path.isfile', return_value=True)
|
||||
monkeypatch.setenv('EDITOR', 'dummy_editor')
|
||||
|
||||
cmd = Command(script=test[0], stdout=test[4], stderr=test[5])
|
||||
#assert (get_new_command(cmd, Settings({})) ==
|
||||
# 'dummy_editor {} +{} && {}'.format(test[1], test[2], test[0]))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('test', tests)
|
||||
@pytest.mark.usefixtures('no_memoize')
|
||||
|
@ -18,5 +18,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git add dist/*.js', stderr=stderr)) \
|
||||
== "git add --force dist/*.js"
|
||||
assert (get_new_command(Command('git add dist/*.js', stderr=stderr))
|
||||
== "git add --force dist/*.js")
|
||||
|
@ -49,9 +49,9 @@ def test_match(git_not_command, git_command, git_not_command_one_of_this):
|
||||
|
||||
def test_get_new_command(git_not_command, git_not_command_one_of_this,
|
||||
git_not_command_closest):
|
||||
assert get_new_command(Command('git brnch', stderr=git_not_command)) \
|
||||
== ['git branch']
|
||||
assert get_new_command(Command('git st', stderr=git_not_command_one_of_this)) \
|
||||
== ['git stats', 'git stash', 'git stage']
|
||||
assert get_new_command(Command('git tags', stderr=git_not_command_closest)) \
|
||||
== ['git tag', 'git stage']
|
||||
assert (get_new_command(Command('git brnch', stderr=git_not_command))
|
||||
== ['git branch'])
|
||||
assert (get_new_command(Command('git st', stderr=git_not_command_one_of_this))
|
||||
== ['git stats', 'git stash', 'git stage'])
|
||||
assert (get_new_command(Command('git tags', stderr=git_not_command_closest))
|
||||
== ['git tag', 'git stage'])
|
||||
|
@ -25,5 +25,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git pull', stderr=stderr)) \
|
||||
== "git branch --set-upstream-to=origin/master master && git pull"
|
||||
assert (get_new_command(Command('git pull', stderr=stderr))
|
||||
== "git branch --set-upstream-to=origin/master master && git pull")
|
||||
|
@ -15,5 +15,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git pull', stderr=stderr)) \
|
||||
== "git stash && git pull && git stash pop"
|
||||
assert (get_new_command(Command('git pull', stderr=stderr))
|
||||
== "git stash && git pull && git stash pop")
|
||||
|
@ -15,5 +15,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git pull', stderr=stderr)) \
|
||||
== "git stash && git pull && git stash pop"
|
||||
assert (get_new_command(Command('git pull', stderr=stderr))
|
||||
== "git stash && git pull && git stash pop")
|
||||
|
@ -39,12 +39,7 @@ To /tmp/bar
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git push', stderr=git_err),
|
||||
Command(script='git push nvbn', stderr=git_err),
|
||||
Command(script='git push nvbn master', stderr=git_err)])
|
||||
def test_match(command):
|
||||
assert match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command', [
|
||||
Command(script='git push nvbn master', stderr=git_err),
|
||||
Command(script='git push', stderr=git_err2),
|
||||
Command(script='git push nvbn', stderr=git_err2),
|
||||
Command(script='git push nvbn master', stderr=git_err2)])
|
||||
@ -68,12 +63,7 @@ def test_not_match(command):
|
||||
(Command(script='git push nvbn', stderr=git_err),
|
||||
'git pull nvbn && git push nvbn'),
|
||||
(Command(script='git push nvbn master', stderr=git_err),
|
||||
'git pull nvbn master && git push nvbn master')])
|
||||
def test_get_new_command(command, output):
|
||||
assert get_new_command(command) == output
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, output', [
|
||||
'git pull nvbn master && git push nvbn master'),
|
||||
(Command(script='git push', stderr=git_err2), 'git pull && git push'),
|
||||
(Command(script='git push nvbn', stderr=git_err2),
|
||||
'git pull nvbn && git push nvbn'),
|
||||
|
@ -14,11 +14,11 @@ def test_match(command):
|
||||
Command('git remote add origin url'),
|
||||
Command('git remote remove origin'),
|
||||
Command('git remote prune origin'),
|
||||
Command('git remote set-branches origin branch')
|
||||
])
|
||||
Command('git remote set-branches origin branch')])
|
||||
def test_not_match(command):
|
||||
assert not match(command)
|
||||
|
||||
|
||||
@pytest.mark.parametrize('command, new_command', [
|
||||
(Command('git remote set-url origin git@github.com:nvbn/thefuck.git'),
|
||||
'git remote add origin git@github.com:nvbn/thefuck.git')])
|
||||
|
@ -14,5 +14,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git stash pop', stderr=stderr)) \
|
||||
== "git add . && git stash pop && git reset ."
|
||||
assert (get_new_command(Command('git stash pop', stderr=stderr))
|
||||
== "git add . && git stash pop && git reset .")
|
||||
|
@ -14,5 +14,5 @@ def test_match(stderr):
|
||||
|
||||
|
||||
def test_get_new_command(stderr):
|
||||
assert get_new_command(Command('git tag alert', stderr=stderr)) \
|
||||
== "git tag --force alert"
|
||||
assert (get_new_command(Command('git tag alert', stderr=stderr))
|
||||
== "git tag --force alert")
|
||||
|
@ -19,5 +19,5 @@ def test_match(is_not_task):
|
||||
|
||||
|
||||
def test_get_new_command(is_not_task):
|
||||
assert get_new_command(Command(script='lein rpl --help', stderr=is_not_task)) \
|
||||
== ['lein repl --help', 'lein jar --help']
|
||||
assert (get_new_command(Command(script='lein rpl --help', stderr=is_not_task))
|
||||
== ['lein repl --help', 'lein jar --help'])
|
||||
|
@ -11,16 +11,6 @@ def file_exists(mocker):
|
||||
get_stderr = "ln: failed to create symbolic link '{}': File exists".format
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('file_exists')
|
||||
@pytest.mark.parametrize('script', [
|
||||
'ln -s dest source',
|
||||
'ln dest -s source',
|
||||
'ln dest source -s'])
|
||||
def test_match(script):
|
||||
stderr = get_stderr('source')
|
||||
assert match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, stderr, exists', [
|
||||
('ln dest source', get_stderr('source'), True),
|
||||
('ls -s dest source', get_stderr('source'), True),
|
||||
@ -38,4 +28,5 @@ def test_not_match(file_exists, script, stderr, exists):
|
||||
('ln dest source -s', 'ln source -s dest')])
|
||||
def test_match(script, result):
|
||||
stderr = get_stderr('source')
|
||||
assert match(Command(script, stderr=stderr))
|
||||
assert get_new_command(Command(script, stderr=stderr)) == result
|
||||
|
@ -25,7 +25,7 @@ def test_match(command):
|
||||
[INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
|
||||
[INFO] Final Memory: 6M/240M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
"""),
|
||||
"""), # noqa
|
||||
Command(script='mvn --help'),
|
||||
Command(script='mvn -v')
|
||||
])
|
||||
|
@ -25,7 +25,7 @@ def test_match(command):
|
||||
[INFO] Finished at: Wed Aug 26 13:05:47 BST 2015
|
||||
[INFO] Final Memory: 6M/240M
|
||||
[INFO] ------------------------------------------------------------------------
|
||||
"""),
|
||||
"""), # noqa
|
||||
Command(script='mvn --help'),
|
||||
Command(script='mvn -v')
|
||||
])
|
||||
|
@ -8,5 +8,5 @@ def test_match():
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Command('./test_sudo.py'))\
|
||||
== 'python ./test_sudo.py'
|
||||
assert (get_new_command(Command('./test_sudo.py'))
|
||||
== 'python ./test_sudo.py')
|
||||
|
@ -17,5 +17,5 @@ def test_not_match(command):
|
||||
|
||||
|
||||
def test_get_new_command():
|
||||
assert get_new_command(Command(script='rm -rf /')) \
|
||||
== 'rm -rf / --no-preserve-root'
|
||||
assert (get_new_command(Command(script='rm -rf /'))
|
||||
== 'rm -rf / --no-preserve-root')
|
||||
|
@ -18,11 +18,11 @@ def test_match(sed_unterminated_s):
|
||||
|
||||
|
||||
def test_get_new_command(sed_unterminated_s):
|
||||
assert get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s)) \
|
||||
== 'sed -e s/foo/bar/'
|
||||
assert get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s)) \
|
||||
== 'sed -es/foo/bar/'
|
||||
assert get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s)) \
|
||||
== r"sed -e 's/\/foo/bar/'"
|
||||
assert get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s)) \
|
||||
== r"sed -e s/foo/bar/ -es/baz/quz/"
|
||||
assert (get_new_command(Command('sed -e s/foo/bar', stderr=sed_unterminated_s))
|
||||
== 'sed -e s/foo/bar/')
|
||||
assert (get_new_command(Command('sed -es/foo/bar', stderr=sed_unterminated_s))
|
||||
== 'sed -es/foo/bar/')
|
||||
assert (get_new_command(Command(r"sed -e 's/\/foo/bar'", stderr=sed_unterminated_s))
|
||||
== r"sed -e 's/\/foo/bar/'")
|
||||
assert (get_new_command(Command(r"sed -e s/foo/bar -es/baz/quz", stderr=sed_unterminated_s))
|
||||
== r"sed -e s/foo/bar/ -es/baz/quz/")
|
||||
|
@ -82,7 +82,7 @@ yarn_help_stdout = b'''
|
||||
|
||||
Run `yarn help COMMAND` for more information on specific commands.
|
||||
Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn.
|
||||
'''
|
||||
''' # noqa
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
|
@ -47,8 +47,8 @@ def test_get_corrected_commands(mocker):
|
||||
get_new_command=lambda x: [x.script + '@', x.script + ';'],
|
||||
priority=60)]
|
||||
mocker.patch('thefuck.corrector.get_rules', return_value=rules)
|
||||
assert [cmd.script for cmd in get_corrected_commands(command)] \
|
||||
== ['test!', 'test@', 'test;']
|
||||
assert ([cmd.script for cmd in get_corrected_commands(command)]
|
||||
== ['test!', 'test@', 'test;'])
|
||||
|
||||
|
||||
def test_organize_commands():
|
||||
|
@ -13,10 +13,10 @@ from thefuck.system import Path
|
||||
class TestCorrectedCommand(object):
|
||||
|
||||
def test_equality(self):
|
||||
assert CorrectedCommand('ls', None, 100) == \
|
||||
CorrectedCommand('ls', None, 200)
|
||||
assert CorrectedCommand('ls', None, 100) != \
|
||||
CorrectedCommand('ls', lambda *_: _, 100)
|
||||
assert (CorrectedCommand('ls', None, 100) ==
|
||||
CorrectedCommand('ls', None, 200))
|
||||
assert (CorrectedCommand('ls', None, 100) !=
|
||||
CorrectedCommand('ls', lambda *_: _, 100))
|
||||
|
||||
def test_hashable(self):
|
||||
assert {CorrectedCommand('ls', None, 100),
|
||||
@ -41,8 +41,8 @@ class TestRule(object):
|
||||
priority=900,
|
||||
requires_output=True))
|
||||
rule_path = os.path.join(os.sep, 'rules', 'bash.py')
|
||||
assert Rule.from_path(Path(rule_path)) \
|
||||
== Rule('bash', match, get_new_command, priority=900)
|
||||
assert (Rule.from_path(Path(rule_path))
|
||||
== Rule('bash', match, get_new_command, priority=900))
|
||||
load_source.assert_called_once_with('bash', rule_path)
|
||||
|
||||
@pytest.mark.parametrize('rules, exclude_rules, rule, is_enabled', [
|
||||
@ -79,15 +79,15 @@ class TestRule(object):
|
||||
def test_get_corrected_commands_with_rule_returns_list(self):
|
||||
rule = Rule(get_new_command=lambda x: [x.script + '!', x.script + '@'],
|
||||
priority=100)
|
||||
assert list(rule.get_corrected_commands(Command(script='test'))) \
|
||||
assert (list(rule.get_corrected_commands(Command(script='test')))
|
||||
== [CorrectedCommand(script='test!', priority=100),
|
||||
CorrectedCommand(script='test@', priority=200)]
|
||||
CorrectedCommand(script='test@', priority=200)])
|
||||
|
||||
def test_get_corrected_commands_with_rule_returns_command(self):
|
||||
rule = Rule(get_new_command=lambda x: x.script + '!',
|
||||
priority=100)
|
||||
assert list(rule.get_corrected_commands(Command(script='test'))) \
|
||||
== [CorrectedCommand(script='test!', priority=100)]
|
||||
assert (list(rule.get_corrected_commands(Command(script='test')))
|
||||
== [CorrectedCommand(script='test!', priority=100)])
|
||||
|
||||
|
||||
class TestCommand(object):
|
||||
|
@ -30,11 +30,11 @@ def test_read_actions(patch_get_key):
|
||||
const.KEY_DOWN, 'j',
|
||||
# Ctrl+C:
|
||||
const.KEY_CTRL_C, 'q'])
|
||||
assert list(islice(ui.read_actions(), 8)) \
|
||||
assert (list(islice(ui.read_actions(), 8))
|
||||
== [const.ACTION_SELECT, const.ACTION_SELECT,
|
||||
const.ACTION_PREVIOUS, const.ACTION_PREVIOUS,
|
||||
const.ACTION_NEXT, const.ACTION_NEXT,
|
||||
const.ACTION_ABORT, const.ACTION_ABORT]
|
||||
const.ACTION_ABORT, const.ACTION_ABORT])
|
||||
|
||||
|
||||
def test_command_selector():
|
||||
@ -74,8 +74,8 @@ class TestSelectCommand(object):
|
||||
def test_without_confirmation_with_side_effects(
|
||||
self, capsys, commands_with_side_effect, settings):
|
||||
settings.require_confirmation = False
|
||||
assert ui.select_command(iter(commands_with_side_effect)) \
|
||||
== commands_with_side_effect[0]
|
||||
assert (ui.select_command(iter(commands_with_side_effect))
|
||||
== commands_with_side_effect[0])
|
||||
assert capsys.readouterr() == ('', 'ls (+side effect)\n')
|
||||
|
||||
def test_with_confirmation(self, capsys, patch_get_key, commands):
|
||||
@ -91,8 +91,8 @@ class TestSelectCommand(object):
|
||||
def test_with_confirmation_with_side_effct(self, capsys, patch_get_key,
|
||||
commands_with_side_effect):
|
||||
patch_get_key(['\n'])
|
||||
assert ui.select_command(iter(commands_with_side_effect)) \
|
||||
== commands_with_side_effect[0]
|
||||
assert (ui.select_command(iter(commands_with_side_effect))
|
||||
== commands_with_side_effect[0])
|
||||
assert capsys.readouterr() == ('', u'\x1b[1K\rls (+side effect) [enter/↑/↓/ctrl+c]\n')
|
||||
|
||||
def test_with_confirmation_select_second(self, capsys, patch_get_key, commands):
|
||||
|
@ -18,8 +18,7 @@ from tests.utils import Command
|
||||
def test_default_settings(settings, override, old, new):
|
||||
settings.clear()
|
||||
settings.update(old)
|
||||
fn = lambda _: _
|
||||
default_settings(override)(fn)(None)
|
||||
default_settings(override)(lambda _: _)(None)
|
||||
assert settings == new
|
||||
|
||||
|
||||
|
@ -3,16 +3,16 @@ from .system import init_output
|
||||
|
||||
init_output()
|
||||
|
||||
from argparse import ArgumentParser
|
||||
from pprint import pformat
|
||||
import sys
|
||||
from . import logs, types
|
||||
from .shells import shell
|
||||
from .conf import settings
|
||||
from .corrector import get_corrected_commands
|
||||
from .exceptions import EmptyCommand
|
||||
from .utils import get_installation_info, get_alias
|
||||
from .ui import select_command
|
||||
from argparse import ArgumentParser # noqa: E402
|
||||
from pprint import pformat # noqa: E402
|
||||
import sys # noqa: E402
|
||||
from . import logs, types # noqa: E402
|
||||
from .shells import shell # noqa: E402
|
||||
from .conf import settings # noqa: E402
|
||||
from .corrector import get_corrected_commands # noqa: E402
|
||||
from .exceptions import EmptyCommand # noqa: E402
|
||||
from .utils import get_installation_info, get_alias # noqa: E402
|
||||
from .ui import select_command # noqa: E402
|
||||
|
||||
|
||||
def fix_command():
|
||||
@ -59,8 +59,7 @@ def how_to_configure_alias():
|
||||
def main():
|
||||
parser = ArgumentParser(prog='thefuck')
|
||||
version = get_installation_info().version
|
||||
parser.add_argument(
|
||||
'-v', '--version',
|
||||
parser.add_argument('-v', '--version',
|
||||
action='version',
|
||||
version='The Fuck {} using Python {}'.format(
|
||||
version, sys.version.split()[0]))
|
||||
|
@ -54,8 +54,8 @@ def _brew_commands():
|
||||
brew_path_prefix = get_brew_path_prefix()
|
||||
if brew_path_prefix:
|
||||
try:
|
||||
return _get_brew_commands(brew_path_prefix) \
|
||||
+ _get_brew_tap_specific_commands(brew_path_prefix)
|
||||
return (_get_brew_commands(brew_path_prefix)
|
||||
+ _get_brew_tap_specific_commands(brew_path_prefix))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
@ -9,6 +9,7 @@ def match(command):
|
||||
def get_new_command(command):
|
||||
return ' '.join(command.script_parts[1:])
|
||||
|
||||
|
||||
# it should be rare enough to actually have to type twice the same word, so
|
||||
# this rule can have a higher priority to come before things like "cd cd foo"
|
||||
priority = 900
|
||||
|
@ -40,6 +40,8 @@ def _make_pattern(pattern):
|
||||
.replace('{line}', '(?P<line>[0-9]+)') \
|
||||
.replace('{col}', '(?P<col>[0-9]+)')
|
||||
return re.compile(pattern, re.MULTILINE)
|
||||
|
||||
|
||||
patterns = [_make_pattern(p).search for p in patterns]
|
||||
|
||||
|
||||
|
@ -11,6 +11,7 @@ def match(command):
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
# git's output here is too complicated to be parsed (see the test file)
|
||||
stash_commands = (
|
||||
'apply',
|
||||
|
@ -1,6 +1,6 @@
|
||||
import subprocess
|
||||
from thefuck.utils import for_app, replace_command, eager
|
||||
import sys
|
||||
|
||||
|
||||
@for_app('ifconfig')
|
||||
def match(command):
|
||||
@ -21,5 +21,3 @@ def get_new_command(command):
|
||||
interface = command.stderr.split(' ')[0][:-1]
|
||||
possible_interfaces = _get_possible_interfaces()
|
||||
return replace_command(command, interface, possible_interfaces)
|
||||
|
||||
|
||||
|
@ -6,4 +6,5 @@ def match(command):
|
||||
def get_new_command(command):
|
||||
return u'man {}'.format(command.script[3:])
|
||||
|
||||
|
||||
priority = 2000
|
||||
|
@ -13,4 +13,5 @@ def get_new_command(command):
|
||||
return [formatme.format(pacman, package, command.script)
|
||||
for package in packages]
|
||||
|
||||
|
||||
enabled_by_default, pacman = archlinux_env()
|
||||
|
@ -33,8 +33,8 @@ def match(command):
|
||||
if 'not found' not in command.stderr:
|
||||
return False
|
||||
matched_layout = _get_matched_layout(command)
|
||||
return matched_layout and \
|
||||
_switch_command(command, matched_layout) != get_alias()
|
||||
return (matched_layout and
|
||||
_switch_command(command, matched_layout) != get_alias())
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
|
@ -3,8 +3,8 @@ from thefuck.utils import replace_command
|
||||
|
||||
|
||||
def match(command):
|
||||
return (re.search(r"([^:]*): Unknown command.*", command.stderr) != None
|
||||
and re.search(r"Did you mean ([^?]*)?", command.stderr) != None)
|
||||
return (re.search(r"([^:]*): Unknown command.*", command.stderr) is not None
|
||||
and re.search(r"Did you mean ([^?]*)?", command.stderr) is not None)
|
||||
|
||||
|
||||
def get_new_command(command):
|
||||
|
@ -26,7 +26,7 @@ def get_new_command(command):
|
||||
|
||||
available = _get_all_environments()
|
||||
if available:
|
||||
return replace_command(command, misspelled_env, available) \
|
||||
+ [create_new]
|
||||
return (replace_command(command, misspelled_env, available)
|
||||
+ [create_new])
|
||||
else:
|
||||
return create_new
|
||||
|
@ -2,6 +2,6 @@ import sys
|
||||
|
||||
|
||||
if sys.platform == 'win32':
|
||||
from .win32 import *
|
||||
from .win32 import * # noqa: F401,F403
|
||||
else:
|
||||
from .unix import *
|
||||
from .unix import * # noqa: F401,F403
|
||||
|
@ -52,5 +52,6 @@ except ImportError:
|
||||
def _expanduser(self):
|
||||
return self.__class__(os.path.expanduser(str(self)))
|
||||
|
||||
|
||||
if not hasattr(Path, 'expanduser'):
|
||||
Path.expanduser = _expanduser
|
||||
|
@ -41,5 +41,6 @@ except ImportError:
|
||||
def _expanduser(self):
|
||||
return self.__class__(os.path.expanduser(str(self)))
|
||||
|
||||
|
||||
# pathlib's expanduser fails on windows, see http://bugs.python.org/issue19776
|
||||
Path.expanduser = _expanduser
|
||||
|
@ -40,8 +40,8 @@ class Command(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Command):
|
||||
return (self.script, self.stdout, self.stderr) \
|
||||
== (other.script, other.stdout, other.stderr)
|
||||
return ((self.script, self.stdout, self.stderr)
|
||||
== (other.script, other.stdout, other.stderr))
|
||||
else:
|
||||
return False
|
||||
|
||||
@ -159,12 +159,12 @@ class Rule(object):
|
||||
|
||||
def __eq__(self, other):
|
||||
if isinstance(other, Rule):
|
||||
return (self.name, self.match, self.get_new_command,
|
||||
return ((self.name, self.match, self.get_new_command,
|
||||
self.enabled_by_default, self.side_effect,
|
||||
self.priority, self.requires_output) \
|
||||
self.priority, self.requires_output)
|
||||
== (other.name, other.match, other.get_new_command,
|
||||
other.enabled_by_default, other.side_effect,
|
||||
other.priority, other.requires_output)
|
||||
other.priority, other.requires_output))
|
||||
else:
|
||||
return False
|
||||
|
||||
|
@ -40,6 +40,8 @@ def memoize(fn):
|
||||
return value
|
||||
|
||||
return wrapper
|
||||
|
||||
|
||||
memoize.disabled = False
|
||||
|
||||
|
||||
@ -238,6 +240,8 @@ def cache(*depends_on):
|
||||
return value
|
||||
|
||||
return _cache
|
||||
|
||||
|
||||
cache.disabled = False
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user