8000 MNT packaging instead of a custom regex to parse versions (#15566) · scikit-learn/scikit-learn@ad57efa · GitHub
[go: up one dir, main page]

Skip to content

Commit ad57efa

Browse files
authored
MNT packaging instead of a custom regex to parse versions (#15566)
* use x.y.z (no rc/beta/etc) for version in sphinx config * use parse_version, and refactor binder branch inference * install packaging in doc build envs * use packaging
1 parent 28d2c97 commit ad57efa

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

build_tools/circle/build_doc.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,13 @@ if [[ "$CIRCLE_JOB" == "doc-min-dependencies" ]]; then
125125
conda config --set restore_free_channel true
126126
fi
127127

128+
# packaging won't be needed once setuptools starts shipping packaging>=17.0
128129
conda create -n $CONDA_ENV_NAME --yes --quiet python="${PYTHON_VERSION:-*}" \
129130
numpy="${NUMPY_VERSION:-*}" scipy="${SCIPY_VERSION:-*}" \
130131
cython="${CYTHON_VERSION:-*}" pytest coverage \
131132
matplotlib="${MATPLOTLIB_VERSION:-*}" sphinx=2.1.2 pillow \
132133
scikit-image="${SCIKIT_IMAGE_VERSION:-*}" pandas="${PANDAS_VERSION:-*}" \
133-
joblib memory_profiler
134+
joblib memory_profiler packaging
134135

135136
source activate testenv
136137
pip install sphinx-gallery==0.3.1

doc/conf.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import os
1717
import warnings
1818
import re
19+
from packaging.version import parse
1920

2021
# If extensions (or modules to document with autodoc) are in another
2122
# directory, add these directories to sys.path here. If the directory
@@ -85,7 +86,7 @@
8586
#
8687
# The short X.Y version.
8788
import sklearn
88-
version = sklearn.__version__
89+
version = parse(sklearn.__version__).base_version
8990
# The full version, including alpha/beta/rc tags.
9091
release = sklearn.__version__
9192

@@ -245,17 +246,16 @@
245246
'joblib': ('https://joblib.readthedocs.io/en/latest/', None),
246247
}
247248

248-
if 'dev' in version:
249+
v = parse(release)
250+
if v.release is None:
251+
raise ValueError(
252+
'Ill-formed version: {!r}. Version should follow '
253+
'PEP440'.format(version))
254+
255+
if v.is_devrelease:
249256
binder_branch = 'master'
250257
else:
251-
match = re.match(r'^(\d+)\.(\d+)(?:\.\d+)?$', version)
252-
if match is None:
253-
raise ValueError(
254-
'Ill-formed version: {!r}. Expected either '
255-
"a version containing 'dev' "
256-
'or a version like X.Y or X.Y.Z.'.format(version))
257-
258-
major, minor = match.groups()
258+
major, minor = v.release[:2]
259259
binder_branch = '{}.{}.X'.format(major, minor)
260260

261261

doc/developers/contributing.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,9 +537,12 @@ Building the documentation
537537
First, make sure you have :ref:`properly installed <install_bleeding_edge>`
538538
the development version.
539539

540+
..
541+
packaging is not needed once setuptools starts shipping packaging>=17.0
542+
540543
Building the documentation requires installing some additional packages::
541544

542-
pip install sphinx sphinx-gallery numpydoc matplotlib Pillow pandas scikit-image
545+
pip install sphinx sphinx-gallery numpydoc matplotlib Pillow pandas scikit-image packaging
543546

544547
To build the documentation, you need to be in the ``doc`` folder::
545548

0 commit comments

Comments
 (0)
0