Skip to content

Commit 8d64edb

Browse files
authored
Python: impactx.__version__ (#494)
* Test: `impactx.__version__` Make sure this is not empty. * Fix: `impactx.__version__` Set a default value and fallback.
1 parent c0a0fa2 commit 8d64edb

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ option(ImpactX_amrex_internal "Download & build AMReX" ON)
8080
option(ImpactX_openpmd_internal "Download & build openPMD-api" ON)
8181
option(ImpactX_pyamrex_internal "Download & build pyAMReX" ON)
8282

83-
set(pyImpactX_VERSION_INFO "" CACHE STRING
83+
set(pyImpactX_VERSION_INFO "${ImpactX_VERSION}" CACHE STRING
8484
"PEP-440 conformant version (set by setup.py)")
8585

8686
# change the default build type to Release (or RelWithDebInfo) instead of Debug

src/python/pyImpactX.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
#include <ImpactX.H>
99
#include <particles/elements/All.H>
1010

11+
#ifndef PYIMPACTX_VERSION_INFO
12+
# include <ImpactXVersion.H>
13+
#endif
14+
1115
#define STRINGIFY(x) #x
1216
#define MACRO_STRINGIFY(x) STRINGIFY(x)
1317

@@ -25,7 +29,7 @@ void init_transformation(py::module&);
2529

2630
PYBIND11_MODULE(impactx_pybind, m) {
2731
// make sure AMReX types are known
28-
py::module::import("amrex.space3d");
32+
auto amr = py::module::import("amrex.space3d");
2933

3034
m.doc() = R"pbdoc(
3135
impactx_pybind
@@ -47,12 +51,16 @@ PYBIND11_MODULE(impactx_pybind, m) {
4751
init_transformation(m);
4852
init_ImpactX(m);
4953

54+
// expose our amrex module
55+
m.attr("amr") = amr;
56+
5057
// API runtime version
5158
// note PEP-440 syntax: x.y.zaN but x.y.z.devN
5259
#ifdef PYIMPACTX_VERSION_INFO
5360
m.attr("__version__") = MACRO_STRINGIFY(PYIMPACTX_VERSION_INFO);
5461
#else
55-
m.attr("__version__") = "dev";
62+
// note: not necessarily PEP-440 compliant
63+
m.attr("__version__") = IMPACTX_VERSION;
5664
#endif
5765

5866
// authors

tests/python/test_impactx.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,18 @@
1212
import pytest
1313

1414
import amrex.space3d as amr
15+
import impactx
1516
from impactx import ImpactX, RefPart, distribution, elements
1617

1718

19+
def test_impactx_module():
20+
"""
21+
Tests the basic modules we provide.
22+
"""
23+
print(f"version={impactx.__version__}")
24+
assert impactx.__version__ # version must not be empty
25+
26+
1827
def test_impactx_fodo_file():
1928
"""
2029
This tests an equivalent to main.cpp in C++

0 commit comments

Comments
 (0)