|
| 1 | +import time |
| 2 | +import re |
| 3 | +import sys |
| 4 | + |
| 5 | +import requests |
| 6 | + |
| 7 | +from collections import defaultdict |
| 8 | + |
| 9 | +from pathlib import Path |
| 10 | + |
| 11 | +from tox.config.cli.parse import get_options |
| 12 | +from tox.session.state import State |
| 13 | +from tox.config.sets import CoreConfigSet |
| 14 | +from tox.config.source.tox_ini import ToxIni |
| 15 | + |
| 16 | +PYTHON_VERSION = "3.13" |
| 17 | + |
| 18 | +MATCH_LIB_SENTRY_REGEX = r"py[\d\.]*-(.*)-.*" |
| 19 | + |
| 20 | +PYPI_PROJECT_URL = "https://pypi.python.org/pypi/{project}/json" |
| 21 | +PYPI_VERSION_URL = "https://pypi.python.org/pypi/{project}/{version}/json" |
| 22 | + |
| 23 | + |
| 24 | +def get_tox_envs(tox_ini_path: Path) -> list: |
| 25 | + tox_ini = ToxIni(tox_ini_path) |
| 26 | + conf = State(get_options(), []).conf |
| 27 | + tox_section = next(tox_ini.sections()) |
| 28 | + core_config_set = CoreConfigSet( |
| 29 | + conf, tox_section, tox_ini_path.parent, tox_ini_path |
| 30 | + ) |
| 31 | + ( |
| 32 | + core_config_set.loaders.extend( |
| 33 | + tox_ini.get_loaders( |
| 34 | + tox_section, |
| 35 | + base=[], |
| 36 | + override_map=defaultdict(list, {}), |
| 37 | + conf=core_config_set, |
| 38 | + ) |
| 39 | + ) |
| 40 | + ) |
| 41 | + return core_config_set.load("env_list") |
| 42 | + |
| 43 | + |
| 44 | +def get_libs(tox_ini: Path, regex: str) -> set: |
| 45 | + libs = set() |
| 46 | + for env in get_tox_envs(tox_ini): |
| 47 | + match = re.match(regex, env) |
| 48 | + if match: |
| 49 | + libs.add(match.group(1)) |
| 50 | + |
| 51 | + return sorted(libs) |
| 52 | + |
| 53 | + |
| 54 | +def main(): |
| 55 | + """ |
| 56 | + Check if libraries in our tox.ini are ready for Python version defined in `PYTHON_VERSION`. |
| 57 | + """ |
| 58 | + print(f"Checking libs from tox.ini for Python {PYTHON_VERSION} compatibility:") |
| 59 | + |
| 60 | + ready = set() |
| 61 | + not_ready = set() |
| 62 | + not_found = set() |
| 63 | + |
| 64 | + tox_ini = Path(__file__).parent.parent.parent.joinpath("tox.ini") |
| 65 | + |
| 66 | + libs = get_libs(tox_ini, MATCH_LIB_SENTRY_REGEX) |
| 67 | + |
| 68 | + for lib in libs: |
| 69 | + print(".", end="") |
| 70 | + sys.stdout.flush() |
| 71 | + |
| 72 | + # Get latest version of lib |
| 73 | + url = PYPI_PROJECT_URL.format(project=lib) |
| 74 | + pypi_data = requests.get(url) |
| 75 | + |
| 76 | + if pypi_data.status_code != 200: |
| 77 | + not_found.add(lib) |
| 78 | + continue |
| 79 | + |
| 80 | + latest_version = pypi_data.json()["info"]["version"] |
| 81 | + |
| 82 | + # Get supported Python version of latest version of lib |
| 83 | + url = PYPI_PROJECT_URL.format(project=lib, version=latest_version) |
| 84 | + pypi_data = requests.get(url) |
| 85 | + |
| 86 | + if pypi_data.status_code != 200: |
| 87 | + continue |
| 88 | + |
| 89 | + classifiers = pypi_data.json()["info"]["classifiers"] |
| 90 | + |
| 91 | + if f"Programming Language :: Python :: {PYTHON_VERSION}" in classifiers: |
| 92 | + ready.add(lib) |
| 93 | + else: |
| 94 | + not_ready.add(lib) |
| 95 | + |
| 96 | + # cut pypi some slack |
| 97 | + time.sleep(0.1) |
| 98 | + |
| 99 | + # Print report |
| 100 | + print("\n") |
| 101 | + print(f"\nReady for Python {PYTHON_VERSION}:") |
| 102 | + if len(ready) == 0: |
| 103 | + print("- None ") |
| 104 | + |
| 105 | + for x in sorted(ready): |
| 106 | + print(f"- {x}") |
| 107 | + |
| 108 | + print(f"\nNOT ready for Python {PYTHON_VERSION}:") |
| 109 | + if len(not_ready) == 0: |
| 110 | + print("- None ") |
| 111 | + |
| 112 | + for x in sorted(not_ready): |
| 113 | + print(f"- {x}") |
| 114 | + |
| 115 | + print("\nNot found on PyPI:") |
| 116 | + if len(not_found) == 0: |
| 117 | + print("- None ") |
| 118 | + |
| 119 | + for x in sorted(not_found): |
| 120 | + print(f"- {x}") |
| 121 | + |
| 122 | + |
| 123 | +if __name__ == "__main__": |
| 124 | + main() |
0 commit comments