diff --git a/setup.py b/setup.py index 64edb62..d4415eb 100644 --- a/setup.py +++ b/setup.py @@ -3,6 +3,8 @@ from setuptools.command.build_ext import build_ext import sys import setuptools +__version__ = '0.0.1' + class get_pybind_include(object): """Helper class to determine the pybind11 include path @@ -22,7 +24,7 @@ class get_pybind_include(object): ext_modules = [ Extension( 'python_example', - ['py/main.cpp'], + ['src/main.cpp'], include_dirs=[ # Path to pybind11 headers get_pybind_include(), @@ -76,6 +78,7 @@ class BuildExt(build_ext): def build_extensions(self): ct = self.compiler.compiler_type opts = self.c_opts.get(ct, []) + opts.append('-DVERSION_INFO="%s"' % self.distribution.get_version()) if ct == 'unix': opts.append(cpp_flag(self.compiler)) if has_flag(self.compiler, '-fvisibility=hidden'): @@ -86,7 +89,7 @@ class BuildExt(build_ext): setup( name='python_example', - version='0.0.1', + version=__version__, author='Sylvain Corlay', author_email='sylvain.corlay@gmail.com', url='https://github.com/pybind/python_example', diff --git a/py/main.cpp b/src/main.cpp similarity index 85% rename from py/main.cpp rename to src/main.cpp index 4b7f765..d81046d 100644 --- a/py/main.cpp +++ b/src/main.cpp @@ -36,5 +36,11 @@ PYBIND11_PLUGIN(python_example) { Some other explanation about the subtract function. )pbdoc"); +#ifdef VERSION_INFO + m.attr("__version__") = py::str(VERSION_INFO); +#else + m.attr("__version__") = py::str("dev"); +#endif + return m.ptr(); }