Skip to content

Commit 6683437

Browse files
committed
fix: support tests job
Signed-off-by: Henry Schreiner <[email protected]>
1 parent 057f18a commit 6683437

File tree

4 files changed

+80
-103
lines changed

4 files changed

+80
-103
lines changed

CMakeLists.txt

+7
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,13 @@ if(PYBIND11_INSTALL)
327327
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pybind11.pc"
328328
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
329329

330+
if(DEFINED SKBUILD_PROJECT_NAME AND SKBUILD_PROJECT_NAME STREQUAL "pybind11")
331+
file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/empty")
332+
file(TOUCH "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py")
333+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/")
334+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/empty/__init__.py" DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig/")
335+
endif()
336+
330337
# Uninstall target
331338
if(PYBIND11_MASTER_PROJECT)
332339
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/tools/cmake_uninstall.cmake.in"

pyproject.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,18 @@ version_info = tuple(_to_int(s) for s in __version__.split("."))
7474

7575

7676
[tool.scikit-build]
77+
minimum-version = "build-system.requires"
78+
sdist.exclude = [
79+
"/docs/**",
80+
"/.**",
81+
]
7782
wheel.install-dir = "pybind11"
7883
wheel.platlib = false
79-
minimum-version = "build-system.requires"
84+
wheel.packages = [
85+
# not-in-global-start
86+
"pybind11",
87+
# not-in-global-end
88+
]
8089

8190
[tool.scikit-build.cmake.define]
8291
BUILD_TESTING = false

tests/extra_python_package/test_files.py

+63-99
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22

33
import contextlib
44
import os
5-
import string
5+
import re
66
import subprocess
77
import sys
88
import tarfile
99
import zipfile
10+
from pathlib import Path
11+
from typing import Generator
12+
from pprint import pprint
1013

1114
# These tests must be run explicitly
1215

13-
DIR = os.path.abspath(os.path.dirname(__file__))
14-
MAIN_DIR = os.path.dirname(os.path.dirname(DIR))
16+
DIR = Path(__file__).parent.resolve()
17+
MAIN_DIR = DIR.parent.parent
18+
19+
MARKER_PATTERN = re.compile(
20+
r"# not-in-global-start.*?# not-in-global-end\n?", re.DOTALL
21+
)
1522

1623
PKGCONFIG = """\
1724
prefix=${{pcfiledir}}/../../
@@ -114,44 +121,48 @@
114121
}
115122

116123
headers = main_headers | conduit_headers | detail_headers | eigen_headers | stl_headers
117-
src_files = headers | cmake_files | pkgconfig_files
118-
all_files = src_files | py_files
119-
124+
generated_files = cmake_files | pkgconfig_files
125+
all_files = headers | generated_files | py_files
120126

121127
sdist_files = {
122-
"pybind11",
123-
"pybind11/include",
124-
"pybind11/include/pybind11",
125-
"pybind11/include/pybind11/conduit",
126-
"pybind11/include/pybind11/detail",
127-
"pybind11/include/pybind11/eigen",
128-
"pybind11/include/pybind11/stl",
129-
"pybind11/share",
130-
"pybind11/share/cmake",
131-
"pybind11/share/cmake/pybind11",
132-
"pybind11/share/pkgconfig",
133128
"pyproject.toml",
134-
"setup.cfg",
135-
"setup.py",
136129
"LICENSE",
137-
"MANIFEST.in",
138130
"README.rst",
139131
"PKG-INFO",
140132
"SECURITY.md",
141133
}
142134

143-
local_sdist_files = {
144-
".egg-info",
145-
".egg-info/PKG-INFO",
146-
".egg-info/SOURCES.txt",
147-
".egg-info/dependency_links.txt",
148-
".egg-info/not-zip-safe",
149-
".egg-info/top_level.txt",
150-
}
135+
136+
@contextlib.contextmanager
137+
def preserve_file(filename: Path) -> Generator[str, None, None]:
138+
old_stat = filename.stat()
139+
old_file = filename.read_text(encoding="utf-8")
140+
try:
141+
yield old_file
142+
finally:
143+
filename.write_text(old_file, encoding="utf-8")
144+
os.utime(filename, (old_stat.st_atime, old_stat.st_mtime))
145+
146+
147+
@contextlib.contextmanager
148+
def build_global() -> Generator[None, None, None]:
149+
"""
150+
Build global SDist and wheel.
151+
"""
152+
153+
pyproject = MAIN_DIR / "pyproject.toml"
154+
with preserve_file(pyproject) as txt:
155+
new_txt = txt.replace('name = "pybind11"', 'name = "pybind11-global"')
156+
assert txt != new_txt
157+
newer_txt = MARKER_PATTERN.sub("", new_txt)
158+
assert new_txt != newer_txt
159+
160+
pyproject.write_text(newer_txt, encoding="utf-8")
161+
yield
151162

152163

153164
def read_tz_file(tar: tarfile.TarFile, name: str) -> bytes:
154-
start = tar.getnames()[0] + "/"
165+
start = tar.getnames()[0].split("/")[0] + "/"
155166
inner_file = tar.extractfile(tar.getmember(f"{start}{name}"))
156167
assert inner_file
157168
with contextlib.closing(inner_file) as f:
@@ -176,48 +187,22 @@ def test_build_sdist(monkeypatch, tmpdir):
176187
version = start[9:-1]
177188
simpler = {n.split("/", 1)[-1] for n in tar.getnames()[1:]}
178189

179-
setup_py = read_tz_file(tar, "setup.py")
180190
pyproject_toml = read_tz_file(tar, "pyproject.toml")
181-
pkgconfig = read_tz_file(tar, "pybind11/share/pkgconfig/pybind11.pc")
182-
cmake_cfg = read_tz_file(
183-
tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake"
184-
)
185191

186-
assert (
187-
'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
188-
in cmake_cfg.decode("utf-8")
189-
)
190-
191-
files = {f"pybind11/{n}" for n in all_files}
192-
files |= sdist_files
193-
files |= {f"pybind11{n}" for n in local_sdist_files}
194-
files.add("pybind11.egg-info/entry_points.txt")
195-
files.add("pybind11.egg-info/requires.txt")
196-
assert simpler == files
197-
198-
with open(os.path.join(MAIN_DIR, "tools", "setup_main.py.in"), "rb") as f:
199-
contents = (
200-
string.Template(f.read().decode("utf-8"))
201-
.substitute(version=version, extra_cmd="")
202-
.encode("utf-8")
203-
)
204-
assert setup_py == contents
205-
206-
with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
207-
contents = f.read()
208-
assert pyproject_toml == contents
192+
files = headers | sdist_files
193+
assert files <= simpler
209194

210195
simple_version = ".".join(version.split(".")[:3])
211-
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version).encode("utf-8")
212-
assert normalize_line_endings(pkgconfig) == pkgconfig_expected
196+
assert b'name = "pybind11"' in pyproject_toml
213197

214198

215199
def test_build_global_dist(monkeypatch, tmpdir):
216200
monkeypatch.chdir(MAIN_DIR)
217-
monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")
218-
subprocess.run(
219-
[sys.executable, "-m", "build", "--sdist", "--outdir", str(tmpdir)], check=True
220-
)
201+
with build_global():
202+
subprocess.run(
203+
[sys.executable, "-m", "build", "--sdist", "--outdir", str(tmpdir)],
204+
check=True,
205+
)
221206

222207
(sdist,) = tmpdir.visit("*.tar.gz")
223208

@@ -226,38 +211,12 @@ def test_build_global_dist(monkeypatch, tmpdir):
226211
version = start[16:-1]
227212
simpler = {n.split("/", 1)[-1] for n in tar.getnames()[1:]}
228213

229-
setup_py = read_tz_file(tar, "setup.py")
230214
pyproject_toml = read_tz_file(tar, "pyproject.toml")
231-
pkgconfig = read_tz_file(tar, "pybind11/share/pkgconfig/pybind11.pc")
232-
cmake_cfg = read_tz_file(
233-
tar, "pybind11/share/cmake/pybind11/pybind11Config.cmake"
234-
)
235-
236-
assert (
237-
'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
238-
in cmake_cfg.decode("utf-8")
239-
)
240215

241-
files = {f"pybind11/{n}" for n in all_files}
242-
files |= sdist_files
243-
files |= {f"pybind11_global{n}" for n in local_sdist_files}
244-
assert simpler == files
245-
246-
with open(os.path.join(MAIN_DIR, "tools", "setup_global.py.in"), "rb") as f:
247-
contents = (
248-
string.Template(f.read().decode())
249-
.substitute(version=version, extra_cmd="")
250-
.encode("utf-8")
251-
)
252-
assert setup_py == contents
216+
files = headers | sdist_files
217+
assert files <= simpler
253218

254-
with open(os.path.join(MAIN_DIR, "tools", "pyproject.toml"), "rb") as f:
255-
contents = f.read()
256-
assert pyproject_toml == contents
257-
258-
simple_version = ".".join(version.split(".")[:3])
259-
pkgconfig_expected = PKGCONFIG.format(VERSION=simple_version).encode("utf-8")
260-
assert normalize_line_endings(pkgconfig) == pkgconfig_expected
219+
assert b'name = "pybind11-global"' in pyproject_toml
261220

262221

263222
def tests_build_wheel(monkeypatch, tmpdir):
@@ -288,18 +247,22 @@ def tests_build_wheel(monkeypatch, tmpdir):
288247

289248
def tests_build_global_wheel(monkeypatch, tmpdir):
290249
monkeypatch.chdir(MAIN_DIR)
291-
monkeypatch.setenv("PYBIND11_GLOBAL_SDIST", "1")
292-
293-
subprocess.run(
294-
[sys.executable, "-m", "pip", "wheel", ".", "-w", str(tmpdir)], check=True
295-
)
250+
with build_global():
251+
subprocess.run(
252+
[sys.executable, "-m", "pip", "wheel", ".",
253+
"-Cskbuild.wheel.install-dir=/data",
254+
"-Cskbuild.experimental=true",
255+
"-w",
256+
str(tmpdir)], check=True
257+
)
296258

297259
(wheel,) = tmpdir.visit("*.whl")
298260

299-
files = {f"data/data/{n}" for n in src_files}
261+
files = {f"data/data/{n}" for n in headers}
300262
files |= {f"data/headers/{n[8:]}" for n in headers}
263+
files |= {f"data/data/{n}" for n in generated_files}
301264
files |= {
302-
"dist-info/LICENSE",
265+
"dist-info/licenses/LICENSE",
303266
"dist-info/METADATA",
304267
"dist-info/WHEEL",
305268
"dist-info/RECORD",
@@ -309,6 +272,7 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
309272
names = z.namelist()
310273

311274
beginning = names[0].split("/", 1)[0].rsplit(".", 1)[0]
275+
pprint(names)
312276
trimmed = {n[len(beginning) + 1 :] for n in names}
313277

314278
assert files == trimmed

tools/pyproject.toml

-3
This file was deleted.

0 commit comments

Comments
 (0)