MCPcopy Create free account
hub / github.com/bloomberg/pystack / find_all_available_pythons

Function find_all_available_pythons

tests/utils.py:43–81  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

41
42
43def find_all_available_pythons() -> Iterable[Interpreter]: # pragma: no cover
44 versions: List[Tuple[Tuple[int, int], str]]
45 test_version = os.getenv("PYTHON_TEST_VERSION")
46 if test_version == "auto":
47 versions = [((sys.version_info[0], sys.version_info[1]), sys.executable)]
48 elif test_version is not None:
49 major, minor = test_version.split(".")
50 if minor.endswith("t"):
51 minor = minor[:-1]
52 versions = [((int(major), int(minor)), f"python{test_version}")]
53 else:
54 versions = ALL_VERSIONS
55
56 for version, name in versions:
57 location = shutil.which(name)
58 if not location:
59 continue
60
61 result = subprocess.run(
62 [location, "--version"],
63 stdout=subprocess.DEVNULL,
64 stderr=subprocess.DEVNULL,
65 )
66 if result.returncode != 0:
67 continue
68
69 result = subprocess.run(
70 ["file", "-L", location],
71 stdout=subprocess.PIPE,
72 stderr=subprocess.DEVNULL,
73 )
74 if result.returncode != 0:
75 continue
76 assert result.stdout is not None
77 has_symbols = result.returncode == 0 and (
78 b" stripped" not in result.stdout or b"not stripped" in result.stdout
79 )
80
81 yield Interpreter(version, pathlib.Path(location), has_symbols)
82
83
84AVAILABLE_PYTHONS = tuple(find_all_available_pythons())

Callers 1

utils.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected