Skip to content

Commit 0ec0792

Browse files
jorgensdjhale
andauthored
Add version depndent intersphinx mapping (#3960)
* Add version depndent intersphinx mapping * Sort import * Granular intersphinx mapping * Ruff formatting * Use importlib to get python version of program * Oneliner * Fix versioning test * Fix basix reference * Update intersphinx mapping for documentation versions * Fix syntax for dictionary entries in conf.py * Ruff fix. * Tidy. * Fix numpy version string. --------- Co-authored-by: Jack S. Hale <mail@jackhale.co.uk>
1 parent 1638853 commit 0ec0792

File tree

3 files changed

+58
-13
lines changed

3 files changed

+58
-13
lines changed

python/doc/source/conf.py

Lines changed: 51 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,15 @@
66
import os
77
import sys
88

9+
import mpi4py
10+
11+
import numpy as np
12+
import packaging
13+
14+
import basix
915
import dolfinx
16+
import ffcx
17+
import ufl
1018

1119
sys.path.insert(0, os.path.abspath("."))
1220
import jupytext_process # isort:skip
@@ -152,14 +160,50 @@
152160

153161
codeautolink_concat_default = True
154162

163+
# Could be reimplemented using packaging.version
164+
dolfinx_version = "main" if "dev0" in dolfinx.__version__ else "v" + dolfinx.__version__
165+
basix_version = "main" if "dev0" in basix.__version__ else "v" + basix.__version__
166+
ffcx_version = "main" if "dev0" in ffcx.__version__ else "v" + ffcx.__version__
167+
ufl_version = "main" if "dev0" in ufl.__version__ else ufl.__version__
168+
169+
numpy_version = packaging.version.parse(np.__version__)
170+
numpy_doc_version = f"{numpy_version.major}.{numpy_version.minor}"
171+
172+
# Note that as of late 2025 pyvista and petsc4py only have docs for the latest
173+
# releases.
155174
intersphinx_mapping = {
156-
"basix": ("https://docs.fenicsproject.org/basix/main/python/", None),
157-
"ffcx": ("https://docs.fenicsproject.org/ffcx/main/", None),
158-
"ufl": ("https://docs.fenicsproject.org/ufl/main/", None),
159-
"mpi4py": ("https://mpi4py.readthedocs.io/en/stable", None),
160-
"petsc4py": ("https://petsc.org/release/petsc4py", None),
161-
"numpy": ("https://numpy.org/doc/stable/", None),
162-
"pyvista": ("https://docs.pyvista.org/", None),
175+
"petsc4py": (
176+
"https://petsc.org/release/petsc4py",
177+
None,
178+
),
179+
"numpy": (
180+
f"https://numpy.org/doc/{numpy_doc_version}",
181+
None,
182+
),
183+
"pyvista": (
184+
"https://docs.pyvista.org",
185+
None,
186+
),
187+
"mpi4py": (
188+
f"https://mpi4py.readthedocs.io/en/{mpi4py.__version__}",
189+
None,
190+
),
191+
"dolfinx": (
192+
f"https://docs.fenicsproject.org/dolfinx/{dolfinx_version}/python",
193+
None,
194+
),
195+
"basix": (
196+
f"https://docs.fenicsproject.org/basix/{basix_version}/python",
197+
None,
198+
),
199+
"ffcx": (
200+
f"https://docs.fenicsproject.org/ffcx/{ffcx_version}",
201+
None,
202+
),
203+
"ufl": (
204+
f"https://docs.fenicsproject.org/ufl/{ufl_version}",
205+
None,
206+
),
163207
}
164208

165209
napoleon_google_docstring = True

python/dolfinx/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@
4444
has_slepc,
4545
ufcx_signature,
4646
)
47-
from dolfinx.cpp import __version__
47+
48+
from importlib.metadata import metadata
49+
50+
__version__ = metadata("fenics-dolfinx")["Version"]
4851

4952
_cpp.common.init_logging(sys.argv)
5053
del _cpp, sys

python/test/unit/common/test_version.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
1-
# Copyright (C) 2021 Chris Richardson
1+
# Copyright (C) 2021-2025 Chris Richardson, Jørgen S. Dokken
22
#
33
# This file is part of DOLFINx (https://www.fenicsproject.org)
44
#
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66

7-
from importlib.metadata import version
87

98
import dolfinx
109

1110

1211
def test_version():
1312
"""Test that installed Python version matches C++ version."""
14-
py_version = version("fenics-dolfinx")
1513
# Change any final '.dev0' to '.0'
16-
py_version = py_version.replace("dev", "")
17-
cpp_version = dolfinx.__version__
14+
py_version = dolfinx.__version__.replace("dev0", "0")
15+
cpp_version = dolfinx.cpp.__version__
1816
if py_version != cpp_version:
1917
raise RuntimeError(
2018
f"Incorrect versions. Python version: {py_version}, Core version: {cpp_version}"

0 commit comments

Comments
 (0)