Skip to content

Commit 890fcad

Browse files
authored
More robust version check test (#3965)
* More robust version number handling. * Fix typo in docstring. * Refinements.
1 parent a214beb commit 890fcad

File tree

3 files changed

+22
-11
lines changed

3 files changed

+22
-11
lines changed

python/dolfinx/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545
ufcx_signature,
4646
)
4747

48-
from importlib.metadata import metadata
48+
from importlib.metadata import version
4949

50-
__version__ = metadata("fenics-dolfinx")["Version"]
50+
__version__ = version("fenics-dolfinx")
5151

5252
_cpp.common.init_logging(sys.argv)
5353
del _cpp, sys

python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ docs = [
4545
lint = ["ruff>=0.2.0"]
4646
optional = ["numba", "pyamg"]
4747
petsc4py = ["petsc4py"]
48-
test = ["matplotlib", "networkx", "pytest", "scipy", "fenics-dolfinx[optional]"]
48+
test = ["matplotlib", "networkx", "packaging", "pytest", "scipy", "fenics-dolfinx[optional]"]
4949
ci = [
5050
"mypy",
5151
"pytest-xdist",

python/test/unit/common/test_version.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,27 @@
44
#
55
# SPDX-License-Identifier: LGPL-3.0-or-later
66

7+
from packaging.version import parse
78

89
import dolfinx
910

1011

1112
def test_version():
12-
"""Test that installed Python version matches C++ version."""
13-
# Change any final '.dev0' to '.0'
14-
py_version = dolfinx.__version__.replace("dev0", "0")
15-
cpp_version = dolfinx.cpp.__version__
16-
if py_version != cpp_version:
17-
raise RuntimeError(
18-
f"Incorrect versions. Python version: {py_version}, Core version: {cpp_version}"
19-
)
13+
"""Test that installed Python version matches C++ version.
14+
15+
Python DOLFINx follows `major.minor.micro` with the append of `.devx`
16+
and `.postx` denoting development and postrelease, respectively.
17+
18+
C++ DOLFINx follows `major.minor.micro` with a development denoted
19+
`major.minor.micro.0`. postrelease cannot be reflected in C++,
20+
any changes to the C++ code should bump micro.
21+
"""
22+
cpp_version = parse(dolfinx.cpp.__version__)
23+
python_version = parse(dolfinx.__version__)
24+
25+
assert cpp_version.major == python_version.major
26+
assert cpp_version.minor == python_version.minor
27+
assert cpp_version.micro == python_version.micro
28+
29+
cpp_is_devrelease = True if len(cpp_version.release) == 4 else False
30+
assert cpp_is_devrelease == python_version.is_devrelease

0 commit comments

Comments
 (0)