aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt6
-rw-r--r--Python/pywarpx/__init__.py10
-rwxr-xr-xPython/pywarpx/_libwarpx.py5
-rw-r--r--Source/Python/pyWarpX.cpp10
-rw-r--r--setup.py10
5 files changed, 27 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 81a1f2da1..8f10049cb 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -126,6 +126,9 @@ option(WarpX_PYTHON_IPO
ON
)
+set(pyWarpX_VERSION_INFO "" CACHE STRING
+ "PEP-440 conformant version (set by distutils)")
+
# enforce consistency of dependent options
if(WarpX_APP OR WarpX_PYTHON)
set(WarpX_LIB ON CACHE STRING "Build WarpX as a library" FORCE)
@@ -497,7 +500,7 @@ foreach(D IN LISTS WarpX_DIMS)
target_compile_definitions(ablastr_${SD} PUBLIC WARPX_USE_PSATD)
endif()
- if(WarpX_PYTHON)
+ if(WarpX_PYTHON AND pyWarpX_VERSION_INFO)
# for module __version__
target_compile_definitions(pyWarpX_${SD} PRIVATE
PYWARPX_VERSION_INFO=${pyWarpX_VERSION_INFO})
@@ -534,6 +537,7 @@ set_cxx_warnings()
# Generate Configuration and .pc Files ########################################
#
get_source_version(WarpX_${WarpX_DIMS_LAST} ${WarpX_SOURCE_DIR})
+set(WarpX_GIT_VERSION ${WarpX_${WarpX_DIMS_LAST}_GIT_VERSION})
configure_file(
${WarpX_SOURCE_DIR}/Source/Utils/WarpXVersion.H.in
${WarpX_BINARY_DIR}/Source/Utils/WarpXVersion.H
diff --git a/Python/pywarpx/__init__.py b/Python/pywarpx/__init__.py
index f0f4177d4..8b57f60fb 100644
--- a/Python/pywarpx/__init__.py
+++ b/Python/pywarpx/__init__.py
@@ -40,10 +40,16 @@ from .WarpX import warpx
from ._libwarpx import libwarpx
# This is a circular import and must happen after the import of libwarpx
-from . import picmi # isort:skip
+from . import picmi # isort:skip
+
+# intentionally query the value - only set once sim dimension is known
+def __getattr__(name):
+ # https://stackoverflow.com/a/57263518/2719194
+ if name == '__version__':
+ return libwarpx.__version__
+ raise AttributeError(f"module '{__name__}' has no attribute '{name}'")
# TODO
-#__version__ = cxx.__version__
#__doc__ = cxx.__doc__
#__license__ = cxx.__license__
#__author__ = cxx.__author__
diff --git a/Python/pywarpx/_libwarpx.py b/Python/pywarpx/_libwarpx.py
index 592459132..615d9fd66 100755
--- a/Python/pywarpx/_libwarpx.py
+++ b/Python/pywarpx/_libwarpx.py
@@ -33,6 +33,9 @@ class LibWarpX():
self.initialized = False
atexit.register(self.finalize)
+ # set once libwarpx_so is loaded
+ self.__version__ = None
+
def __getattr__(self, attribute):
if attribute == 'libwarpx_so':
# If the 'libwarpx_so' is referenced, load it.
@@ -109,6 +112,8 @@ class LibWarpX():
except ImportError:
raise Exception(f"Dimensionality '{self.geometry_dim}' was not compiled in this Python install. Please recompile with -DWarpX_DIMS={_dims}")
+ self.__version__ = self.libwarpx_so.__version__
+
def getNProcs(self):
'''
diff --git a/Source/Python/pyWarpX.cpp b/Source/Python/pyWarpX.cpp
index 37d910f03..31c8e6ec6 100644
--- a/Source/Python/pyWarpX.cpp
+++ b/Source/Python/pyWarpX.cpp
@@ -1,4 +1,4 @@
-/* Copyright 2021-2022 The ImpactX Community
+/* Copyright 2021-2023 The WarpX Community
*
* Authors: Axel Huebl
* License: BSD-3-Clause-LBNL
@@ -8,6 +8,7 @@
#include <WarpX.H> // todo: move this out to Python/WarpX.cpp
#include <Utils/WarpXUtil.H> // todo: move to its own Python/Utils.cpp
+#include <Utils/WarpXVersion.H>
#include <Initialization/WarpXAMReXInit.H>
#define STRINGIFY(x) #x
@@ -71,10 +72,11 @@ PYBIND11_MODULE(PYWARPX_MODULE_NAME, m) {
// API runtime version
// note PEP-440 syntax: x.y.zaN but x.y.z.devN
-#ifdef PYIMPACTX_VERSION_INFO
- m.attr("__version__") = MACRO_STRINGIFY(PYIMPACTX_VERSION_INFO);
+#ifdef PYWARPX_VERSION_INFO
+ m.attr("__version__") = MACRO_STRINGIFY(PYWARPX_VERSION_INFO);
#else
- m.attr("__version__") = "dev";
+ // note: not necessarily PEP-440 compliant
+ m.attr("__version__") = WarpX::Version();
#endif
// authors
diff --git a/setup.py b/setup.py
index 42ec635f6..8d14aaa09 100644
--- a/setup.py
+++ b/setup.py
@@ -108,6 +108,8 @@ class CMakeBuild(build_ext):
'-DWarpX_QED_TABLE_GEN:BOOL=' + WARPX_QED_TABLE_GEN,
## dependency control (developers & package managers)
'-DWarpX_amrex_internal=' + WARPX_AMREX_INTERNAL,
+ # PEP-440 conformant version from package
+ "-DpyWarpX_VERSION_INFO=" + self.distribution.get_version(),
# see PICSAR and openPMD below
## static/shared libs
'-DBUILD_SHARED_LIBS:BOOL=' + BUILD_SHARED_LIBS,
@@ -173,17 +175,11 @@ class CMakeBuild(build_ext):
build_args += ['--parallel', BUILD_PARALLEL]
- env = os.environ.copy()
- env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(
- env.get('CXXFLAGS', ''),
- self.distribution.get_version()
- )
build_dir = os.path.join(self.build_temp, dims)
os.makedirs(build_dir, exist_ok=True)
subprocess.check_call(
['cmake', ext.sourcedir] + cmake_args,
- cwd=build_dir,
- env=env
+ cwd=build_dir
)
subprocess.check_call(
['cmake', '--build', '.'] + build_args,