Skip to content

Commit 4aea3d2

Browse files
authored
Runtime verification of sphinx and jinja2 versions (#381)
* Add runtime sphinx/jinja version checker. * Remove jinja2 pin. * modify CI to account for removed pin.
1 parent 25e626d commit 4aea3d2

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

.github/workflows/test.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@ jobs:
2323
python-version: ${{ matrix.python-version }}
2424

2525
- name: Setup environment
26-
run: |
27-
python -m venv venv
28-
source venv/bin/activate
29-
30-
- name: Install
3126
run: |
3227
python -m pip install --upgrade pip wheel setuptools
3328
python -m pip install -r requirements/test.txt -r doc/requirements.txt
3429
python -m pip install codecov
3530
python -m pip install ${{ matrix.sphinx-version }}
31+
python -m pip list
32+
33+
- name: Downgrade Jinja2 for sphinx<4
34+
if: (${{ matrix.sphinx-version }} == 'sphinx==1.8.0') ||
35+
(${{ matrix.sphinx-version }} == 'sphinx==2.1')
36+
run: python -m pip install jinja2==3.0.3
37+
38+
- name: Install
39+
run: |
3640
python -m pip install .
3741
pip list
3842

numpydoc/__init__.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,31 @@
55
__version__ = '1.2.2.dev0'
66

77

8+
def _verify_sphinx_jinja():
9+
"""Ensure sphinx and jinja versions are compatible.
10+
11+
Jinja2>=3.1 requires Sphinx>=4.0.2. Raises exception if this condition is
12+
not met.
13+
14+
TODO: This check can be removed when the minimum supported sphinx version
15+
for numpydoc sphinx>=4.0.2
16+
"""
17+
import sphinx, jinja2
18+
from packaging import version
19+
20+
if version.parse(sphinx.__version__) <= version.parse("4.0.2"):
21+
if version.parse(jinja2.__version__) >= version.parse("3.1"):
22+
from sphinx.errors import VersionRequirementError
23+
raise VersionRequirementError(
24+
"\n\nSphinx<4.0.2 is incompatible with Jinja2>=3.1.\n"
25+
"If you wish to continue using sphinx<4.0.2 you need to pin "
26+
"Jinja2<3.1."
27+
)
28+
29+
30+
_verify_sphinx_jinja()
31+
32+
833
def setup(app, *args, **kwargs):
934
from .numpydoc import setup
1035
return setup(app, *args, **kwargs)

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def read(fname):
4343
author_email="[email protected]",
4444
url="https://numpydoc.readthedocs.io",
4545
license="BSD",
46-
install_requires=["sphinx>=1.8", 'Jinja2>=2.10,<3.1'],
46+
install_requires=["sphinx>=1.8", 'Jinja2>=2.10'],
4747
python_requires=">=3.7",
4848
extras_require={
4949
"testing": [

0 commit comments

Comments
 (0)