Skip to content

Commit 1913f25

Browse files
committed
Fix setup.py detail headers and add pip install tests to Travis
The default `install_headers` from `distutils` flattens all the headers into a single directory -- `detail` subdirectory was lost. This commit fixes this by overriding the setup with a custom header installer. Tests are added to Travis to make sure `setup.py sdist` and `pip install` do not miss any headers and that the directory structure is preserved. [skip appveyor]
1 parent e8b5074 commit 1913f25

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

.travis.yml

+8-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ matrix:
6565
# Documentation build:
6666
- os: linux
6767
language: docs
68-
env: DOCS STYLE LINT
68+
env: DOCS STYLE LINT PIP
69+
cache: false
6970
install:
7071
- export PATH="~/.local/bin:$PATH"
7172
- $PY_CMD -m pip install --user --upgrade sphinx sphinx_rtd_theme breathe flake8 pep8-naming
@@ -76,6 +77,12 @@ matrix:
7677
- $PY_CMD -m sphinx -W -b html docs docs/.build
7778
- tools/check-style.sh
7879
- flake8
80+
- |
81+
# Make sure setup.py distributes and installs all the headers
82+
$PY_CMD setup.py sdist
83+
$PY_CMD -m pip install --user -U ./dist/*
84+
installed=$($PY_CMD -c "import pybind11; print(pybind11.get_include(True) + '/pybind11')")
85+
diff -rq $installed ./include/pybind11
7986
cache:
8087
directories:
8188
- $HOME/.local/bin

MANIFEST.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
include include/pybind11/*.h
1+
recursive-include include/pybind11 *.h
22
include LICENSE README.md CONTRIBUTING.md

setup.py

+19-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Setup script for PyPI; use CMakeFile.txt to build extension modules
44

55
from setuptools import setup
6+
from distutils.command.install_headers import install_headers
67
from pybind11 import __version__
78
import os
89

@@ -17,7 +18,7 @@
1718
'include/pybind11/detail/descr.h',
1819
'include/pybind11/detail/init.h',
1920
'include/pybind11/detail/internals.h',
20-
'include/pybind11/detail/typeid.h'
21+
'include/pybind11/detail/typeid.h',
2122
'include/pybind11/attr.h',
2223
'include/pybind11/buffer_info.h',
2324
'include/pybind11/cast.h',
@@ -36,6 +37,22 @@
3637
'include/pybind11/stl_bind.h',
3738
]
3839

40+
41+
class InstallHeaders(install_headers):
42+
"""Use custom header installer because the default one flattens subdirectories"""
43+
def run(self):
44+
if not self.distribution.headers:
45+
return
46+
47+
for header in self.distribution.headers:
48+
subdir = os.path.dirname(os.path.relpath(header, 'include/pybind11'))
49+
install_dir = os.path.join(self.install_dir, subdir)
50+
self.mkpath(install_dir)
51+
52+
(out, _) = self.copy_file(header, install_dir)
53+
self.outfiles.append(out)
54+
55+
3956
setup(
4057
name='pybind11',
4158
version=__version__,
@@ -47,6 +64,7 @@
4764
packages=['pybind11'],
4865
license='BSD',
4966
headers=headers,
67+
cmdclass=dict(install_headers=InstallHeaders),
5068
classifiers=[
5169
'Development Status :: 5 - Production/Stable',
5270
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)