From 8026416c97e4af8473b28f0e7c0bd385370e98b3 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 16:22:36 -0600 Subject: [PATCH 1/7] Install headers using both headers and package_data --- pybind11/__init__.py | 33 ++------------------------ setup.py | 55 +++++++++++++++++++++++--------------------- 2 files changed, 31 insertions(+), 57 deletions(-) diff --git a/pybind11/__init__.py b/pybind11/__init__.py index c625e8c948..b0d5367000 100644 --- a/pybind11/__init__.py +++ b/pybind11/__init__.py @@ -2,35 +2,6 @@ def get_include(user=False): - from distutils.dist import Distribution import os - import sys - - # Are we running in a virtual environment? - virtualenv = hasattr(sys, 'real_prefix') or \ - sys.prefix != getattr(sys, "base_prefix", sys.prefix) - - # Are we running in a conda environment? - conda = os.path.exists(os.path.join(sys.prefix, 'conda-meta')) - - if virtualenv: - return os.path.join(sys.prefix, 'include', 'site', - 'python' + sys.version[:3]) - elif conda: - if os.name == 'nt': - return os.path.join(sys.prefix, 'Library', 'include') - else: - return os.path.join(sys.prefix, 'include') - else: - dist = Distribution({'name': 'pybind11'}) - dist.parse_config_files() - - dist_cobj = dist.get_command_obj('install', create=True) - - # Search for packages in user's home directory? - if user: - dist_cobj.user = user - dist_cobj.prefix = "" - dist_cobj.finalize_options() - - return os.path.dirname(dist_cobj.install_headers) + d = os.path.dirname(__file__) + return os.path.join(os.path.dirname(d), "include") diff --git a/setup.py b/setup.py index f677f2af4a..4248949643 100644 --- a/setup.py +++ b/setup.py @@ -7,37 +7,39 @@ from pybind11 import __version__ import os +package_data = [ + 'include/pybind11/detail/class.h', + 'include/pybind11/detail/common.h', + 'include/pybind11/detail/descr.h', + 'include/pybind11/detail/init.h', + 'include/pybind11/detail/internals.h', + 'include/pybind11/detail/typeid.h', + 'include/pybind11/attr.h', + 'include/pybind11/buffer_info.h', + 'include/pybind11/cast.h', + 'include/pybind11/chrono.h', + 'include/pybind11/common.h', + 'include/pybind11/complex.h', + 'include/pybind11/eigen.h', + 'include/pybind11/embed.h', + 'include/pybind11/eval.h', + 'include/pybind11/functional.h', + 'include/pybind11/iostream.h', + 'include/pybind11/numpy.h', + 'include/pybind11/operators.h', + 'include/pybind11/options.h', + 'include/pybind11/pybind11.h', + 'include/pybind11/pytypes.h', + 'include/pybind11/stl.h', + 'include/pybind11/stl_bind.h', +] + # Prevent installation of pybind11 headers by setting # PYBIND11_USE_CMAKE. if os.environ.get('PYBIND11_USE_CMAKE'): headers = [] else: - headers = [ - 'include/pybind11/detail/class.h', - 'include/pybind11/detail/common.h', - 'include/pybind11/detail/descr.h', - 'include/pybind11/detail/init.h', - 'include/pybind11/detail/internals.h', - 'include/pybind11/detail/typeid.h', - 'include/pybind11/attr.h', - 'include/pybind11/buffer_info.h', - 'include/pybind11/cast.h', - 'include/pybind11/chrono.h', - 'include/pybind11/common.h', - 'include/pybind11/complex.h', - 'include/pybind11/eigen.h', - 'include/pybind11/embed.h', - 'include/pybind11/eval.h', - 'include/pybind11/functional.h', - 'include/pybind11/iostream.h', - 'include/pybind11/numpy.h', - 'include/pybind11/operators.h', - 'include/pybind11/options.h', - 'include/pybind11/pybind11.h', - 'include/pybind11/pytypes.h', - 'include/pybind11/stl.h', - 'include/pybind11/stl_bind.h', - ] + headers = package_data class InstallHeaders(install_headers): @@ -66,6 +68,7 @@ def run(self): packages=['pybind11'], license='BSD', headers=headers, + package_data={'pybind11': package_data}, cmdclass=dict(install_headers=InstallHeaders), classifiers=[ 'Development Status :: 5 - Production/Stable', From d2daeb231a205f9ac32c6b03a7ae23964e18322b Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 16:45:27 -0600 Subject: [PATCH 2/7] Not zip_safe --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index 4248949643..b69190c24f 100644 --- a/setup.py +++ b/setup.py @@ -69,6 +69,7 @@ def run(self): license='BSD', headers=headers, package_data={'pybind11': package_data}, + zip_safe=False, cmdclass=dict(install_headers=InstallHeaders), classifiers=[ 'Development Status :: 5 - Production/Stable', From 879f4e93e68fddbccfd707061b14b3169505f725 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 17:34:16 -0600 Subject: [PATCH 3/7] Update get_include --- pybind11/__init__.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pybind11/__init__.py b/pybind11/__init__.py index b0d5367000..4b1de3efaa 100644 --- a/pybind11/__init__.py +++ b/pybind11/__init__.py @@ -4,4 +4,9 @@ def get_include(user=False): import os d = os.path.dirname(__file__) - return os.path.join(os.path.dirname(d), "include") + if os.path.exists(os.path.join(d, "include")): + # Package is installed + return os.path.join(d, "include") + else: + # Package is from a source directory + return os.path.join(os.path.dirname(d), "include") From b19e14939c5f50fc7533d0d218bca96557b24ef1 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 20:29:52 -0600 Subject: [PATCH 4/7] Install the headers inside --- setup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index b69190c24f..bcead42e93 100644 --- a/setup.py +++ b/setup.py @@ -4,6 +4,7 @@ from setuptools import setup from distutils.command.install_headers import install_headers +from distutils.command.build_py import build_py from pybind11 import __version__ import os @@ -57,6 +58,15 @@ def run(self): self.outfiles.append(out) +# Install the headers inside the package as well +class BuildPy(build_py): + def build_package_data(self): + build_py.build_package_data(self) + for header in self.distribution.headers: + target = os.path.join(self.build_lib, 'pybind11', header) + self.mkpath(os.path.dirname(target)) + self.copy_file(header, target, preserve_mode=False) + setup( name='pybind11', version=__version__, @@ -68,9 +78,8 @@ def run(self): packages=['pybind11'], license='BSD', headers=headers, - package_data={'pybind11': package_data}, zip_safe=False, - cmdclass=dict(install_headers=InstallHeaders), + cmdclass=dict(install_headers=InstallHeaders, build_py=BuildPy), classifiers=[ 'Development Status :: 5 - Production/Stable', 'Intended Audience :: Developers', From 45a3a56d5558df2e31c352577103df4e9737b7fd Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 20:33:55 -0600 Subject: [PATCH 5/7] Install headers regardless of the env variable --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index bcead42e93..e8f7d08236 100644 --- a/setup.py +++ b/setup.py @@ -62,7 +62,7 @@ def run(self): class BuildPy(build_py): def build_package_data(self): build_py.build_package_data(self) - for header in self.distribution.headers: + for header in package_data: target = os.path.join(self.build_lib, 'pybind11', header) self.mkpath(os.path.dirname(target)) self.copy_file(header, target, preserve_mode=False) From 27dc5116f46e571146b087648b7c7d1197b9ca74 Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Tue, 19 Nov 2019 22:57:21 -0600 Subject: [PATCH 6/7] Fix formatting --- setup.py | 1 + 1 file changed, 1 insertion(+) diff --git a/setup.py b/setup.py index e8f7d08236..473ea1ee08 100644 --- a/setup.py +++ b/setup.py @@ -67,6 +67,7 @@ def build_package_data(self): self.mkpath(os.path.dirname(target)) self.copy_file(header, target, preserve_mode=False) + setup( name='pybind11', version=__version__, From 3dd7723c35765f0709292fb34a404a87661baa0f Mon Sep 17 00:00:00 2001 From: Isuru Fernando Date: Sun, 24 Nov 2019 02:55:20 -0600 Subject: [PATCH 7/7] No need of user=True in __main__.py --- pybind11/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pybind11/__main__.py b/pybind11/__main__.py index 9ef8378029..89b263a8ad 100644 --- a/pybind11/__main__.py +++ b/pybind11/__main__.py @@ -10,8 +10,7 @@ def print_includes(): dirs = [sysconfig.get_path('include'), sysconfig.get_path('platinclude'), - get_include(), - get_include(True)] + get_include()] # Make unique but preserve order unique_dirs = []