Skip to content

Commit ea9673e

Browse files
committed
[python-nb] Add exposeVersion()
1 parent a6f9773 commit ea9673e

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

python-nb/coal.cc

+44-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,47 @@
11
/// Copyright 2025 INRIA
22
#include <nanobind/nanobind.h>
3+
#include "coal/config.hh"
34

4-
NB_MODULE(COAL_PYTHON_LIBNAME, m) {}
5+
namespace nb = nanobind;
6+
using namespace nb::literals;
7+
8+
inline constexpr bool checkVersionAtLeast(int major, int minor, int patch) {
9+
return COAL_VERSION_AT_LEAST(major, minor, patch);
10+
}
11+
12+
inline constexpr bool checkVersionAtMost(int major, int minor, int patch) {
13+
return COAL_VERSION_AT_MOST(major, minor, patch);
14+
}
15+
16+
void exposeVersion(nb::module_ &m) {
17+
m.attr("__version__") = COAL_VERSION;
18+
m.attr("COAL_MAJOR_VERSION") = COAL_MAJOR_VERSION;
19+
m.attr("COAL_MINOR_VERSION") = COAL_MINOR_VERSION;
20+
m.attr("COAL_PATCH_VERSION") = COAL_PATCH_VERSION;
21+
22+
m.attr("WITH_QHULL") =
23+
#if COAL_HAS_QHULL
24+
true;
25+
#else
26+
false;
27+
#endif
28+
29+
m.attr("WITH_OCTOMAP") =
30+
#if COAL_HAS_OCTOMAP
31+
true;
32+
#else
33+
false;
34+
#endif
35+
36+
m.def("checkVersionAtLeast", &checkVersionAtLeast, "major"_a, "minor"_a,
37+
"patch"_a,
38+
"Checks if the current version of coal is at least the version "
39+
"provided by the input arguments.");
40+
41+
m.def("checkVersionAtMost", &checkVersionAtMost, "major"_a, "minor"_a,
42+
"patch"_a,
43+
"Checks if the current version of coal is at most the version provided "
44+
"by the input arguments.");
45+
}
46+
47+
NB_MODULE(COAL_PYTHON_LIBNAME, m) { exposeVersion(m); }

0 commit comments

Comments
 (0)