| 15 | @pytest.mark.parametrize("parallel", [False, True]) |
| 16 | @pytest.mark.parametrize("std", [11, 0]) |
| 17 | def test_simple_setup_py(monkeypatch, tmpdir, parallel, std): |
| 18 | monkeypatch.chdir(tmpdir) |
| 19 | monkeypatch.syspath_prepend(MAIN_DIR) |
| 20 | |
| 21 | (tmpdir / "setup.py").write_text( |
| 22 | dedent( |
| 23 | f"""\ |
| 24 | import sys |
| 25 | sys.path.append({MAIN_DIR!r}) |
| 26 | |
| 27 | from setuptools import setup, Extension |
| 28 | from pybind11.setup_helpers import build_ext, Pybind11Extension |
| 29 | |
| 30 | std = {std} |
| 31 | |
| 32 | ext_modules = [ |
| 33 | Pybind11Extension( |
| 34 | "simple_setup", |
| 35 | sorted(["main.cpp"]), |
| 36 | cxx_std=std, |
| 37 | ), |
| 38 | ] |
| 39 | |
| 40 | cmdclass = dict() |
| 41 | if std == 0: |
| 42 | cmdclass["build_ext"] = build_ext |
| 43 | |
| 44 | |
| 45 | parallel = {parallel} |
| 46 | if parallel: |
| 47 | from pybind11.setup_helpers import ParallelCompile |
| 48 | ParallelCompile().install() |
| 49 | |
| 50 | setup( |
| 51 | name="simple_setup_package", |
| 52 | cmdclass=cmdclass, |
| 53 | ext_modules=ext_modules, |
| 54 | ) |
| 55 | """ |
| 56 | ), |
| 57 | encoding="ascii", |
| 58 | ) |
| 59 | |
| 60 | (tmpdir / "main.cpp").write_text( |
| 61 | dedent( |
| 62 | """\ |
| 63 | #include <pybind11/pybind11.h> |
| 64 | |
| 65 | int f(int x) { |
| 66 | return x * 3; |
| 67 | } |
| 68 | PYBIND11_MODULE(simple_setup, m) { |
| 69 | m.def("f", &f); |
| 70 | } |
| 71 | """ |
| 72 | ), |
| 73 | encoding="ascii", |
| 74 | ) |