From d96505f3f9605223dbab0329924072fd62786e49 Mon Sep 17 00:00:00 2001 From: BurdenBear <541795600@qq.com> Date: Wed, 24 Jan 2018 19:52:02 +0800 Subject: [PATCH 1/9] fix $PATH problem when using cmder(git-bash) on windows. --- thefuck/utils.py | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 3a47ae4..0a98d9e 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -6,6 +6,7 @@ import sys import time import six +import sys from decorator import decorator from difflib import get_close_matches as difflib_get_close_matches from functools import wraps @@ -144,7 +145,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,23 +156,21 @@ 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'] + + win32 = sys.platform.startswith('win') + paths = os.environ.get('PATH', '') + paths = paths.split(';') if win32 else paths.split(':') bins = [exe.name.decode('utf8') if six.PY2 else exe.name - for path in os.environ.get('PATH', '').split(os.pathsep) - if include_path_in_search(path) + for path in paths + if include_path_in_search(path) # keep the filter if you still want it for exe in _safe(lambda: list(Path(path).iterdir()), []) if not _safe(exe.is_dir, True) and exe.name not in tf_entry_points] aliases = [alias.decode('utf8') if six.PY2 else alias for alias in shell.get_aliases() if alias != tf_alias] - win32 = sys.platform.startswith('win') if win32: bins += [exe[:-4] for exe in bins if exe.endswith(".exe")] From df68e0cd796c554687c19129f4781aa988688a3e Mon Sep 17 00:00:00 2001 From: BurdenBear <541795600@qq.com> Date: Sat, 27 Jan 2018 13:55:43 +0800 Subject: [PATCH 2/9] using os.pathsep, and fix lint issue --- thefuck/utils.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 0a98d9e..619b093 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -158,19 +158,16 @@ def _safe(fn, fallback): tf_alias = get_alias() tf_entry_points = ['thefuck', 'fuck'] - win32 = sys.platform.startswith('win') - paths = os.environ.get('PATH', '') - paths = paths.split(';') if win32 else paths.split(':') - bins = [exe.name.decode('utf8') if six.PY2 else exe.name - for path in paths - if include_path_in_search(path) # keep the filter if you still want it + for path in os.environ.get('PATH', '').split(os.pathsep) + if include_path_in_search(path) for exe in _safe(lambda: list(Path(path).iterdir()), []) if not _safe(exe.is_dir, True) and exe.name not in tf_entry_points] aliases = [alias.decode('utf8') if six.PY2 else alias for alias in shell.get_aliases() if alias != tf_alias] + win32 = sys.platform.startswith('win') if win32: bins += [exe[:-4] for exe in bins if exe.endswith(".exe")] From 7340836936f64cdf3cf3356a3189d3fb18db7e78 Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 20:59:01 -0600 Subject: [PATCH 3/9] don't import sys twice --- thefuck/utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/thefuck/utils.py b/thefuck/utils.py index 619b093..e028f8e 100644 --- a/thefuck/utils.py +++ b/thefuck/utils.py @@ -6,7 +6,6 @@ import sys import time import six -import sys from decorator import decorator from difflib import get_close_matches as difflib_get_close_matches from functools import wraps From 174269603ea2b32e4eac087961b068a6f6cc2512 Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 22:09:49 -0600 Subject: [PATCH 4/9] make flake8 happy redux --- fastentrypoints.py | 5 +++-- setup.py | 9 ++++----- tests/rules/test_edit_filename.py | 1 - tests/rules/test_yarn_command_not_found.py | 2 +- tests/test_system_win32.py | 5 +++-- 5 files changed, 11 insertions(+), 11 deletions(-) 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..2d99d23 100644 --- a/tests/rules/test_edit_filename.py +++ b/tests/rules/test_edit_filename.py @@ -1,4 +1,3 @@ -import os import pytest 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: From f3dc4ed9c3c720dee545a1271ffc5dc1f41e6307 Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 23:01:06 -0600 Subject: [PATCH 5/9] Trigger CI rerun From fadef4d85ad4dbb629a3ea507f8a0c62d27da82e Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 23:07:04 -0600 Subject: [PATCH 6/9] add diaganostics to yaml --- .github/workflows/test.yml | 7 +++++++ 1 file changed, 7 insertions(+) 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 From 4d46c5267ad3e4c293a3ef355fa81c84134a331d Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 23:54:56 -0600 Subject: [PATCH 7/9] add os import --- tests/rules/test_edit_filename.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/rules/test_edit_filename.py b/tests/rules/test_edit_filename.py index 2d99d23..e560a22 100644 --- a/tests/rules/test_edit_filename.py +++ b/tests/rules/test_edit_filename.py @@ -1,5 +1,5 @@ - import pytest +import os from thefuck.rules.edit_filename import EDITORS, get_new_command, match from thefuck.types import Command From c2c5eafea6fc5aaab1b60ce0b4bba5a28e699121 Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 23:55:36 -0600 Subject: [PATCH 8/9] reformat code to make flake8 happy --- thefuck/rules/git_direct_commit.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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): From 99839dba32cf908b2201b3ba466449cedf550739 Mon Sep 17 00:00:00 2001 From: Tomas Gallucci Date: Mon, 30 Nov 2026 23:55:58 -0600 Subject: [PATCH 9/9] make test platform agnostic --- tests/rules/test_upper_to_lower_case.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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))