| 41 | |
| 42 | |
| 43 | def 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 | |
| 84 | AVAILABLE_PYTHONS = tuple(find_all_available_pythons()) |