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" ,
59
69
"share/cmake/pybind11/pybind11Tools.cmake" ,
60
70
}
61
71
72
+ pkgconfig_files = {
73
+ "share/pkgconfig/pybind11.pc" ,
74
+ }
75
+
62
76
py_files = {
63
77
"__init__.py" ,
64
78
"__main__.py" ,
69
83
}
70
84
71
85
headers = main_headers | detail_headers | stl_headers
72
- src_files = headers | cmake_files
86
+ src_files = headers | cmake_files | pkgconfig_files
73
87
all_files = src_files | py_files
74
88
75
89
82
96
"pybind11/share" ,
83
97
"pybind11/share/cmake" ,
84
98
"pybind11/share/cmake/pybind11" ,
99
+ "pybind11/share/pkgconfig" ,
85
100
"pyproject.toml" ,
86
101
"setup.cfg" ,
87
102
"setup.py" ,
101
116
}
102
117
103
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
+
104
131
def test_build_sdist (monkeypatch , tmpdir ):
105
132
106
133
monkeypatch .chdir (MAIN_DIR )
107
134
108
- out = subprocess .check_output (
109
- [
110
- sys .executable ,
111
- "-m" ,
112
- "build" ,
113
- "--sdist" ,
114
- "--outdir" ,
115
- str (tmpdir ),
116
- ]
135
+ subprocess .run (
136
+ [sys .executable , "-m" , "build" , "--sdist" , f"--outdir={ tmpdir } " ], check = True
117
137
)
118
- if hasattr (out , "decode" ):
119
- out = out .decode ()
120
138
121
139
(sdist ,) = tmpdir .visit ("*.tar.gz" )
122
140
@@ -125,25 +143,17 @@ def test_build_sdist(monkeypatch, tmpdir):
125
143
version = start [9 :- 1 ]
126
144
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
127
145
128
- with contextlib .closing (
129
- tar .extractfile (tar .getmember (start + "setup.py" ))
130
- ) as f :
131
- setup_py = f .read ()
132
-
133
- with contextlib .closing (
134
- tar .extractfile (tar .getmember (start + "pyproject.toml" ))
135
- ) as f :
136
- pyproject_toml = f .read ()
137
-
138
- with contextlib .closing (
139
- tar .extractfile (
140
- tar .getmember (
141
- start + "pybind11/share/cmake/pybind11/pybind11Config.cmake"
142
- )
143
- )
144
- ) as f :
145
- contents = f .read ().decode ("utf8" )
146
- 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
+ )
147
157
148
158
files = {f"pybind11/{ n } " for n in all_files }
149
159
files |= sdist_files
@@ -154,51 +164,47 @@ def test_build_sdist(monkeypatch, tmpdir):
154
164
155
165
with open (os .path .join (MAIN_DIR , "tools" , "setup_main.py.in" ), "rb" ) as f :
156
166
contents = (
157
- string .Template (f .read ().decode ())
167
+ string .Template (f .read ().decode ("utf-8" ))
158
168
.substitute (version = version , extra_cmd = "" )
159
- .encode ()
169
+ .encode ("utf-8" )
160
170
)
161
171
assert setup_py == contents
162
172
163
173
with open (os .path .join (MAIN_DIR , "tools" , "pyproject.toml" ), "rb" ) as f :
164
174
contents = f .read ()
165
175
assert pyproject_toml == contents
166
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
+
167
181
168
182
def test_build_global_dist (monkeypatch , tmpdir ):
169
183
170
184
monkeypatch .chdir (MAIN_DIR )
171
185
monkeypatch .setenv ("PYBIND11_GLOBAL_SDIST" , "1" )
172
- out = subprocess .check_output (
173
- [
174
- sys .executable ,
175
- "-m" ,
176
- "build" ,
177
- "--sdist" ,
178
- "--outdir" ,
179
- str (tmpdir ),
180
- ]
186
+ subprocess .run (
187
+ [sys .executable , "-m" , "build" , "--sdist" , "--outdir" , str (tmpdir )], check = True
181
188
)
182
189
183
- if hasattr (out , "decode" ):
184
- out = out .decode ()
185
-
186
190
(sdist ,) = tmpdir .visit ("*.tar.gz" )
187
191
188
192
with tarfile .open (str (sdist ), "r:gz" ) as tar :
189
193
start = tar .getnames ()[0 ] + "/"
190
194
version = start [16 :- 1 ]
191
195
simpler = {n .split ("/" , 1 )[- 1 ] for n in tar .getnames ()[1 :]}
192
196
193
- with contextlib .closing (
194
- tar .extractfile (tar .getmember (start + "setup.py" ))
195
- ) as f :
196
- 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
+ )
197
203
198
- with contextlib . closing (
199
- tar . extractfile ( tar . getmember ( start + "pyproject.toml" ))
200
- ) as f :
201
- pyproject_toml = f . read ( )
204
+ assert (
205
+ 'set(pybind11_INCLUDE_DIR "${PACKAGE_PREFIX_DIR}/include")'
206
+ in cmake_cfg . decode ( "utf-8" )
207
+ )
202
208
203
209
files = {f"pybind11/{ n } " for n in all_files }
204
210
files |= sdist_files
@@ -209,20 +215,24 @@ def test_build_global_dist(monkeypatch, tmpdir):
209
215
contents = (
210
216
string .Template (f .read ().decode ())
211
217
.substitute (version = version , extra_cmd = "" )
212
- .encode ()
218
+ .encode ("utf-8" )
213
219
)
214
220
assert setup_py == contents
215
221
216
222
with open (os .path .join (MAIN_DIR , "tools" , "pyproject.toml" ), "rb" ) as f :
217
223
contents = f .read ()
218
224
assert pyproject_toml == contents
219
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
+
220
230
221
231
def tests_build_wheel (monkeypatch , tmpdir ):
222
232
monkeypatch .chdir (MAIN_DIR )
223
233
224
- subprocess .check_output (
225
- [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )]
234
+ subprocess .run (
235
+ [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )], check = True
226
236
)
227
237
228
238
(wheel ,) = tmpdir .visit ("*.whl" )
@@ -249,8 +259,8 @@ def tests_build_global_wheel(monkeypatch, tmpdir):
249
259
monkeypatch .chdir (MAIN_DIR )
250
260
monkeypatch .setenv ("PYBIND11_GLOBAL_SDIST" , "1" )
251
261
252
- subprocess .check_output (
253
- [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )]
262
+ subprocess .run (
263
+ [sys .executable , "-m" , "pip" , "wheel" , "." , "-w" , str (tmpdir )], check = True
254
264
)
255
265
256
266
(wheel ,) = tmpdir .visit ("*.whl" )
0 commit comments