4 from textwrap
import dedent
8 DIR = os.path.abspath(os.path.dirname(__file__))
9 MAIN_DIR = os.path.dirname(os.path.dirname(DIR))
10 WIN = sys.platform.startswith(
"win32")
or sys.platform.startswith(
"cygwin")
13 @pytest.mark.parametrize(
"parallel", [
False,
True])
14 @pytest.mark.parametrize(
"std", [11, 0])
16 monkeypatch.chdir(tmpdir)
17 monkeypatch.syspath_prepend(MAIN_DIR)
19 (tmpdir /
"setup.py").write_text(
23 sys.path.append({MAIN_DIR!r})
25 from setuptools import setup, Extension
26 from pybind11.setup_helpers import build_ext, Pybind11Extension
40 cmdclass["build_ext"] = build_ext
45 from pybind11.setup_helpers import ParallelCompile
46 ParallelCompile().install()
49 name="simple_setup_package",
51 ext_modules=ext_modules,
58 (tmpdir /
"main.cpp").write_text(
61 #include <pybind11/pybind11.h>
66 PYBIND11_MODULE(simple_setup, m) {
74 out = subprocess.check_output(
75 [sys.executable,
"setup.py",
"build_ext",
"--inplace"],
79 out = subprocess.check_output(
80 [sys.executable,
"setup.py",
"build_ext",
"--inplace",
"--force"],
81 env=
dict(os.environ, CFLAGS=
"-g"),
84 assert b
"-g0" not in out
88 for item
in tmpdir.listdir():
92 len([f
for f
in tmpdir.listdir()
if f.basename.startswith(
"simple_setup")]) == 1
94 assert len(
list(tmpdir.listdir())) == 4
96 (tmpdir /
"test.py").write_text(
100 assert simple_setup.f(3) == 9
106 subprocess.check_call(
107 [sys.executable,
"test.py"], stdout=sys.stdout, stderr=sys.stderr
112 monkeypatch.syspath_prepend(MAIN_DIR)
116 monkeypatch.chdir(tmpdir)
119 subdir = root /
"dir"
121 src = subdir /
"ext.cpp"
123 relpath = src.relto(tmpdir)
125 assert ext.name ==
"ext"
126 subdir.ensure(
"__init__.py")
128 assert ext.name ==
"dir.ext"
132 monkeypatch.syspath_prepend(MAIN_DIR)
136 monkeypatch.chdir(tmpdir)
137 root = tmpdir /
"src"
139 subdir = root /
"dir"
141 src = subdir /
"ext.cpp"
144 assert ext.name ==
"dir.ext"
146 assert ext.name ==
"foo.dir.ext"
147 subdir.ensure(
"__init__.py")
149 assert ext.name ==
"dir.ext"
151 assert ext.name ==
"foo.dir.ext"