Skip to content

Commit 2a5ba8f

Browse files
authored
expose version number of PartMC and pybind11 via ppmc.__versions_of_build_time_dependencies__ (#310)
1 parent 4c8d153 commit 2a5ba8f

File tree

6 files changed

+61
-7
lines changed

6 files changed

+61
-7
lines changed

CMakeLists.txt

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,12 @@ target_include_directories(camplib PRIVATE
310310
${SUNDIALS_SOURCE_DIR}/include
311311
${CMAKE_BINARY_DIR}/include
312312
)
313+
file(MAKE_DIRECTORY ${CMAKE_BINARY_DIR}/include/camp)
314+
execute_process(
315+
COMMAND ${PYTHON_EXECUTABLE} "-c" "import sys; print(''.join([line.replace(')','').replace('set(','#define ').replace('PACKAGE_', 'CAMP_') for line in sys.stdin if line.startswith('set(PACKAGE_VERSION')]))"
316+
INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/camp/CMakeLists.txt
317+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/include/camp/version.h
318+
)
313319

314320
### netCDF #########################################################################################
315321

@@ -428,11 +434,13 @@ string(CONCAT
428434
"print(''.join([f'#define {line.split()[3]} {line.split()[5]}\\n' for line in sys.stdin if 'parameter ::' in line]))"
429435
)
430436
include(CheckFunctionExists)
431-
execute_process(
432-
COMMAND ${PYTHON_EXECUTABLE} "-c" "${cmd}"
433-
INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/partmc/src/aero_data.F90
434-
OUTPUT_FILE ${CMAKE_BINARY_DIR}/include/aero_data_parameters.hpp
435-
)
437+
foreach(file aero_data;output)
438+
execute_process(
439+
COMMAND ${PYTHON_EXECUTABLE} "-c" "${cmd}"
440+
INPUT_FILE ${CMAKE_SOURCE_DIR}/gitmodules/partmc/src/${file}.F90
441+
OUTPUT_FILE ${CMAKE_BINARY_DIR}/include/${file}_parameters.hpp
442+
)
443+
endforeach()
436444

437445
target_include_directories(partmclib PRIVATE
438446
${SUNDIALS_SOURCE_DIR}/include

MANIFEST.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ graft gitmodules/partmc/src
33
include gitmodules/partmc/src/condense_solver.c
44

55
include gitmodules/camp/COPYING
6+
include gitmodules/camp/CMakeLists.txt
67
graft gitmodules/camp/src
78

89
include gitmodules/json-fortran/LICENSE

PyPartMC/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,8 @@ def __build_extension_env():
4343
with __build_extension_env():
4444
import _PyPartMC
4545
from _PyPartMC import *
46-
from _PyPartMC import __all__, __version__ # pylint: disable=no-name-in-module
46+
from _PyPartMC import ( # pylint: disable=no-name-in-module
47+
__all__,
48+
__version__,
49+
__versions_of_build_time_dependencies__,
50+
)

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,13 @@ flowchart TD
278278
- Q: Why some of the constructors expect data to be passed as **lists of single-entry dictionaries** instead of multi-element dictionaries?
279279
A: This is intentional and related with PartMC relying on the order of elements within spec-file input; while Python dictionaries preserve ordering (insertion order), JSON format does not, and we intend to make these data structures safe to be [de]serialized using JSON.
280280

281+
- Q: How to check the version of PartMC that PyPartMC was compiled against?
282+
A: Version numbers of compile-time dependencies of PyPartMC, including PartMC, can be accessed as follows:
283+
```Python
284+
import PyPartMC
285+
PyPartMC.__versions_of_build_time_dependencies__['PartMC']
286+
```
287+
281288
## Troubleshooting
282289

283290
#### Common installation issues

src/pypartmc.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "nlohmann/json.hpp"
99
#include "pybind11_json/pybind11_json.hpp"
1010
#include "pybind11/complex.h"
11+
#include "sundials/sundials_config.h"
12+
#include "camp/version.h"
1113

1214
#include "util.hpp"
1315
#include "rand.hpp"
@@ -25,6 +27,7 @@
2527
#include "camp_core.hpp"
2628
#include "photolysis.hpp"
2729
#include "output.hpp"
30+
#include "output_parameters.hpp"
2831

2932
#define STRINGIFY(x) #x
3033
#define MACRO_STRINGIFY(x) STRINGIFY(x)
@@ -490,6 +493,16 @@ PYBIND11_MODULE(_PyPartMC, m) {
490493

491494
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
492495

496+
auto vobtd = py::dict();
497+
vobtd["pybind11"] = MACRO_STRINGIFY(PYBIND11_VERSION_MAJOR) "." MACRO_STRINGIFY(PYBIND11_VERSION_MINOR) "." MACRO_STRINGIFY(PYBIND11_VERSION_PATCH);
498+
vobtd["PartMC"] = PARTMC_VERSION;
499+
vobtd["SUNDIALS"] = SUNDIALS_VERSION;
500+
vobtd["CAMP"] = CAMP_VERSION;
501+
// TODO #164
502+
// - expose git hashes?
503+
// - more submodules (netCDF, ...)
504+
m.attr("__versions_of_build_time_dependencies__") = vobtd;
505+
493506
m.attr("__all__") = py::make_tuple(
494507
"__version__",
495508
"AeroData",

tests/test_version.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@
44
# Authors: https://github.com/open-atmos/PyPartMC/graphs/contributors #
55
####################################################################################################
66

7+
import pytest
8+
79
import PyPartMC as ppmc
810

911

1012
def test_version():
11-
print(ppmc.__version__)
13+
assert 3 < len(ppmc.__version__) < 20
14+
15+
16+
@pytest.mark.parametrize(
17+
"pkg",
18+
(
19+
"PartMC",
20+
"pybind11",
21+
"CAMP",
22+
"SUNDIALS",
23+
),
24+
)
25+
def test_versions_of_build_time_dependencies(pkg):
26+
sut = ppmc.__versions_of_build_time_dependencies__
27+
assert 3 < len(sut[pkg]) < 20
28+
assert '"' not in sut[pkg]
29+
30+
31+
def test_versions_of_build_time_dependencies_printable():
32+
print(ppmc.__versions_of_build_time_dependencies__)

0 commit comments

Comments
 (0)