Skip to content

Commit ee6126f

Browse files
committed
fix: use universal way of passing version
1 parent c06d5e0 commit ee6126f

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

setup.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313

1414
__version__ = "0.0.1"
1515

16-
# Windows strips quotes
17-
wrap = r'\"{}\"' if sys.platform.startswith("win") else '"{}"'
18-
1916
# The main interface is through Pybind11Extension.
2017
# * You can add cxx_std=11/14/17, and then build_ext can be removed.
2118
# * You can set include_pybind11=false to add the include directory yourself,
@@ -29,7 +26,7 @@
2926
Pybind11Extension("python_example",
3027
["src/main.cpp"],
3128
# Example: passing in the version to the compiled code
32-
define_macros = [('VERSION_INFO', wrap.format(__version__))],
29+
define_macros = [('VERSION_INFO', __version__)],
3330
),
3431
]
3532

src/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#include <pybind11/pybind11.h>
22

3+
#define STRINGIFY(x) #x
4+
#define MACRO_STRINGIFY(x) STRINGIFY(x)
5+
36
int add(int i, int j) {
47
return i + j;
58
}
@@ -33,7 +36,7 @@ PYBIND11_MODULE(python_example, m) {
3336
)pbdoc");
3437

3538
#ifdef VERSION_INFO
36-
m.attr("__version__") = VERSION_INFO;
39+
m.attr("__version__") = MACRO_STRINGIFY(VERSION_INFO);
3740
#else
3841
m.attr("__version__") = "dev";
3942
#endif

0 commit comments

Comments
 (0)