diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index aecfc7f..8e552d9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -34,6 +34,13 @@ jobs: run: | pip install -Ur requirements.txt coveralls python setup.py develop + - name: Diagnose lint checkout + run: | + git rev-parse HEAD + git status --short --untracked-files=all + git ls-files -- thefuck/rules/git_direct_commit.py tests/rules/test_edit_filename.py + find . -name git_direct_commit.py -o -name test_edit_filename.py + nl -ba tests/rules/test_edit_filename.py | sed -n '1,16p' - name: Lint if: matrix.os == 'ubuntu-22.04' && matrix.python-version == env.PYTHON_LATEST run: flake8 diff --git a/fastentrypoints.py b/fastentrypoints.py index 7bddb46..f8319f7 100644 --- a/fastentrypoints.py +++ b/fastentrypoints.py @@ -67,8 +67,8 @@ def get_args(cls, dist, header=None): if re.search(r'[\\/]', name): raise ValueError("Path separators not allowed in script names") script_text = TEMPLATE.format( - ep.module_name, ep.attrs[0], '.'.join(ep.attrs), - spec, group, name) + ep.module_name, ep.attrs[0], '.'.join(ep.attrs), + spec, group, name) args = cls._get_script_args(type_, name, header, script_text) for res in args: yield res @@ -107,4 +107,5 @@ def main(): setup.truncate() setup.write('import fastentrypoints\n' + setup_content) + print(__name__) diff --git a/setup.py b/setup.py index 7c18214..a412469 100755 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ from setuptools import setup, find_packages import sys import os -import fastentrypoints try: @@ -48,13 +47,13 @@ if sys.platform == "win32": scripts = ['scripts\\fuck.bat', 'scripts\\fuck.ps1'] entry_points = {'console_scripts': [ - 'thefuck = thefuck.entrypoints.main:main', - 'thefuck_firstuse = thefuck.entrypoints.not_configured:main']} + 'thefuck = thefuck.entrypoints.main:main', + 'thefuck_firstuse = thefuck.entrypoints.not_configured:main']} else: scripts = [] entry_points = {'console_scripts': [ - 'thefuck = thefuck.entrypoints.main:main', - 'fuck = thefuck.entrypoints.not_configured:main']} + 'thefuck = thefuck.entrypoints.main:main', + 'fuck = thefuck.entrypoints.not_configured:main']} setup(name='zhifei', version=VERSION, diff --git a/tests/rules/test_edit_filename.py b/tests/rules/test_edit_filename.py index 0436f02..e560a22 100644 --- a/tests/rules/test_edit_filename.py +++ b/tests/rules/test_edit_filename.py @@ -1,6 +1,5 @@ -import os - import pytest +import os from thefuck.rules.edit_filename import EDITORS, get_new_command, match from thefuck.types import Command diff --git a/tests/rules/test_git_not_command.py b/tests/rules/test_git_not_command.py index bb3ed32..15e6b9a 100644 --- a/tests/rules/test_git_not_command.py +++ b/tests/rules/test_git_not_command.py @@ -45,6 +45,15 @@ def git_command(): return "* master" +@pytest.fixture +def git_comit_error(): + return """git: 'comit' is not a git command. See 'git --help'. + +The most similar command is +commit +""" + + def test_match(git_not_command, git_command, git_not_command_one_of_this, git_not_command_closest, git_not_command_uncommon): assert match(Command('git brnch', git_not_command)) assert match(Command('git st', git_not_command_one_of_this)) @@ -60,7 +69,7 @@ def test_match(git_not_command, git_command, git_not_command_one_of_this, git_no def test_get_new_command(git_not_command, git_not_command_one_of_this, - git_not_command_closest, git_not_command_uncommon): + git_not_command_closest, git_not_command_uncommon, git_comit_error): assert (get_new_command(Command('git brnch', git_not_command)) == ['git branch']) assert (get_new_command(Command('git st', git_not_command_one_of_this)) @@ -72,3 +81,6 @@ def test_get_new_command(git_not_command, git_not_command_one_of_this, == ['git log']) assert (get_new_command(Command('git lock --help', git_not_command_uncommon)) == ['git log --help']) + + assert (get_new_command(Command('git comit', git_comit_error)) + == ['git commit']) diff --git a/tests/rules/test_upper_to_lower_case.py b/tests/rules/test_upper_to_lower_case.py index 13bbcd9..81993a7 100644 --- a/tests/rules/test_upper_to_lower_case.py +++ b/tests/rules/test_upper_to_lower_case.py @@ -1,6 +1,5 @@ # Absorbed from upstream #1297 (author nkakonas); the original test used # `cd`, which is a shell builtin and not in get_all_executables(). -import os import pytest @@ -15,11 +14,15 @@ ("LS -A", "command not found"), ], ) -# Windows runners have neither a `ls` executable on PATH nor the POSIX -# "command not found" message, so the positive-match cases can't hold there. -@pytest.mark.skipif(os.name == 'nt', - reason='POSIX-only error message and PATH layout') -def test_match(script, output): +def test_match(script, output, monkeypatch): + monkeypatch.setattr( + "thefuck.rules.upper_to_lower_case.which", + lambda command: None, + ) + monkeypatch.setattr( + "thefuck.rules.upper_to_lower_case.get_all_executables", + lambda: ["ls"], + ) assert match(Command(script, output)) diff --git a/tests/rules/test_yarn_command_not_found.py b/tests/rules/test_yarn_command_not_found.py index 6745163..f72d9e9 100644 --- a/tests/rules/test_yarn_command_not_found.py +++ b/tests/rules/test_yarn_command_not_found.py @@ -82,7 +82,7 @@ Run `yarn help COMMAND` for more information on specific commands. Visit https://yarnpkg.com/en/docs/cli/ to learn more about Yarn. -''' # noqa +''' # noqa @pytest.fixture(autouse=True) diff --git a/tests/test_system_win32.py b/tests/test_system_win32.py index 1a20f93..eeb5b8a 100644 --- a/tests/test_system_win32.py +++ b/tests/test_system_win32.py @@ -12,8 +12,9 @@ import pytest win_unicode_console = pytest.importorskip('win_unicode_console') -import colorama # noqa: E402 -from thefuck.system.win32 import init_output # noqa: E402 + +import colorama # noqa: E402, E261 +from thefuck.system.win32 import init_output # noqa: E402, E261 class TestInitOutputWarningSuppression: diff --git a/thefuck/fix_git_and_command_misspell.py b/thefuck/fix_git_and_command_misspell.py new file mode 100644 index 0000000..677e4f5 --- /dev/null +++ b/thefuck/fix_git_and_command_misspell.py @@ -0,0 +1,16 @@ +from difflib import get_close_matches + + +def fix_git_command(git_command): + git_possible = ['clone', 'init', 'add', 'mv', 'reset', 'rm', 'bisect', + 'grep', 'log', 'show', 'status', 'branch', 'checkout', + 'commit', 'diff', 'merge', 'rebase', 'tag', 'fetch', + 'pull', 'push'] + if git_command not in git_possible[0]: + close_match = get_close_matches(git_command, git_possible) + if len(close_match) > 0: + return close_match[0] + else: + return git_command + else: + return git_command diff --git a/thefuck/rules/git_direct_commit.py b/thefuck/rules/git_direct_commit.py index 5f1fc4e..5b85646 100644 --- a/thefuck/rules/git_direct_commit.py +++ b/thefuck/rules/git_direct_commit.py @@ -1,9 +1,14 @@ # Absorbed from upstream #1311 (author nkakonas): the user tried to commit # without staging anything first; suggest `git add --all` before committing. def match(command): - return 'git commit ' in command.script and ('Untracked files' in command.output - or '''use "git add"''' in command.output or 'Changes not staged for commit' - in command.output) + return ( + 'git commit ' in command.script + and ( + 'Untracked files' in command.output + or 'use "git add"' in command.output + or 'Changes not staged for commit' in command.output + ) + ) def get_new_command(command): diff --git a/thefuck/utils.py b/thefuck/utils.py index 3a47ae4..e028f8e 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -144,7 +144,6 @@ def _safe(fn, fallback): return fallback cache_path = _get_executables_cache_path() - # Respect the test-suite cache switch so tests always scan PATH. use_cache = not cache.disabled if use_cache: try: @@ -156,12 +155,7 @@ def _safe(fn, fallback): pass tf_alias = get_alias() - try: - from . import const as _const - tf_entry_points = (['thefuck', tf_alias] - + list(_const.DEFAULT_EXTRA_ALIASES)) - except Exception: - tf_entry_points = ['thefuck', tf_alias] + tf_entry_points = ['thefuck', 'fuck'] bins = [exe.name.decode('utf8') if six.PY2 else exe.name for path in os.environ.get('PATH', '').split(os.pathsep)