MCPcopy Index your code
hub / github.com/pre-commit/pre-commit / normalize_cmd

Function normalize_cmd

pre_commit/parse_shebang.py:65–85  ·  view source on GitHub ↗

Fixes for the following issues on windows - https://bugs.python.org/issue8557 - windows does not parse shebangs This function also makes deep-path shebangs work just fine

(
        cmd: tuple[str, ...],
        *,
        env: Mapping[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

63
64
65def normalize_cmd(
66 cmd: tuple[str, ...],
67 *,
68 env: Mapping[str, str] | None = None,
69) -> tuple[str, ...]:
70 """Fixes for the following issues on windows
71 - https://bugs.python.org/issue8557
72 - windows does not parse shebangs
73
74 This function also makes deep-path shebangs work just fine
75 """
76 # Use PATH to determine the executable
77 exe = normexe(cmd[0], env=env)
78
79 # Figure out the shebang from the resulting command
80 cmd = parse_filename(exe) + (exe,) + cmd[1:]
81
82 # This could have given us back another bare executable
83 exe = normexe(cmd[0], env=env)
84
85 return (exe,) + cmd[1:]

Callers 4

_run_legacyFunction · 0.90
cdFunction · 0.90
ignore_exit_codeFunction · 0.90
n1Function · 0.90

Calls 2

normexeFunction · 0.85
parse_filenameFunction · 0.85

Tested by

no test coverage detected