|
1 |
| -"""Tests for the minimum dependencies in the README.rst file.""" |
| 1 | +"""Tests for the minimum dependencies in README.rst and pyproject.toml""" |
2 | 2 |
|
3 | 3 |
|
4 | 4 | import os
|
@@ -50,3 +50,39 @@ def test_min_dependencies_readme():
|
50 | 50 | min_version = parse_version(dependent_packages[package][0])
|
51 | 51 |
|
52 | 52 | 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