8000 MAINT Check pyproject toml is consistent with min_dependencies (#25610) · scikit-learn/scikit-learn@b472ad8 · GitHub
[go: up one dir, main page]

Skip to content

Commit b472ad8

Browse files
thomasjpfanjeremiedbb
authored andcommitted
MAINT Check pyproject toml is consistent with min_dependencies (#25610)
* MAINT Check pyproject toml is consistent with min_dependencies * CLN Make it clear that only SciPy and Cython are checked * CLN Revert auto formatter
1 parent 06afa36 commit b472ad8

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

sklearn/tests/test_min_dependencies_readme.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Tests for the minimum dependencies in the README.rst file."""
1+
"""Tests for the minimum dependencies in README.rst and pyproject.toml"""
22

33

44
import os
@@ -50,3 +50,39 @@ def test_min_dependencies_readme():
5050
min_version = parse_version(dependent_packages[package][0])
5151

5252
assert version == min_version, f"{package} has a mismatched version"
53+
54+
55+
def test_min_dependencies_pyproject_toml():
56+
"""Check versions in pyproject.toml is consistent with _min_dependencies."""
57+
# tomllib is available in Python 3.11
58+
tomllib = pytest.importorskip("tomllib")
59+
60+
root_directory = Path(sklearn.__path__[0]).parent
61+
pyproject_toml_path = root_directory / "pyproject.toml"
62+
63+
if not pyproject_toml_path.exists():
64+
# Skip the test if the pyproject.toml file is not available.
65+
# For instance, when installing scikit-learn from wheels
66+
pytest.skip("pyproject.toml is not available.")
67+
68+
with pyproject_toml_path.open("rb") as f:
69+
pyproject_toml = tomllib.load(f)
70+
71+
build_requirements = pyproject_toml["build-system"]["requires"]
72+
73+
pyproject_build_min_versions = {}
74+
for requirement in build_requirements:
75+
if ">=" in requirement:
76+
package, version = requirement.split(">=")
77+
package = package.lower()
78+
pyproject_build_min_versions[package] = version
79+
80+
# Only scipy and cython are listed in pyproject.toml
81+
# NumPy is more complex using oldest-supported-numpy.
82+
assert set(["scipy", "cython"]) == set(pyproject_build_min_versions)
83+
84+
for package, version in pyproject_build_min_versions.items():
85+
version = parse_version(version)
86+
expected_min_version = parse_version(dependent_packages[package][0])
87+
88+
assert version == expected_min_version, f"{package} has a mismatched version"

0 commit comments

Comments
 (0)
0