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

Function _find_by_sys_executable

pre_commit/languages/python.py:85–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83
84
85def _find_by_sys_executable() -> str | None:
86 def _norm(path: str) -> str | None:
87 _, exe = os.path.split(path.lower())
88 exe, _, _ = exe.partition('.exe')
89 if exe not in {'python', 'pythonw'} and find_executable(exe):
90 return exe
91 return None
92
93 # On linux, I see these common sys.executables:
94 #
95 # system `python`: /usr/bin/python -> python2.7
96 # system `python2`: /usr/bin/python2 -> python2.7
97 # virtualenv v: v/bin/python (will not return from this loop)
98 # virtualenv v -ppython2: v/bin/python -> python2
99 # virtualenv v -ppython2.7: v/bin/python -> python2.7
100 # virtualenv v -ppypy: v/bin/python -> v/bin/pypy
101 for path in (sys.executable, os.path.realpath(sys.executable)):
102 exe = _norm(path)
103 if exe:
104 return exe
105 return None
106
107
108@functools.lru_cache(maxsize=1)

Callers 1

get_default_versionFunction · 0.85

Calls 1

_normFunction · 0.70

Tested by

no test coverage detected