summaryrefslogtreecommitdiffstats
path: root/pre_commit/parse_shebang.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2023-01-30 16:53:19 +0000
commit02d5100afa71d1343de4066b812cd4cdc774d812 (patch)
tree6bccae957398fab29aaa226fb0bd65f0c258a36a /pre_commit/parse_shebang.py
parentAdding upstream version 2.21.0. (diff)
downloadpre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.tar.xz
pre-commit-02d5100afa71d1343de4066b812cd4cdc774d812.zip
Adding upstream version 3.0.2.upstream/3.0.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pre_commit/parse_shebang.py')
-rw-r--r--pre_commit/parse_shebang.py18
1 files changed, 11 insertions, 7 deletions
diff --git a/pre_commit/parse_shebang.py b/pre_commit/parse_shebang.py
index 3ac933c..3ee04e8 100644
--- a/pre_commit/parse_shebang.py
+++ b/pre_commit/parse_shebang.py
@@ -20,13 +20,13 @@ def parse_filename(filename: str) -> tuple[str, ...]:
def find_executable(
- exe: str, _environ: Mapping[str, str] | None = None,
+ exe: str, *, env: Mapping[str, str] | None = None,
) -> str | None:
exe = os.path.normpath(exe)
if os.sep in exe:
return exe
- environ = _environ if _environ is not None else os.environ
+ environ = env if env is not None else os.environ
if 'PATHEXT' in environ:
exts = environ['PATHEXT'].split(os.pathsep)
@@ -43,12 +43,12 @@ def find_executable(
return None
-def normexe(orig: str) -> str:
+def normexe(orig: str, *, env: Mapping[str, str] | None = None) -> str:
def _error(msg: str) -> NoReturn:
raise ExecutableNotFoundError(f'Executable `{orig}` {msg}')
if os.sep not in orig and (not os.altsep or os.altsep not in orig):
- exe = find_executable(orig)
+ exe = find_executable(orig, env=env)
if exe is None:
_error('not found')
return exe
@@ -62,7 +62,11 @@ def normexe(orig: str) -> str:
return orig
-def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
+def normalize_cmd(
+ cmd: tuple[str, ...],
+ *,
+ env: Mapping[str, str] | None = None,
+) -> tuple[str, ...]:
"""Fixes for the following issues on windows
- https://bugs.python.org/issue8557
- windows does not parse shebangs
@@ -70,12 +74,12 @@ def normalize_cmd(cmd: tuple[str, ...]) -> tuple[str, ...]:
This function also makes deep-path shebangs work just fine
"""
# Use PATH to determine the executable
- exe = normexe(cmd[0])
+ exe = normexe(cmd[0], env=env)
# Figure out the shebang from the resulting command
cmd = parse_filename(exe) + (exe,) + cmd[1:]
# This could have given us back another bare executable
- exe = normexe(cmd[0])
+ exe = normexe(cmd[0], env=env)
return (exe,) + cmd[1:]