1 from __future__
import annotations
6 from textwrap
import dedent
10 DIR = os.path.abspath(os.path.dirname(__file__))
11 MAIN_DIR = os.path.dirname(os.path.dirname(DIR))
12 WIN = sys.platform.startswith(
"win32")
or sys.platform.startswith(
"cygwin")
15 @pytest.mark.parametrize(
"parallel", [
False,
True])
16 @pytest.mark.parametrize(
"std", [11, 0])
18 monkeypatch.chdir(tmpdir)
19 monkeypatch.syspath_prepend(MAIN_DIR)
21 (tmpdir /
"setup.py").write_text(
25 sys.path.append({MAIN_DIR!r})
27 from setuptools import setup, Extension
28 from pybind11.setup_helpers import build_ext, Pybind11Extension
42 cmdclass["build_ext"] = build_ext
47 from pybind11.setup_helpers import ParallelCompile
48 ParallelCompile().install()
51 name="simple_setup_package",
53 ext_modules=ext_modules,
60 (tmpdir /
"main.cpp").write_text(
63 #include <pybind11/pybind11.h>
68 PYBIND11_MODULE(simple_setup, m) {
76 out = subprocess.check_output(
77 [sys.executable,
"setup.py",
"build_ext",
"--inplace"],
81 out = subprocess.check_output(
82 [sys.executable,
"setup.py",
"build_ext",
"--inplace",
"--force"],
83 env=
dict(os.environ, CFLAGS=
"-g"),
86 assert b
"-g0" not in out
90 for item
in tmpdir.listdir():
94 len([f
for f
in tmpdir.listdir()
if f.basename.startswith(
"simple_setup")]) == 1
96 assert len(
list(tmpdir.listdir())) == 4
98 (tmpdir /
"test.py").write_text(
102 assert simple_setup.f(3) == 9
108 subprocess.check_call(
109 [sys.executable,
"test.py"], stdout=sys.stdout, stderr=sys.stderr
114 monkeypatch.syspath_prepend(MAIN_DIR)
118 monkeypatch.chdir(tmpdir)
121 subdir = root /
"dir"
123 src = subdir /
"ext.cpp"
125 relpath = src.relto(tmpdir)
127 assert ext.name ==
"ext"
128 subdir.ensure(
"__init__.py")
130 assert ext.name ==
"dir.ext"
134 monkeypatch.syspath_prepend(MAIN_DIR)
138 monkeypatch.chdir(tmpdir)
139 root = tmpdir /
"src"
141 subdir = root /
"dir"
143 src = subdir /
"ext.cpp"
146 assert ext.name ==
"dir.ext"
148 assert ext.name ==
"foo.dir.ext"
149 subdir.ensure(
"__init__.py")
151 assert ext.name ==
"dir.ext"
153 assert ext.name ==
"foo.dir.ext"