blob: 577a6b6c37c9d284b0d5b7453de62aaa71c50869 [file] [log] [blame]
Wenzel Jakob929fd7e2015-10-15 18:24:12 +02001#!/usr/bin/env python
Henry Schreinerd8c7ee02020-07-20 13:35:21 -04002# -*- coding: utf-8 -*-
Wenzel Jakob929fd7e2015-10-15 18:24:12 +02003
Dean Moldovana0c1ccf2016-08-12 13:50:00 +02004# Setup script for PyPI; use CMakeFile.txt to build extension modules
Wenzel Jakob929fd7e2015-10-15 18:24:12 +02005
6from setuptools import setup
Dean Moldovan1913f252017-08-23 14:20:53 +02007from distutils.command.install_headers import install_headers
Isuru Fernando37352492019-11-28 01:59:23 -06008from distutils.command.build_py import build_py
Wenzel Jakob4f972c02016-03-01 10:36:10 +01009from pybind11 import __version__
Sylvain Corlayd5ce82b2017-02-14 13:16:14 +010010import os
Wenzel Jakob929fd7e2015-10-15 18:24:12 +020011
Isuru Fernando37352492019-11-28 01:59:23 -060012package_data = [
13 'include/pybind11/detail/class.h',
14 'include/pybind11/detail/common.h',
15 'include/pybind11/detail/descr.h',
16 'include/pybind11/detail/init.h',
17 'include/pybind11/detail/internals.h',
18 'include/pybind11/detail/typeid.h',
19 'include/pybind11/attr.h',
20 'include/pybind11/buffer_info.h',
21 'include/pybind11/cast.h',
22 'include/pybind11/chrono.h',
23 'include/pybind11/common.h',
24 'include/pybind11/complex.h',
25 'include/pybind11/eigen.h',
26 'include/pybind11/embed.h',
27 'include/pybind11/eval.h',
28 'include/pybind11/functional.h',
29 'include/pybind11/iostream.h',
30 'include/pybind11/numpy.h',
31 'include/pybind11/operators.h',
32 'include/pybind11/options.h',
33 'include/pybind11/pybind11.h',
34 'include/pybind11/pytypes.h',
35 'include/pybind11/stl.h',
36 'include/pybind11/stl_bind.h',
37]
38
Sylvain Corlayd5ce82b2017-02-14 13:16:14 +010039# Prevent installation of pybind11 headers by setting
40# PYBIND11_USE_CMAKE.
41if os.environ.get('PYBIND11_USE_CMAKE'):
42 headers = []
43else:
Isuru Fernando37352492019-11-28 01:59:23 -060044 headers = package_data
Sylvain Corlayd5ce82b2017-02-14 13:16:14 +010045
Dean Moldovan1913f252017-08-23 14:20:53 +020046
47class InstallHeaders(install_headers):
48 """Use custom header installer because the default one flattens subdirectories"""
49 def run(self):
50 if not self.distribution.headers:
51 return
52
53 for header in self.distribution.headers:
54 subdir = os.path.dirname(os.path.relpath(header, 'include/pybind11'))
55 install_dir = os.path.join(self.install_dir, subdir)
56 self.mkpath(install_dir)
57
58 (out, _) = self.copy_file(header, install_dir)
59 self.outfiles.append(out)
60
61
Isuru Fernando37352492019-11-28 01:59:23 -060062# Install the headers inside the package as well
63class BuildPy(build_py):
64 def build_package_data(self):
65 build_py.build_package_data(self)
66 for header in package_data:
67 target = os.path.join(self.build_lib, 'pybind11', header)
68 self.mkpath(os.path.dirname(target))
69 self.copy_file(header, target, preserve_mode=False)
70
Isuru Fernandoe107fc22020-04-26 14:56:10 +000071 def get_outputs(self, include_bytecode=1):
72 outputs = build_py.get_outputs(self, include_bytecode=include_bytecode)
73 for header in package_data:
74 target = os.path.join(self.build_lib, 'pybind11', header)
75 outputs.append(target)
76 return outputs
77
Isuru Fernando37352492019-11-28 01:59:23 -060078
Sylvain Corlayd5ce82b2017-02-14 13:16:14 +010079setup(
80 name='pybind11',
81 version=__version__,
82 description='Seamless operability between C++11 and Python',
83 author='Wenzel Jakob',
84 author_email='wenzel.jakob@epfl.ch',
Maciek Starzyk9b028562018-06-02 20:21:19 +020085 url='https://github.com/pybind/pybind11',
86 download_url='https://github.com/pybind/pybind11/tarball/v' + __version__,
Sylvain Corlayd5ce82b2017-02-14 13:16:14 +010087 packages=['pybind11'],
88 license='BSD',
89 headers=headers,
Isuru Fernando37352492019-11-28 01:59:23 -060090 zip_safe=False,
91 cmdclass=dict(install_headers=InstallHeaders, build_py=BuildPy),
Wenzel Jakob929fd7e2015-10-15 18:24:12 +020092 classifiers=[
93 'Development Status :: 5 - Production/Stable',
94 'Intended Audience :: Developers',
95 'Topic :: Software Development :: Libraries :: Python Modules',
96 'Topic :: Utilities',
97 'Programming Language :: C++',
98 'Programming Language :: Python :: 2.7',
99 'Programming Language :: Python :: 3',
100 'Programming Language :: Python :: 3.2',
101 'Programming Language :: Python :: 3.3',
102 'Programming Language :: Python :: 3.4',
Wenzel Jakobb456ec72015-10-15 22:43:55 +0200103 'Programming Language :: Python :: 3.5',
Wenzel Jakob2723a382017-01-01 17:14:27 +0100104 'Programming Language :: Python :: 3.6',
105 'License :: OSI Approved :: BSD License'
Wenzel Jakob929fd7e2015-10-15 18:24:12 +0200106 ],
107 keywords='C++11, Python bindings',
Wenzel Jakob2723a382017-01-01 17:14:27 +0100108 long_description="""pybind11 is a lightweight header-only library that
109exposes C++ types in Python and vice versa, mainly to create Python bindings of
Wenzel Jakob929fd7e2015-10-15 18:24:12 +0200110existing C++ code. Its goals and syntax are similar to the excellent
Wenzel Jakob2723a382017-01-01 17:14:27 +0100111Boost.Python by David Abrahams: to minimize boilerplate code in traditional
112extension modules by inferring type information using compile-time
Wenzel Jakob929fd7e2015-10-15 18:24:12 +0200113introspection.
114
Wenzel Jakob0f294e22017-01-04 15:17:18 +0100115The main issue with Boost.Python-and the reason for creating such a similar
116project-is Boost. Boost is an enormously large and complex suite of utility
Wenzel Jakob929fd7e2015-10-15 18:24:12 +0200117libraries that works with almost every C++ compiler in existence. This
118compatibility has its cost: arcane template tricks and workarounds are
119necessary to support the oldest and buggiest of compiler specimens. Now that
120C++11-compatible compilers are widely available, this heavy machinery has
121become an excessively large and unnecessary dependency.
122
123Think of this library as a tiny self-contained version of Boost.Python with
Wenzel Jakob48548ea2016-01-17 22:36:44 +0100124everything stripped away that isn't relevant for binding generation. Without
Wenzel Jakob2723a382017-01-01 17:14:27 +0100125comments, the core header files only require ~4K lines of code and depend on
126Python (2.7 or 3.x, or PyPy2.7 >= 5.7) and the C++ standard library. This
127compact implementation was possible thanks to some of the new C++11 language
128features (specifically: tuples, lambda functions and variadic templates). Since
129its creation, this library has grown beyond Boost.Python in many ways, leading
130to dramatically simpler binding code in many common situations.""")