MCPcopy Index your code
hub / github.com/python/mypy / _python_executable_from_version

Function _python_executable_from_version

mypy/main.py:326–344  ·  view source on GitHub ↗
(python_version: tuple[int, int])

Source from the content-addressed store, hash-verified

324
325
326def _python_executable_from_version(python_version: tuple[int, int]) -> str:
327 if sys.version_info[:2] == python_version:
328 return sys.executable
329 str_ver = ".".join(map(str, python_version))
330 try:
331 sys_exe = (
332 subprocess.check_output(
333 python_executable_prefix(str_ver) + ["-c", "import sys; print(sys.executable)"],
334 stderr=subprocess.STDOUT,
335 )
336 .decode()
337 .strip()
338 )
339 return sys_exe
340 except (subprocess.CalledProcessError, FileNotFoundError) as e:
341 raise PythonExecutableInferenceError(
342 "failed to find a Python executable matching version {},"
343 " perhaps try --python-executable, or --no-site-packages?".format(python_version)
344 ) from e
345
346
347def infer_python_executable(options: Options, special_opts: argparse.Namespace) -> None:

Callers 1

infer_python_executableFunction · 0.85

Calls 7

mapClass · 0.85
python_executable_prefixFunction · 0.85
stripMethod · 0.80
joinMethod · 0.45
decodeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…