|
17 | 17 | Iterable,
|
18 | 18 | Iterator,
|
19 | 19 | List,
|
| 20 | + Literal, |
20 | 21 | Optional,
|
21 | 22 | Tuple,
|
22 | 23 | Generator,
|
|
41 | 42 | PYO3_GUIDE_SRC = PYO3_DIR / "guide" / "src"
|
42 | 43 | PYO3_GUIDE_TARGET = PYO3_TARGET / "guide"
|
43 | 44 | PYO3_DOCS_TARGET = PYO3_TARGET / "doc"
|
44 |
| -PY_VERSIONS = ("3.7", "3.8", "3.9", "3.10", "3.11", "3.12", "3.13") |
45 |
| -PYPY_VERSIONS = ("3.9", "3.10", "3.11") |
46 | 45 | FREE_THREADED_BUILD = bool(sysconfig.get_config_var("Py_GIL_DISABLED"))
|
47 | 46 |
|
48 | 47 |
|
| 48 | +def _get_output(*args: str) -> str: |
| 49 | + return subprocess.run(args, capture_output=True, text=True, check=True).stdout |
| 50 | + |
| 51 | + |
| 52 | +def _parse_supported_interpreter_version( |
| 53 | + python_impl: Literal["cpython", "pypy"], |
| 54 | +) -> Tuple[str, str]: |
| 55 | + output = _get_output("cargo", "metadata", "--format-version=1", "--no-deps") |
| 56 | + cargo_packages = json.loads(output)["packages"] |
| 57 | + # Check Python interpreter version support in package metadata |
| 58 | + package = "pyo3-ffi" |
| 59 | + metadata = next(pkg["metadata"] for pkg in cargo_packages if pkg["name"] == package) |
| 60 | + version_info = metadata[python_impl] |
| 61 | + assert "min-version" in version_info, f"missing min-version for {python_impl}" |
| 62 | + assert "max-version" in version_info, f"missing max-version for {python_impl}" |
| 63 | + return version_info["min-version"], version_info["max-version"] |
| 64 | + |
| 65 | + |
| 66 | +def _supported_interpreter_versions( |
| 67 | + python_impl: Literal["cpython", "pypy"], |
| 68 | +) -> List[str]: |
| 69 | + min_version, max_version = _parse_supported_interpreter_version(python_impl) |
| 70 | + major = int(min_version.split(".")[0]) |
| 71 | + assert major == 3, f"unsupported Python major version {major}" |
| 72 | + min_minor = int(min_version.split(".")[1]) |
| 73 | + max_minor = int(max_version.split(".")[1]) |
| 74 | + versions = [f"{major}.{minor}" for minor in range(min_minor, max_minor + 1)] |
| 75 | + return versions |
| 76 | + |
| 77 | + |
| 78 | +PY_VERSIONS = _supported_interpreter_versions("cpython") |
| 79 | +PYPY_VERSIONS = _supported_interpreter_versions("pypy") |
| 80 | + |
| 81 | + |
49 | 82 | @nox.session(venv_backend="none")
|
50 | 83 | def test(session: nox.Session) -> None:
|
51 | 84 | test_rust(session)
|
@@ -931,10 +964,6 @@ def _run_cargo_set_package_version(
|
931 | 964 | _run(session, *command, external=True)
|
932 | 965 |
|
933 | 966 |
|
934 |
| -def _get_output(*args: str) -> str: |
935 |
| - return subprocess.run(args, capture_output=True, text=True, check=True).stdout |
936 |
| - |
937 |
| - |
938 | 967 | def _for_all_version_configs(
|
939 | 968 | session: nox.Session, job: Callable[[Dict[str, str]], None]
|
940 | 969 | ) -> None:
|
|
0 commit comments