2
2
3
3
import contextlib
4
4
import os
5
- import string
5
+ import re
6
6
import subprocess
7
7
import sys
8
8
import tarfile
9
9
import zipfile
10
+ from pathlib import Path
11
+ from typing import Generator
12
+ from pprint import pprint
10
13
11
14
# These tests must be run explicitly
12
15
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
+ )
15
22
16
23
PKGCONFIG = """\
17
24
prefix=${{pcfiledir}}/../../
114
121
}
115
122
116
123
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
120
126
121
127
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" ,
133
128
"pyproject.toml" ,
134
- "setup.cfg" ,
135
- "setup.py" ,
136
129
"LICENSE" ,
137
- "MANIFEST.in" ,
138
130
"README.rst" ,
139
131
"PKG-INFO" ,
140
132
"SECURITY.md" ,
141
133
}
142
134
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
151
162
152
163
153
164
def read_tz_file (tar : tarfile .TarFile , name : str ) -> bytes :
154
- start = tar .getnames ()[0 ] + "/"
165
+ start = tar .getnames ()[0 ]. split ( "/" )[ 0 ] + "/"
155
166
inner_file = tar .extractfile (tar .getmember (f"{ start } { name } " ))
156
167
assert inner_file
157
168
with contextlib .closing (inner_file ) as f :
@@ -176,48 +187,22 @@ def test_build_sdist(monkeypatch, tmpdir):
176
187
version = start [9 :- 1 ]
177
188
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
178
189
179
- setup_py = read_tz_file (tar , "setup.py" )
180
190
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
- )
185
191
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
209
194
210
195
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
213
197
214
198
215
199
def test_build_global_dist (monkeypatch , tmpdir ):
216
200
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
+ )
221
206
222
207
(sdist ,) = tmpdir .visit ("*.tar.gz" )
223
208
@@ -226,38 +211,12 @@ def test_build_global_dist(monkeypatch, tmpdir):
226
211
version = start [16 :- 1 ]
227
212
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
228
213
229
- setup_py = read_tz_file (tar , "setup.py" )
230
214
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
- )
240
215
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
253
218
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
261
220
262
221
263
222
def tests_build_wheel (monkeypatch , tmpdir ):
@@ -288,18 +247,22 @@ def tests_build_wheel(monkeypatch, tmpdir):
288
247
289
248
def tests_build_global_wheel (monkeypatch , tmpdir ):
290
249
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
+ )
296
258
297
259
(wheel ,) = tmpdir .visit ("*.whl" )
298
260
299
- files = {f"data/data/{ n } " for n in src_files }
261
+ files = {f"data/data/{ n } " for n in headers }
300
262
files |= {f"data/headers/{ n [8 :]} " for n in headers }
263
+ files |= {f"data/data/{ n } " for n in generated_files }
301
264
files |= {
302
- "dist-info/LICENSE" ,
265
+ "dist-info/licenses/ LICENSE" ,
303
266
"dist-info/METADATA" ,
304
267
"dist-info/WHEEL" ,
305
268
"dist-info/RECORD" ,
@@ -309,6 +272,7 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
309
272
names = z .namelist ()
310
273
311
274
beginning = names [0 ].split ("/" , 1 )[0 ].rsplit ("." , 1 )[0 ]
275
+ pprint (names )
312
276
trimmed = {n [len (beginning ) + 1 :] for n in names }
313
277
314
278
assert files == trimmed
0 commit comments