forked from scikit-learn/scikit-learn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MNT Use substitutions for minimum dependencies in README.rst (scikit-…
…learn#18301) Co-authored-by: Thomas J. Fan <[email protected]>
- Loading branch information
1 parent
4aada4e
commit 09c41fe
Showing
2 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""Tests for the minimum dependencies in the README.rst file.""" | ||
|
||
|
||
import os | ||
import re | ||
from pathlib import Path | ||
|
||
import pytest | ||
import sklearn | ||
from sklearn._build_utils.min_dependencies import dependent_packages | ||
from sklearn.utils.fixes import parse_version | ||
|
||
|
||
def test_min_dependencies_readme(): | ||
# Test that the minimum dependencies in the README.rst file are | ||
# consistent with the minimum dependencies defined at the file: | ||
# sklearn/_build_utils/min_dependencies.py | ||
|
||
pattern = re.compile(r"(\.\. \|)" + | ||
r"(([A-Za-z]+\-?)+)" + | ||
r"(MinVersion\| replace::)" + | ||
r"( [0-9]+\.[0-9]+(\.[0-9]+)?)") | ||
|
||
readme_path = Path(sklearn.__path__[0]).parents[0] | ||
readme_file = readme_path / "README.rst" | ||
|
||
if not os.path.exists(readme_file): | ||
# Skip the test if the README.rst file is not available. | ||
# For instance, when installing scikit-learn from wheels | ||
pytest.skip("The README.rst file is not available.") | ||
|
||
with readme_file.open("r") as f: | ||
for line in f: | ||
matched = pattern.match(line) | ||
|
||
if not matched: | ||
continue | ||
|
||
package, version = matched.group(2), matched.group(5) | ||
|
||
if package in dependent_packages: | ||
version = parse_version(version) | ||
min_version = parse_version(dependent_packages[package][0]) | ||
|
||
assert version == min_version |