diff options
Diffstat (limited to 'pre_commit/commands')
-rw-r--r-- | pre_commit/commands/install_uninstall.py | 32 | ||||
-rw-r--r-- | pre_commit/commands/run.py | 3 |
2 files changed, 8 insertions, 27 deletions
diff --git a/pre_commit/commands/install_uninstall.py b/pre_commit/commands/install_uninstall.py index 7974423..50c6443 100644 --- a/pre_commit/commands/install_uninstall.py +++ b/pre_commit/commands/install_uninstall.py @@ -1,4 +1,3 @@ -import itertools import logging import os.path import shlex @@ -31,10 +30,6 @@ PRIOR_HASHES = ( CURRENT_HASH = b'138fd403232d2ddd5efb44317e38bf03' TEMPLATE_START = '# start templated\n' TEMPLATE_END = '# end templated\n' -# Homebrew/homebrew-core#35825: be more timid about appropriate `PATH` -# #1312 os.defpath is too restrictive on BSD -POSIX_SEARCH_PATH = ('/usr/local/bin', '/usr/bin', '/bin') -SYS_EXE = os.path.basename(os.path.realpath(sys.executable)) def _hook_paths( @@ -54,26 +49,6 @@ def is_our_script(filename: str) -> bool: return any(h in contents for h in (CURRENT_HASH,) + PRIOR_HASHES) -def shebang() -> str: - if sys.platform == 'win32': - py, _ = os.path.splitext(SYS_EXE) - else: - exe_choices = [ - f'python{sys.version_info[0]}.{sys.version_info[1]}', - f'python{sys.version_info[0]}', - ] - # avoid searching for bare `python` as it's likely to be python 2 - if SYS_EXE != 'python': - exe_choices.append(SYS_EXE) - for path, exe in itertools.product(POSIX_SEARCH_PATH, exe_choices): - if os.access(os.path.join(path, exe), os.X_OK): - py = exe - break - else: - py = SYS_EXE - return f'#!/usr/bin/env {py}' - - def _install_hook_script( config_file: str, hook_type: str, @@ -107,6 +82,13 @@ def _install_hook_script( before, rest = contents.split(TEMPLATE_START) _, after = rest.split(TEMPLATE_END) + # on windows always use `/bin/sh` since `bash` might not be on PATH + # though we use bash-specific features `sh` on windows is actually + # bash in "POSIXLY_CORRECT" mode which still supports the features we + # use: subshells / arrays + if sys.platform == 'win32': # pragma: win32 cover + hook_file.write('#!/bin/sh\n') + hook_file.write(before + TEMPLATE_START) hook_file.write(f'INSTALL_PYTHON={shlex.quote(sys.executable)}\n') # TODO: python3.8+: shlex.join diff --git a/pre_commit/commands/run.py b/pre_commit/commands/run.py index 2714faf..f8ced0f 100644 --- a/pre_commit/commands/run.py +++ b/pre_commit/commands/run.py @@ -275,7 +275,6 @@ def _run_hooks( hooks: Sequence[Hook], skips: Set[str], args: argparse.Namespace, - environ: MutableMapping[str, str], ) -> int: """Actually run the hooks.""" cols = _compute_cols(hooks) @@ -416,7 +415,7 @@ def run( to_install = [hook for hook in hooks if hook.id not in skips] install_hook_envs(to_install, store) - return _run_hooks(config, hooks, skips, args, environ) + return _run_hooks(config, hooks, skips, args) # https://github.com/python/mypy/issues/7726 raise AssertionError('unreachable') |