Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | |
Dean Moldovan | a0c1ccf | 2016-08-12 13:50:00 +0200 | [diff] [blame] | 3 | # Setup script for PyPI; use CMakeFile.txt to build extension modules |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 4 | |
| 5 | from setuptools import setup |
Dean Moldovan | 1913f25 | 2017-08-23 14:20:53 +0200 | [diff] [blame] | 6 | from distutils.command.install_headers import install_headers |
Isuru Fernando | 3735249 | 2019-11-28 01:59:23 -0600 | [diff] [blame] | 7 | from distutils.command.build_py import build_py |
Wenzel Jakob | 4f972c0 | 2016-03-01 10:36:10 +0100 | [diff] [blame] | 8 | from pybind11 import __version__ |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 9 | import os |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 10 | |
Isuru Fernando | 3735249 | 2019-11-28 01:59:23 -0600 | [diff] [blame] | 11 | package_data = [ |
| 12 | 'include/pybind11/detail/class.h', |
| 13 | 'include/pybind11/detail/common.h', |
| 14 | 'include/pybind11/detail/descr.h', |
| 15 | 'include/pybind11/detail/init.h', |
| 16 | 'include/pybind11/detail/internals.h', |
| 17 | 'include/pybind11/detail/typeid.h', |
| 18 | 'include/pybind11/attr.h', |
| 19 | 'include/pybind11/buffer_info.h', |
| 20 | 'include/pybind11/cast.h', |
| 21 | 'include/pybind11/chrono.h', |
| 22 | 'include/pybind11/common.h', |
| 23 | 'include/pybind11/complex.h', |
| 24 | 'include/pybind11/eigen.h', |
| 25 | 'include/pybind11/embed.h', |
| 26 | 'include/pybind11/eval.h', |
| 27 | 'include/pybind11/functional.h', |
| 28 | 'include/pybind11/iostream.h', |
| 29 | 'include/pybind11/numpy.h', |
| 30 | 'include/pybind11/operators.h', |
| 31 | 'include/pybind11/options.h', |
| 32 | 'include/pybind11/pybind11.h', |
| 33 | 'include/pybind11/pytypes.h', |
| 34 | 'include/pybind11/stl.h', |
| 35 | 'include/pybind11/stl_bind.h', |
| 36 | ] |
| 37 | |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 38 | # Prevent installation of pybind11 headers by setting |
| 39 | # PYBIND11_USE_CMAKE. |
| 40 | if os.environ.get('PYBIND11_USE_CMAKE'): |
| 41 | headers = [] |
| 42 | else: |
Isuru Fernando | 3735249 | 2019-11-28 01:59:23 -0600 | [diff] [blame] | 43 | headers = package_data |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 44 | |
Dean Moldovan | 1913f25 | 2017-08-23 14:20:53 +0200 | [diff] [blame] | 45 | |
| 46 | class InstallHeaders(install_headers): |
| 47 | """Use custom header installer because the default one flattens subdirectories""" |
| 48 | def run(self): |
| 49 | if not self.distribution.headers: |
| 50 | return |
| 51 | |
| 52 | for header in self.distribution.headers: |
| 53 | subdir = os.path.dirname(os.path.relpath(header, 'include/pybind11')) |
| 54 | install_dir = os.path.join(self.install_dir, subdir) |
| 55 | self.mkpath(install_dir) |
| 56 | |
| 57 | (out, _) = self.copy_file(header, install_dir) |
| 58 | self.outfiles.append(out) |
| 59 | |
| 60 | |
Isuru Fernando | 3735249 | 2019-11-28 01:59:23 -0600 | [diff] [blame] | 61 | # Install the headers inside the package as well |
| 62 | class BuildPy(build_py): |
| 63 | def build_package_data(self): |
| 64 | build_py.build_package_data(self) |
| 65 | for header in package_data: |
| 66 | target = os.path.join(self.build_lib, 'pybind11', header) |
| 67 | self.mkpath(os.path.dirname(target)) |
| 68 | self.copy_file(header, target, preserve_mode=False) |
| 69 | |
| 70 | |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 71 | setup( |
| 72 | name='pybind11', |
| 73 | version=__version__, |
| 74 | description='Seamless operability between C++11 and Python', |
| 75 | author='Wenzel Jakob', |
| 76 | author_email='wenzel.jakob@epfl.ch', |
Maciek Starzyk | 9b02856 | 2018-06-02 20:21:19 +0200 | [diff] [blame] | 77 | url='https://github.com/pybind/pybind11', |
| 78 | download_url='https://github.com/pybind/pybind11/tarball/v' + __version__, |
Sylvain Corlay | d5ce82b | 2017-02-14 13:16:14 +0100 | [diff] [blame] | 79 | packages=['pybind11'], |
| 80 | license='BSD', |
| 81 | headers=headers, |
Isuru Fernando | 3735249 | 2019-11-28 01:59:23 -0600 | [diff] [blame] | 82 | zip_safe=False, |
| 83 | cmdclass=dict(install_headers=InstallHeaders, build_py=BuildPy), |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 84 | classifiers=[ |
| 85 | 'Development Status :: 5 - Production/Stable', |
| 86 | 'Intended Audience :: Developers', |
| 87 | 'Topic :: Software Development :: Libraries :: Python Modules', |
| 88 | 'Topic :: Utilities', |
| 89 | 'Programming Language :: C++', |
| 90 | 'Programming Language :: Python :: 2.7', |
| 91 | 'Programming Language :: Python :: 3', |
| 92 | 'Programming Language :: Python :: 3.2', |
| 93 | 'Programming Language :: Python :: 3.3', |
| 94 | 'Programming Language :: Python :: 3.4', |
Wenzel Jakob | b456ec7 | 2015-10-15 22:43:55 +0200 | [diff] [blame] | 95 | 'Programming Language :: Python :: 3.5', |
Wenzel Jakob | 2723a38 | 2017-01-01 17:14:27 +0100 | [diff] [blame] | 96 | 'Programming Language :: Python :: 3.6', |
| 97 | 'License :: OSI Approved :: BSD License' |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 98 | ], |
| 99 | keywords='C++11, Python bindings', |
Wenzel Jakob | 2723a38 | 2017-01-01 17:14:27 +0100 | [diff] [blame] | 100 | long_description="""pybind11 is a lightweight header-only library that |
| 101 | exposes C++ types in Python and vice versa, mainly to create Python bindings of |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 102 | existing C++ code. Its goals and syntax are similar to the excellent |
Wenzel Jakob | 2723a38 | 2017-01-01 17:14:27 +0100 | [diff] [blame] | 103 | Boost.Python by David Abrahams: to minimize boilerplate code in traditional |
| 104 | extension modules by inferring type information using compile-time |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 105 | introspection. |
| 106 | |
Wenzel Jakob | 0f294e2 | 2017-01-04 15:17:18 +0100 | [diff] [blame] | 107 | The main issue with Boost.Python-and the reason for creating such a similar |
| 108 | project-is Boost. Boost is an enormously large and complex suite of utility |
Wenzel Jakob | 929fd7e | 2015-10-15 18:24:12 +0200 | [diff] [blame] | 109 | libraries that works with almost every C++ compiler in existence. This |
| 110 | compatibility has its cost: arcane template tricks and workarounds are |
| 111 | necessary to support the oldest and buggiest of compiler specimens. Now that |
| 112 | C++11-compatible compilers are widely available, this heavy machinery has |
| 113 | become an excessively large and unnecessary dependency. |
| 114 | |
| 115 | Think of this library as a tiny self-contained version of Boost.Python with |
Wenzel Jakob | 48548ea | 2016-01-17 22:36:44 +0100 | [diff] [blame] | 116 | everything stripped away that isn't relevant for binding generation. Without |
Wenzel Jakob | 2723a38 | 2017-01-01 17:14:27 +0100 | [diff] [blame] | 117 | comments, the core header files only require ~4K lines of code and depend on |
| 118 | Python (2.7 or 3.x, or PyPy2.7 >= 5.7) and the C++ standard library. This |
| 119 | compact implementation was possible thanks to some of the new C++11 language |
| 120 | features (specifically: tuples, lambda functions and variadic templates). Since |
| 121 | its creation, this library has grown beyond Boost.Python in many ways, leading |
| 122 | to dramatically simpler binding code in many common situations.""") |