1
0
Fork 0

Merging upstream version 2.17.0.

Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
Daniel Baumann 2025-02-09 21:32:33 +01:00
parent 27828ee7f3
commit 66bc55f7a7
Signed by: daniel
GPG key ID: FBB4F0E80A80222F
34 changed files with 336 additions and 116 deletions

View file

@ -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