Skip to content

Commit 7c9ab9c

Browse files
authored
Dynamic build matrix (#99)
* Dynamically generate build matrix for all supported SQLAlchemy versions * Fix formatting
1 parent a657c7e commit 7c9ab9c

File tree

2 files changed

+39
-10
lines changed

2 files changed

+39
-10
lines changed

noxfile.py

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# dependencies = [
1010
# "nox",
1111
# "nox-uv",
12+
# "requests",
1213
# ]
1314
# ///
1415
""" Entry point script for testing, linting, and development of the package.
@@ -31,14 +32,17 @@
3132
$ uv run noxfile.py -s dev -P 3.X
3233
$ uv run noxfile.py -s dev -P pypy-3.X # For PyPy
3334
"""
35+
from itertools import groupby
36+
3437
import nox
38+
from packaging.requirements import Requirement
39+
from packaging.version import Version
40+
import requests
3541

3642

3743
# Python versions supported and tested against: 3.8, 3.9, 3.10, 3.11
3844
PYTHON_MINOR_VERSION_MIN = 8
3945
PYTHON_MINOR_VERSION_MAX = 11
40-
# SQLAlchemy versions supported and tested against: 1.0, 1.1, 1.2, 1.3
41-
SQLALCHEMY_VERSIONS = ["1.0", "1.1", "1.2", "1.3"]
4246

4347
nox.options.default_venv_backend = "uv"
4448

@@ -56,14 +60,37 @@ def lint(session):
5660
"--max-line-length=127", "--statistics", "--extend-exclude", ".venv")
5761

5862

63+
def parametrize_test_versions():
64+
"""Parametrize the session with all supported Python & SQLAlchemy versions."""
65+
response = requests.get("https://pypi.org/pypi/SQLAlchemy/json")
66+
response.raise_for_status()
67+
data = response.json()
68+
all_major_and_minor_sqlalchemy_versions = [
69+
Version(f"{major}.{minor}")
70+
for (major, minor), _ in groupby(
71+
sorted(Version(version) for version in data["releases"].keys()),
72+
key=lambda v: (v.major, v.minor)
73+
)
74+
]
75+
76+
with open("requirements.txt", "r") as f:
77+
requirement = Requirement(f.read().strip())
78+
filtered_sqlalchemy_versions = [
79+
version for version in all_major_and_minor_sqlalchemy_versions
80+
if version in requirement.specifier
81+
]
82+
83+
return [
84+
(f"{interpreter}3.{python_minor}", str(sqlalchemy_version))
85+
for interpreter in ("", "pypy-")
86+
for python_minor in range(PYTHON_MINOR_VERSION_MIN, PYTHON_MINOR_VERSION_MAX + 1)
87+
for sqlalchemy_version in filtered_sqlalchemy_versions
88+
# SQLA 1.1 or below doesn't seem to support Python 3.10+
89+
if sqlalchemy_version >= Version("1.2") or python_minor <= 9]
90+
91+
5992
@nox.session()
60-
@nox.parametrize("python,sqlalchemy",
61-
[(f"{interpreter}3.{python_minor}", sqlalchemy_version)
62-
for interpreter in ("", "pypy-")
63-
for python_minor in range(PYTHON_MINOR_VERSION_MIN, PYTHON_MINOR_VERSION_MAX + 1)
64-
for sqlalchemy_version in SQLALCHEMY_VERSIONS
65-
# SQLA 1.1 or below doesn't seem to support Python 3.10+
66-
if sqlalchemy_version >= "1.2" or python_minor <= 9])
93+
@nox.parametrize("python,sqlalchemy", parametrize_test_versions())
6794
def test(session, sqlalchemy):
6895
"""Run tests with pytest.
6996

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def read(name):
2121
include_package_data=True,
2222
zip_safe=False,
2323
license="MIT",
24-
description="SQLAlchemy mixins for implementing tree-like models using Modified Pre-order Tree Traversal (MPTT) / Nested Sets",
24+
description=(
25+
"SQLAlchemy mixins for implementing tree-like models"
26+
" using Modified Pre-order Tree Traversal (MPTT) / Nested Sets"),
2527
long_description=read("README.rst") + "\n" + read("CHANGES.rst"),
2628
install_requires=read("requirements.txt"),
2729
classifiers=[

0 commit comments

Comments
 (0)