summaryrefslogtreecommitdiffstats
path: root/pre_commit/commands/install_uninstall.py
diff options
context:
space:
mode:
Diffstat (limited to 'pre_commit/commands/install_uninstall.py')
-rw-r--r--pre_commit/commands/install_uninstall.py32
1 files changed, 7 insertions, 25 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