Skip to content

Commit 59c884a

Browse files
committed
Migrate tests to semiwrap and add enhancements
- Builds multiple projects that use things from each other
1 parent 4b17321 commit 59c884a

File tree

203 files changed

+508
-272
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

203 files changed

+508
-272
lines changed

tests/cpp/.gitignore

+6-23
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,18 @@
11

22
*.py[ciod]
33

4+
*.pc
5+
*.pybind11.json
46
*.so
57
*.dll
68
*.pyd
79
*.dylib
810
py.typed
911

1012

11-
/build
12-
/dist
13-
/pip-wheel-metadata
13+
build
14+
dist
15+
trampolines
1416

15-
# autogenerated from template
16-
/pyproject.toml
17+
version.py
1718

18-
/rpytest/version.py
19-
20-
/rpytest/dl/_init_rpytest_dl.py
21-
/rpytest/dl/pkgcfg.py
22-
/rpytest/dl/include
23-
/rpytest/dl/rpy-include
24-
25-
/rpytest/ft/_init_rpytest_ft.py
26-
/rpytest/ft/pkgcfg.py
27-
/rpytest/ft/rpy-include
28-
29-
/rpytest/srconly/_init_rpytest_srconly.py
30-
/rpytest/srconly/pkgcfg.py
31-
/rpytest/srconly/include
32-
/rpytest/srconly/rpy-include
33-
34-
/rpytest/tc/_init_rpytest_tc.py
35-
/rpytest/tc/pkgcfg.py

tests/cpp/dl/downloaded.cpp

-6
This file was deleted.

tests/cpp/dl/downloaded.h

-4
This file was deleted.

tests/cpp/gen/dl/downloaded.yml

-4
This file was deleted.

tests/cpp/rpytest/dl/__init__.py

-6
This file was deleted.

tests/cpp/rpytest/dl/dl.cpp

-3
This file was deleted.

tests/cpp/rpytest/dl/dl.patch

-10
This file was deleted.

tests/cpp/rpytest/ft/src/ft.cpp

-7
This file was deleted.

tests/cpp/rpytest/ft/subpkg.py

-4
This file was deleted.

tests/cpp/rpytest/srconly/__init__.py

-4
This file was deleted.

tests/cpp/rpytest/srconly/srconly.cpp

-10
This file was deleted.

tests/cpp/run_install.py

+21-66
Original file line numberDiff line numberDiff line change
@@ -1,94 +1,49 @@
11
#!/usr/bin/env python3
22

3-
import http.server
43
import os
54
from os.path import abspath, dirname, join
65
import pathlib
76
import shutil
87
import sys
98
import subprocess
10-
import threading
119
import tempfile
1210
import zipfile
1311

1412

15-
def create_artifact_path(path, group_id, artifact_id, version, classifier):
16-
components = group_id.split(".") + [artifact_id, version]
17-
path = join(path, *components)
18-
os.makedirs(path, exist_ok=True)
19-
fname = f"{artifact_id}-{version}-{classifier}.zip"
20-
return join(path, fname)
21-
22-
23-
def http_server():
24-
httpd = http.server.HTTPServer(
25-
("127.0.0.1", 0), http.server.SimpleHTTPRequestHandler
26-
)
27-
28-
t = threading.Thread(target=httpd.serve_forever, daemon=True)
29-
t.start()
30-
31-
return httpd, httpd.socket.getsockname()[1]
13+
def subprocess_must_run(*args, **kwargs):
14+
"""Run a subprocess verbosely and exit if there is an error"""
15+
try:
16+
print("+", *args[0])
17+
subprocess.run(check=True, *args, **kwargs)
18+
except subprocess.CalledProcessError as cbe:
19+
print(cbe, file=sys.stderr)
20+
sys.exit(cbe.returncode)
3221

3322

3423
if __name__ == "__main__":
3524
root = abspath(dirname(__file__))
3625
os.chdir(root)
3726

38-
# delete build/cache directory
39-
shutil.rmtree(join(root, "build", "cache"), ignore_errors=True)
40-
41-
# create tempdir with maven directory structure for pkg
42-
with tempfile.TemporaryDirectory() as d:
43-
# create headers and sources zip files
44-
hname = create_artifact_path(d, "fake.dl", "dl", "1.2.3", "headers")
45-
with zipfile.ZipFile(hname, "w") as z:
46-
z.write(join(root, "dl", "downloaded.h"), "downloaded.h")
47-
48-
sname = create_artifact_path(d, "fake.dl", "dl", "1.2.3", "sources")
49-
with zipfile.ZipFile(sname, "w") as z:
50-
z.write(join(root, "dl", "downloaded.cpp"), "downloaded.cpp")
51-
52-
# http.server prior to 3.7 could only serve the current directory
53-
os.chdir(d)
27+
to_install = ["sw-test-base", "sw-caster-consumer", "sw-test"]
5428

55-
# start http server on random port
56-
httpd, port = http_server()
57-
58-
with open(join(root, "pyproject.toml.tmpl")) as rfp:
59-
content = rfp.read().replace("RANDOM_PORT", str(port))
60-
with open(join(root, "pyproject.toml"), "w") as wfp:
61-
wfp.write(content)
62-
63-
cwd = None
29+
# First, uninstall packages
30+
subprocess_must_run(
31+
[sys.executable, "-m", "pip", "--disable-pip-version-check", "uninstall", "-y"]
32+
+ to_install
33+
)
6434

65-
if len(sys.argv) == 2 and sys.argv[1] == "wheel":
66-
cmd_args = [sys.executable, "-m", "build", "--wheel", "--no-isolation"]
67-
cwd = root
68-
elif len(sys.argv) == 2 and sys.argv[1] == "develop":
69-
cmd_args = [sys.executable, "setup.py", "develop", "-N"]
70-
cwd = root
71-
else:
72-
# run pip install
73-
cmd_args = [
35+
# Now install them
36+
for pkg in to_install:
37+
subprocess_must_run(
38+
[
7439
sys.executable,
7540
"-m",
7641
"pip",
7742
"-v",
7843
"--disable-pip-version-check",
7944
"install",
8045
"--no-build-isolation",
46+
os.path.abspath(pkg),
8147
]
82-
83-
if len(sys.argv) == 2 and sys.argv[1] == "-e":
84-
cmd_args.append("-e")
85-
86-
cmd_args.append(root)
87-
88-
env = os.environ.copy()
89-
env["SETUPTOOLS_SCM_PRETEND_VERSION"] = "0.0.1"
90-
91-
subprocess.check_call(cmd_args, cwd=cwd, env=env)
92-
93-
# Windows fails if you try to delete the directory you're currently in
94-
os.chdir(root)
48+
+ sys.argv[1:]
49+
)

tests/cpp/setup.py

-5
This file was deleted.
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
project('sw-caster-consumer', ['cpp'],
2+
default_options: ['warning_level=1', 'cpp_std=c++20',
3+
'b_colorout=auto', 'optimization=2', 'b_pie=true'])
4+
5+
subdir('wrapcfg')
6+
7+
sw_caster_consumer__module_sources += files(
8+
'src/sw_caster_consumer/cpp/main.cpp',
9+
)
10+
11+
subdir('wrapcfg/modules')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
[build-system]
2+
build-backend = "hatchling.build"
3+
requires = ["semiwrap", "hatch-meson", "hatchling"]
4+
5+
[project]
6+
description = "Test program"
7+
name = "sw-caster-consumer"
8+
version = "0.0.1"
9+
10+
[tool.hatch.build.targets.wheel]
11+
packages = ['src/sw_caster_consumer']
12+
13+
[tool.hatch.build.hooks.semiwrap]
14+
15+
[tool.hatch.build.hooks.meson]
16+
17+
#
18+
# Semiwrap configuration
19+
#
20+
21+
[tool.semiwrap]
22+
[tool.semiwrap.extension_modules."sw_caster_consumer._module"]
23+
depends = ["swtest_base__module"]
24+
25+
[tool.semiwrap.extension_modules."sw_caster_consumer._module".headers]
26+
more = "cpp/more.h"
27+
28+
# checks that caster is included automatically when in a namespace
29+
ns_more = "cpp/ns_more.h"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from ._module import add_more_to_inty
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#include <semiwrap_init.sw_caster_consumer._module.hpp>
2+
3+
SEMIWRAP_PYBIND11_MODULE(m) {
4+
initWrapper(m);
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#pragma once
2+
3+
#include <inty.h>
4+
5+
inline inty add_more_to_inty(inty v, long value) {
6+
v.long_value += value;
7+
return v;
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#pragma once
2+
3+
#include <ns_inty.h>
4+
5+
namespace ns {
6+
7+
inline inty2 add_more_to_inty2(inty2 v, long value) {
8+
v.long_value += value;
9+
return v;
10+
}
11+
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
functions:
4+
add_more_to_inty:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
functions:
4+
add_more_to_inty2:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/meson.build

tests/cpp/sw-test-base/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/src/swtest_base/sw-caster-test-casters.pc
2+
/src/swtest_base/sw-caster-test-casters.pybind11.json
3+
/src/swtest_base/trampolines

tests/cpp/sw-test-base/meson.build

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
project('swtest-base', ['cpp'],
2+
default_options: ['warning_level=1', 'cpp_std=c++20',
3+
'b_colorout=auto', 'optimization=2', 'b_pie=true'])
4+
5+
subdir('wrapcfg')
6+
7+
swtest_base__module_sources += files(
8+
'src/swtest_base/cpp/main.cpp',
9+
)
10+
11+
swtest_base__module2_sources += files(
12+
'src/swtest_base/cpp/main2.cpp',
13+
)
14+
15+
swtest_base__module3_sources += files(
16+
'src/swtest_base/cpp/main3.cpp',
17+
)
18+
19+
subdir('wrapcfg/modules')

0 commit comments

Comments
 (0)