Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 44687a3

Browse files
authored
Merge pull request #2167 from pre-commit/dead
run dead, remove dead code
2 parents de177e8 + 42b0a26 commit 44687a3

3 files changed

Lines changed: 2 additions & 69 deletions

File tree

pre_commit/commands/install_uninstall.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import itertools
21
import logging
32
import os.path
43
import shlex
@@ -31,10 +30,6 @@
3130
CURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03'
3231
TEMPLATE_START = '# start templated\n'
3332
TEMPLATE_END = '# end templated\n'
34-
# Homebrew/homebrew-core#35825: be more timid about appropriate `PATH`
35-
# #1312 os.defpath is too restrictive on BSD
36-
POSIX_SEARCH_PATH = ('/usr/local/bin', '/usr/bin', '/bin')
37-
SYS_EXE = os.path.basename(os.path.realpath(sys.executable))
3833

3934

4035
def _hook_paths(
@@ -54,26 +49,6 @@ def is_our_script(filename: str) -> bool:
5449
return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES)
5550

5651

57-
def shebang() -> str:
58-
if sys.platform == 'win32':
59-
py, _ = os.path.splitext(SYS_EXE)
60-
else:
61-
exe_choices = [
62-
f'python{sys.version_info[0]}.{sys.version_info[1]}',
63-
f'python{sys.version_info[0]}',
64-
]
65-
# avoid searching for bare `python` as it's likely to be python 2
66-
if SYS_EXE != 'python':
67-
exe_choices.append(SYS_EXE)
68-
for path, exe in itertools.product(POSIX_SEARCH_PATH, exe_choices):
69-
if os.access(os.path.join(path, exe), os.X_OK):
70-
py = exe
71-
break
72-
else:
73-
py = SYS_EXE
74-
return f'#!/usr/bin/env {py}'
75-
76-
7752
def _install_hook_script(
7853
config_file: str,
7954
hook_type: str,

pre_commit/commands/run.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,6 @@ def _run_hooks(
275275
hooks: Sequence[Hook],
276276
skips: Set[str],
277277
args: argparse.Namespace,
278-
environ: MutableMapping[str, str],
279278
) -> int:
280279
"""Actually run the hooks."""
281280
cols = _compute_cols(hooks)
@@ -416,7 +415,7 @@ def run(
416415
to_install = [hook for hook in hooks if hook.id not in skips]
417416
install_hook_envs(to_install, store)
418417

419-
return _run_hooks(config, hooks, skips, args, environ)
418+
return _run_hooks(config, hooks, skips, args)
420419

421420
# https://github.com/python/mypy/issues/7726
422421
raise AssertionError('unreachable')

tests/commands/install_uninstall_test.py

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
import os.path
22
import re
3-
import sys
4-
from unittest import mock
53

64
import re_assert
75

86
import pre_commit.constants as C
97
from pre_commit import git
10-
from pre_commit.commands import install_uninstall
118
from pre_commit.commands.install_uninstall import CURRENT_HASH
129
from pre_commit.commands.install_uninstall import install
1310
from pre_commit.commands.install_uninstall import install_hooks
1411
from pre_commit.commands.install_uninstall import is_our_script
1512
from pre_commit.commands.install_uninstall import PRIOR_HASHES
16-
from pre_commit.commands.install_uninstall import shebang
1713
from pre_commit.commands.install_uninstall import uninstall
1814
from pre_commit.parse_shebang import find_executable
1915
from pre_commit.util import cmd_output
@@ -43,43 +39,6 @@ def test_is_previous_pre_commit(tmpdir):
4339
assert is_our_script(f.strpath)
4440

4541

46-
def patch_platform(platform):
47-
return mock.patch.object(sys, 'platform', platform)
48-
49-
50-
def patch_lookup_path(path):
51-
return mock.patch.object(install_uninstall, 'POSIX_SEARCH_PATH', path)
52-
53-
54-
def patch_sys_exe(exe):
55-
return mock.patch.object(install_uninstall, 'SYS_EXE', exe)
56-
57-
58-
def test_shebang_windows():
59-
with patch_platform('win32'), patch_sys_exe('python'):
60-
assert shebang() == '#!/usr/bin/env python'
61-
62-
63-
def test_shebang_windows_drop_ext():
64-
with patch_platform('win32'), patch_sys_exe('python.exe'):
65-
assert shebang() == '#!/usr/bin/env python'
66-
67-
68-
def test_shebang_posix_not_on_path():
69-
with patch_platform('posix'), patch_lookup_path(()):
70-
with patch_sys_exe('python3.6'):
71-
assert shebang() == '#!/usr/bin/env python3.6'
72-
73-
74-
def test_shebang_posix_on_path(tmpdir):
75-
exe = tmpdir.join(f'python{sys.version_info[0]}').ensure()
76-
make_executable(exe)
77-
78-
with patch_platform('posix'), patch_lookup_path((tmpdir.strpath,)):
79-
with patch_sys_exe('python'):
80-
assert shebang() == f'#!/usr/bin/env python{sys.version_info[0]}'
81-
82-
8342
def test_install_pre_commit(in_git_dir, store):
8443
assert not install(C.CONFIG_FILE, store, hook_types=['pre-commit'])
8544
assert os.access(in_git_dir.join('.git/hooks/pre-commit').strpath, os.X_OK)
@@ -336,7 +295,7 @@ def test_failing_hooks_returns_nonzero(tempdir_factory, store):
336295
def _write_legacy_hook(path):
337296
os.makedirs(os.path.join(path, '.git/hooks'), exist_ok=True)
338297
with open(os.path.join(path, '.git/hooks/pre-commit'), 'w') as f:
339-
f.write(f'{shebang()}\nprint("legacy hook")\n')
298+
f.write('#!/usr/bin/env bash\necho legacy hook\n')
340299
make_executable(f.name)
341300

342301

0 commit comments

Comments
 (0)