Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
Fix documentation version sorting (#16)
Browse files Browse the repository at this point in the history
* Update project requirement and constraint files
* Update tox configuration to also use Python v3.11 for testing
* Update Sphinx configuration to search for git tags of format "X.Y.Z"
  • Loading branch information
rbrazinskas authored Oct 16, 2023
1 parent e606903 commit dd4a0a4
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 99 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

Version 0.3.2 (2023-10-16)
--------------------------

* Fix a bug in documentation version sorting.

Version 0.3.1 (2023-08-11)
--------------------------

Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@
}

# -- Options for sphinx_multiversion --------------------------------------------------
smv_tag_whitelist = r'^[0-9]+\.[0-9]+$' # Allow tags that match format "X.Y"
smv_tag_whitelist = r'^[0-9]+\.[0-9]+\.[0-9]+$' # Allow tags that match format "X.Y.Z"
smv_branch_whitelist = '$-' # Exclude all local branches in versions list by using unmatchable pattern
smv_remote_whitelist = '$-' # Exclude all remote branches in versions list by using unmatchable pattern
smv_released_pattern = r'^refs/tags/.*$' # Tags recognized as releases
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ classifiers = [
]
requires-python = ">=3.9, <3.12"
dependencies = [
"sphinx >= 4.5.0"
"sphinx >= 4.5.0",
"packaging >= 23.0"
]

[project.urls]
Expand Down
33 changes: 9 additions & 24 deletions requirements/base.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --no-emit-index-url --output-file=requirements/base.txt pyproject.toml requirements/constraints.txt
Expand Down Expand Up @@ -34,6 +34,13 @@ click==8.1.3
# via
# -r requirements/constraints.txt
# black
colorama==0.4.6
# via
# -r requirements/constraints.txt
# click
# pylint
# pytest
# sphinx
coverage[toml]==7.2.1
# via
# -r requirements/constraints.txt
Expand All @@ -47,10 +54,6 @@ docutils==0.17.1
# -r requirements/constraints.txt
# pydata-sphinx-theme
# sphinx
exceptiongroup==1.1.2
# via
# -r requirements/constraints.txt
# pytest
idna==3.4
# via
# -r requirements/constraints.txt
Expand All @@ -59,10 +62,6 @@ imagesize==1.4.1
# via
# -r requirements/constraints.txt
# sphinx
importlib-metadata==6.8.0
# via
# -r requirements/constraints.txt
# sphinx
iniconfig==2.0.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -101,6 +100,7 @@ packaging==23.0
# pydata-sphinx-theme
# pytest
# sphinx
# sphinx-multiversion-contrib (pyproject.toml)
pathspec==0.11.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -178,25 +178,14 @@ sphinxcontrib-serializinghtml==1.1.5
# via
# -r requirements/constraints.txt
# sphinx
tomli==2.0.1
# via
# -r requirements/constraints.txt
# black
# coverage
# mypy
# pylint
# pytest
tomlkit==0.11.6
# via
# -r requirements/constraints.txt
# pylint
typing-extensions==4.5.0
# via
# -r requirements/constraints.txt
# astroid
# black
# mypy
# pylint
urllib3==1.26.14
# via
# -r requirements/constraints.txt
Expand All @@ -205,7 +194,3 @@ wrapt==1.15.0
# via
# -r requirements/constraints.txt
# astroid
zipp==3.16.2
# via
# -r requirements/constraints.txt
# importlib-metadata
28 changes: 9 additions & 19 deletions requirements/constraints.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=test,docs --no-emit-index-url --output-file=requirements/constraints.txt pyproject.toml
Expand All @@ -20,6 +20,12 @@ charset-normalizer==3.1.0
# via requests
click==8.1.3
# via black
colorama==0.4.6
# via
# click
# pylint
# pytest
# sphinx
coverage[toml]==7.2.1
# via pytest-cov
dill==0.3.6
Expand All @@ -28,14 +34,10 @@ docutils==0.17.1
# via
# pydata-sphinx-theme
# sphinx
exceptiongroup==1.1.2
# via pytest
idna==3.4
# via requests
imagesize==1.4.1
# via sphinx
importlib-metadata==6.8.0
# via sphinx
iniconfig==2.0.0
# via pytest
isort==5.12.0
Expand All @@ -62,6 +64,7 @@ packaging==23.0
# pydata-sphinx-theme
# pytest
# sphinx
# sphinx-multiversion-contrib (pyproject.toml)
pathspec==0.11.0
# via black
platformdirs==3.1.0
Expand Down Expand Up @@ -109,24 +112,11 @@ sphinxcontrib-qthelp==1.0.3
# via sphinx
sphinxcontrib-serializinghtml==1.1.5
# via sphinx
tomli==2.0.1
# via
# black
# coverage
# mypy
# pylint
# pytest
tomlkit==0.11.6
# via pylint
typing-extensions==4.5.0
# via
# astroid
# black
# mypy
# pylint
# via mypy
urllib3==1.26.14
# via requests
wrapt==1.15.0
# via astroid
zipp==3.16.2
# via importlib-metadata
33 changes: 9 additions & 24 deletions requirements/docs.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=docs --no-emit-index-url --output-file=requirements/docs.txt pyproject.toml requirements/constraints.txt
Expand Down Expand Up @@ -34,6 +34,13 @@ click==8.1.3
# via
# -r requirements/constraints.txt
# black
colorama==0.4.6
# via
# -r requirements/constraints.txt
# click
# pylint
# pytest
# sphinx
coverage[toml]==7.2.1
# via
# -r requirements/constraints.txt
Expand All @@ -47,10 +54,6 @@ docutils==0.17.1
# -r requirements/constraints.txt
# pydata-sphinx-theme
# sphinx
exceptiongroup==1.1.2
# via
# -r requirements/constraints.txt
# pytest
idna==3.4
# via
# -r requirements/constraints.txt
Expand All @@ -59,10 +62,6 @@ imagesize==1.4.1
# via
# -r requirements/constraints.txt
# sphinx
importlib-metadata==6.8.0
# via
# -r requirements/constraints.txt
# sphinx
iniconfig==2.0.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -101,6 +100,7 @@ packaging==23.0
# pydata-sphinx-theme
# pytest
# sphinx
# sphinx-multiversion-contrib (pyproject.toml)
pathspec==0.11.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -180,25 +180,14 @@ sphinxcontrib-serializinghtml==1.1.5
# via
# -r requirements/constraints.txt
# sphinx
tomli==2.0.1
# via
# -r requirements/constraints.txt
# black
# coverage
# mypy
# pylint
# pytest
tomlkit==0.11.6
# via
# -r requirements/constraints.txt
# pylint
typing-extensions==4.5.0
# via
# -r requirements/constraints.txt
# astroid
# black
# mypy
# pylint
urllib3==1.26.14
# via
# -r requirements/constraints.txt
Expand All @@ -207,7 +196,3 @@ wrapt==1.15.0
# via
# -r requirements/constraints.txt
# astroid
zipp==3.16.2
# via
# -r requirements/constraints.txt
# importlib-metadata
33 changes: 9 additions & 24 deletions requirements/test.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# This file is autogenerated by pip-compile with Python 3.9
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile --extra=test --no-emit-index-url --output-file=requirements/test.txt pyproject.toml requirements/constraints.txt
Expand Down Expand Up @@ -36,6 +36,13 @@ click==8.1.3
# via
# -r requirements/constraints.txt
# black
colorama==0.4.6
# via
# -r requirements/constraints.txt
# click
# pylint
# pytest
# sphinx
coverage[toml]==7.2.1
# via
# -r requirements/constraints.txt
Expand All @@ -49,10 +56,6 @@ docutils==0.17.1
# -r requirements/constraints.txt
# pydata-sphinx-theme
# sphinx
exceptiongroup==1.1.2
# via
# -r requirements/constraints.txt
# pytest
idna==3.4
# via
# -r requirements/constraints.txt
Expand All @@ -61,10 +64,6 @@ imagesize==1.4.1
# via
# -r requirements/constraints.txt
# sphinx
importlib-metadata==6.8.0
# via
# -r requirements/constraints.txt
# sphinx
iniconfig==2.0.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -106,6 +105,7 @@ packaging==23.0
# pydata-sphinx-theme
# pytest
# sphinx
# sphinx-multiversion-contrib (pyproject.toml)
pathspec==0.11.0
# via
# -r requirements/constraints.txt
Expand Down Expand Up @@ -188,25 +188,14 @@ sphinxcontrib-serializinghtml==1.1.5
# via
# -r requirements/constraints.txt
# sphinx
tomli==2.0.1
# via
# -r requirements/constraints.txt
# black
# coverage
# mypy
# pylint
# pytest
tomlkit==0.11.6
# via
# -r requirements/constraints.txt
# pylint
typing-extensions==4.5.0
# via
# -r requirements/constraints.txt
# astroid
# black
# mypy
# pylint
urllib3==1.26.14
# via
# -r requirements/constraints.txt
Expand All @@ -215,7 +204,3 @@ wrapt==1.15.0
# via
# -r requirements/constraints.txt
# astroid
zipp==3.16.2
# via
# -r requirements/constraints.txt
# importlib-metadata
9 changes: 4 additions & 5 deletions src/sphinx_multiversion/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import tempfile
from typing import Any, Union

from packaging.version import parse
from sphinx.config import Config as sphinx_config
from sphinx.errors import ConfigError as sphinx_config_error
from sphinx.project import Project as sphinx_project
Expand Down Expand Up @@ -284,11 +285,9 @@ def main( # pylint: disable=too-many-branches,too-many-locals,too-many-statemen
else:
gitrefs = sorted(gitrefs, key=lambda x: (x.is_remote, *x))

# TODO: Refactor the line to enable type checking with mypy
# git refs by default are just strings, and we need to extract symver to be able to reasonably sort versions
# fmt: off
gitrefs = sorted(gitrefs, key=lambda x: float(re.match(config.smv_symver_pattern, x.refname).group(1))) # type: ignore # pylint: disable=line-too-long
# fmt: on
# git refs by default are just strings (e.g. "refs/tags/10.11"), and we need
# to extract semver to be able to sort versions
gitrefs.sort(key=lambda gitref: parse(gitref.refname.split("/")[-1]))

logger = logging.getLogger(__name__)
released_versions = []
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ commands =
python -m piptools compile -q --no-emit-index-url --extra=test --output-file=requirements/test.txt requirements/constraints.txt pyproject.toml {posargs}
python -m piptools compile -q --no-emit-index-url --extra=docs --output-file=requirements/docs.txt requirements/constraints.txt pyproject.toml {posargs}

[testenv:py{39,310}]
[testenv:py{39,310,311}]
description =
Run automated tests.
deps =
Expand Down

0 comments on commit dd4a0a4

Please sign in to comment.