12
12
DIR = os .path .abspath (os .path .dirname (__file__ ))
13
13
MAIN_DIR = os .path .dirname (os .path .dirname (DIR ))
14
14
15
+ PKGCONFIG = """\
16
+ prefix=${{pcfiledir}}/../../
17
+ includedir=${{prefix}}/include
18
+
19
+ Name: pybind11
20
+ Description: Seamless operability between C++11 and Python
21
+ Version: {VERSION}
22
+ Cflags: -I${{includedir}}
23
+ """
24
+
15
25
16
26
main_headers = {
17
27
"include/pybind11/attr.h" ,
106
116
}
107
117
108
118
119
+ def read_tz_file (tar : tarfile .TarFile , name : str ) -> bytes :
120
+ start = tar .getnames ()[0 ] + "/"
121
+ inner_file = tar .extractfile (tar .getmember (f"{ start } { name } " ))
122
+ assert inner_file
123
+ with contextlib .closing (inner_file ) as f :
124
+ return f .read ()
125
+
126
+
127
+ def normalize_line_endings (value : bytes ) -> bytes :
128
+ return value .replace (os .linesep .encode ("utf-8" ), b"\n " )
129
+
130
+
109
131
def test_build_sdist (monkeypatch , tmpdir ):
110
132
111
133
monkeypatch .chdir (MAIN_DIR )
112
134
113
- out = subprocess .check_output (
114
- [
115
- sys .executable ,
116
- "-m" ,
117
- "build" ,
118
- "--sdist" ,
119
- "--outdir" ,
120
- str (tmpdir ),
121
- ]
135
+ subprocess .run (
136
+ [sys .executable , "-m" , "build" , "--sdist" , f"--outdir={ tmpdir } " ], check = True
122
137
)
123
- if hasattr (out , "decode" ):
124
- out = out .decode ()
125
138
126
139
(sdist ,) = tmpdir .visit ("*.tar.gz" )
127
140
@@ -130,25 +143,17 @@ def test_build_sdist(monkeypatch, tmpdir):
130
143
version = start [9 :- 1 ]
131
144
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
132
145
133
- with contextlib .closing (
134
- tar .extractfile (tar .getmember (start + "setup.py" ))
135
- ) as f :
136
- setup_py = f .read ()
137
-
138
- with contextlib .closing (
139
- tar .extractfile (tar .getmember (start + "pyproject.toml" ))
140
- ) as f :
141
- pyproject_toml = f .read ()
142
-
143
- with contextlib .closing (
144
- tar .extractfile (
145
- tar .getmember (
146
- start + "pybind11/share/cmake/pybind11/pybind11Config.cmake"
147
- )
148
- )
149
- ) as f :
150
- contents = f .read ().decode ("utf8" )
151
- assert 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")' in contents
146
+ setup_py = read_tz_file (tar , "setup.py" )
147
+ pyproject_toml = read_tz_file (tar , "pyproject.toml" )
148
+ pkgconfig = read_tz_file (tar , "pybind11/share/pkgconfig/pybind11.pc" )
149
+ cmake_cfg = read_tz_file (
150
+ tar , "pybind11/share/cmake/pybind11/pybind11Config.cmake"
151
+ )
152
+
153
+ assert (
154
+ 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
155
+ in cmake_cfg .decode ("utf-8" )
156
+ )
152
157
153
158
files = {f"pybind11/{ n } " for n in all_files }
154
159
files |= sdist_files
@@ -159,51 +164,47 @@ def test_build_sdist(monkeypatch, tmpdir):
159
164
160
165
with open (os .path .join (MAIN_DIR , "tools" , "setup_main.py.in" ), "rb" ) as f :
161
166
contents = (
162
- string .Template (f .read ().decode ())
167
+ string .Template (f .read ().decode ("utf-8" ))
163
168
.substitute (version = version , extra_cmd = "" )
164
- .encode ()
169
+ .encode ("utf-8" )
165
170
)
166
171
assert setup_py == contents
167
172
168
173
with open (os .path .join (MAIN_DIR , "tools" , "pyproject.toml" ), "rb" ) as f :
169
174
contents = f .read ()
170
175
assert pyproject_toml == contents
171
176
177
+ simple_version = "." .join (version .split ("." )[:3 ])
178
+ pkgconfig_expected = PKGCONFIG .format (VERSION = simple_version ).encode ("utf-8" )
179
+ assert normalize_line_endings (pkgconfig ) == pkgconfig_expected
180
+
172
181
173
182
def test_build_global_dist (monkeypatch , tmpdir ):
174
183
175
184
monkeypatch .chdir (MAIN_DIR )
176
185
monkeypatch .setenv ("PYBIND11_GLOBAL_SDIST" , "1" )
177
- out = subprocess .check_output (
178
- [
179
- sys .executable ,
180
- "-m" ,
181
- "build" ,
182
- "--sdist" ,
183
- "--outdir" ,
184
- str (tmpdir ),
185
- ]
186
+ subprocess .run (
187
+ [sys .executable , "-m" , "build" , "--sdist" , "--outdir" , str (tmpdir )], check = True
186
188
)
187
189
188
- if hasattr (out , "decode" ):
189
- out = out .decode ()
190
-
191
190
(sdist ,) = tmpdir .visit ("*.tar.gz" )
192
191
193
192
with tarfile .open (str (sdist ), "r:gz" ) as tar :
194
193
start = tar .getnames ()[0 ] + "/"
195
194
version = start [16 :- 1 ]
196
195
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
197
196
198
- with contextlib .closing (
199
- tar .extractfile (tar .getmember (start + "setup.py" ))
200
- ) as f :
201
- setup_py = f .read ()
197
+ setup_py = read_tz_file (tar , "setup.py" )
198
+ pyproject_toml = read_tz_file (tar , "pyproject.toml" )
199
+ pkgconfig = read_tz_file (tar , "pybind11/share/pkgconfig/pybind11.pc" )
200
+ cmake_cfg = read_tz_file (
201
+ tar , "pybind11/share/cmake/pybind11/pybind11Config.cmake"
202
+ )
202
203
203
- with contextlib . closing (
204
- tar . extractfile ( tar . getmember ( start + "pyproject.toml" ))
205
- ) as f :
206
- pyproject_toml = f . read ( )
204
+ assert (
205
+ 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
206
+ in cmake_cfg . decode ( "utf-8" )
207
+ )
207
208
208
209
files = {f"pybind11/{ n } " for n in all_files }
209
210
files |= sdist_files
@@ -214,20 +215,24 @@ def test_build_global_dist(monkeypatch, tmpdir):
214
215
contents = (
215
216
string .Template (f .read ().decode ())
216
217
.substitute (version = version , extra_cmd = "" )
217
- .encode ()
218
+ .encode ("utf-8" )
218
219
)
219
220
assert setup_py == contents
220
221
221
222
with open (os .path .join (MAIN_DIR , "tools" , "pyproject.toml" ), "rb" ) as f :
222
223
contents = f .read ()
223
224
assert pyproject_toml == contents
224
225
226
+ simple_version = "." .join (version .split ("." )[:3 ])
227
+ pkgconfig_expected = PKGCONFIG .format (VERSION = simple_version ).encode ("utf-8" )
228
+ assert normalize_line_endings (pkgconfig ) == pkgconfig_expected
229
+
225
230
226
231
def tests_build_wheel (monkeypatch , tmpdir ):
227
232
monkeypatch .chdir (MAIN_DIR )
228
233
229
- subprocess .check_output (
230
- [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )]
234
+ subprocess .run (
235
+ [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )], check = True
231
236
)
232
237
233
238
(wheel ,) = tmpdir .visit ("*.whl" )
@@ -254,8 +259,8 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
254
259
monkeypatch .chdir (MAIN_DIR )
255
260
monkeypatch .setenv ("PYBIND11_GLOBAL_SDIST" , "1" )
256
261
257
- subprocess .check_output (
258
- [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )]
262
+ subprocess .run (
263
+ [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )], check = True
259
264
)
260
265
261
266
(wheel ,) = tmpdir .visit ("*.whl" )
0 commit comments