Skip to content

Commit

Permalink
MNT Use substitutions for minimum dependencies in README.rst (scikit-…
Browse files Browse the repository at this point in the history
…learn#18301)

Co-authored-by: Thomas J. Fan <[email protected]>
  • Loading branch information
alfaro96 and thomasjpfan authored Sep 23, 2020
1 parent 4aada4e commit 09c41fe
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 12 deletions.
36 changes: 24 additions & 12 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
.. |DOI| image:: https://zenodo.org/badge/21369/scikit-learn/scikit-learn.svg
.. _DOI: https://zenodo.org/badge/latestdoi/21369/scikit-learn/scikit-learn

.. |PythonMinVersion| replace:: 3.6
.. |NumPyMinVersion| replace:: 1.13.3
.. |SciPyMinVersion| replace:: 0.19.1
.. |JoblibMinVersion| replace:: 0.11
.. |ThreadpoolctlMinVersion| replace:: 2.0.0
.. |MatplotlibMinVersion| replace:: 2.1.1
.. |Scikit-ImageMinVersion| replace:: 0.13
.. |PandasMinVersion| replace:: 0.25.0
.. |SeabornMinVersion| replace:: 0.9.0
.. |PytestMinVersion| replace:: 5.0.1

.. image:: doc/logos/scikit-learn-logo.png
:target: https://scikit-learn.org/

Expand All @@ -46,22 +57,23 @@ Dependencies

scikit-learn requires:

- Python (>= 3.6)
- NumPy (>= 1.13.3)
- SciPy (>= 0.19.1)
- joblib (>= 0.11)
- threadpoolctl (>= 2.0.0)
- Python (>= |PythonMinVersion|)
- NumPy (>= |NumPyMinVersion|)
- SciPy (>= |SciPyMinVersion|)
- joblib (>= |JoblibMinVersion|)
- threadpoolctl (>= |ThreadpoolctlMinVersion|)

=======

**Scikit-learn 0.20 was the last version to support Python 2.7 and Python 3.4.**
scikit-learn 0.23 and later require Python 3.6 or newer.

Scikit-learn plotting capabilities (i.e., functions start with ``plot_``
and classes end with "Display") require Matplotlib (>= 2.1.1). For running the
examples Matplotlib >= 2.1.1 is required. A few examples require
scikit-image >= 0.13, a few examples require pandas >= 0.25.0, some examples
require seaborn >= 0.9.0.
Scikit-learn plotting capabilities (i.e., functions start with ``plot_`` and
classes end with "Display") require Matplotlib (>= |MatplotlibMinVersion|).
For running the examples Matplotlib >= |MatplotlibMinVersion| is required.
A few examples require scikit-image >= |ScikitImageMinVersion|, a few examples
require pandas >= |PandasMinVersion|, some examples require seaborn >=
|SeabornMinVersion|.

User installation
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -117,8 +129,8 @@ To learn more about making a contribution to scikit-learn, please see our
Testing
~~~~~~~

After installation, you can launch the test suite from outside the
source directory (you will need to have ``pytest`` >= 5.0.1 installed)::
After installation, you can launch the test suite from outside the source
directory (you will need to have ``pytest`` >= |PyTestMinVersion| installed)::

pytest sklearn

Expand Down
45 changes: 45 additions & 0 deletions sklearn/tests/test_min_dependencies_readme.py
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

0 comments on commit 09c41fe

Please sign in to comment.