mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-11 08:03:55 +00:00
Install headers using both headers and package_data (#1995)
This commit is contained in:
parent
a60648223d
commit
3735249122
@ -2,35 +2,11 @@ from ._version import version_info, __version__ # noqa: F401 imported but unuse
|
|||||||
|
|
||||||
|
|
||||||
def get_include(user=False):
|
def get_include(user=False):
|
||||||
from distutils.dist import Distribution
|
|
||||||
import os
|
import os
|
||||||
import sys
|
d = os.path.dirname(__file__)
|
||||||
|
if os.path.exists(os.path.join(d, "include")):
|
||||||
# Are we running in a virtual environment?
|
# Package is installed
|
||||||
virtualenv = hasattr(sys, 'real_prefix') or \
|
return os.path.join(d, "include")
|
||||||
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:
|
else:
|
||||||
return os.path.join(sys.prefix, 'include')
|
# Package is from a source directory
|
||||||
else:
|
return os.path.join(os.path.dirname(d), "include")
|
||||||
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)
|
|
||||||
|
@ -10,8 +10,7 @@ from . import get_include
|
|||||||
def print_includes():
|
def print_includes():
|
||||||
dirs = [sysconfig.get_path('include'),
|
dirs = [sysconfig.get_path('include'),
|
||||||
sysconfig.get_path('platinclude'),
|
sysconfig.get_path('platinclude'),
|
||||||
get_include(),
|
get_include()]
|
||||||
get_include(True)]
|
|
||||||
|
|
||||||
# Make unique but preserve order
|
# Make unique but preserve order
|
||||||
unique_dirs = []
|
unique_dirs = []
|
||||||
|
28
setup.py
28
setup.py
@ -4,15 +4,11 @@
|
|||||||
|
|
||||||
from setuptools import setup
|
from setuptools import setup
|
||||||
from distutils.command.install_headers import install_headers
|
from distutils.command.install_headers import install_headers
|
||||||
|
from distutils.command.build_py import build_py
|
||||||
from pybind11 import __version__
|
from pybind11 import __version__
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Prevent installation of pybind11 headers by setting
|
package_data = [
|
||||||
# PYBIND11_USE_CMAKE.
|
|
||||||
if os.environ.get('PYBIND11_USE_CMAKE'):
|
|
||||||
headers = []
|
|
||||||
else:
|
|
||||||
headers = [
|
|
||||||
'include/pybind11/detail/class.h',
|
'include/pybind11/detail/class.h',
|
||||||
'include/pybind11/detail/common.h',
|
'include/pybind11/detail/common.h',
|
||||||
'include/pybind11/detail/descr.h',
|
'include/pybind11/detail/descr.h',
|
||||||
@ -39,6 +35,13 @@ else:
|
|||||||
'include/pybind11/stl_bind.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 = package_data
|
||||||
|
|
||||||
|
|
||||||
class InstallHeaders(install_headers):
|
class InstallHeaders(install_headers):
|
||||||
"""Use custom header installer because the default one flattens subdirectories"""
|
"""Use custom header installer because the default one flattens subdirectories"""
|
||||||
@ -55,6 +58,16 @@ class InstallHeaders(install_headers):
|
|||||||
self.outfiles.append(out)
|
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 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)
|
||||||
|
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='pybind11',
|
name='pybind11',
|
||||||
version=__version__,
|
version=__version__,
|
||||||
@ -66,7 +79,8 @@ setup(
|
|||||||
packages=['pybind11'],
|
packages=['pybind11'],
|
||||||
license='BSD',
|
license='BSD',
|
||||||
headers=headers,
|
headers=headers,
|
||||||
cmdclass=dict(install_headers=InstallHeaders),
|
zip_safe=False,
|
||||||
|
cmdclass=dict(install_headers=InstallHeaders, build_py=BuildPy),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 5 - Production/Stable',
|
'Development Status :: 5 - Production/Stable',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
|
Loading…
Reference in New Issue
Block a user