Skip to content

Commit e2cf2a8

Browse files
committed
refactor: use build-backend instead
1 parent d04407b commit e2cf2a8

File tree

7 files changed

+88
-67
lines changed

7 files changed

+88
-67
lines changed

cibuildwheel/__main__.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
Unbuffered,
2828
detect_ci_provider,
2929
resources_dir,
30-
strtobool,
3130
)
3231

3332
MANYLINUX_ARCHS = (
@@ -41,6 +40,8 @@
4140
"pypy_i686",
4241
)
4342

43+
BUILD_FRONTENDS = {"pip", "build"}
44+
4445

4546
def main() -> None:
4647
platform: PlatformName
@@ -182,10 +183,10 @@ def main() -> None:
182183
build_config = options("build", env_plat=False, sep=" ") or "*"
183184
skip_config = options("skip", env_plat=False, sep=" ")
184185
test_skip = options("test-skip", env_plat=False, sep=" ")
185-
pypa_build = strtobool(os.environ.get("CIBW_PYPA_BUILD", "0"))
186186

187187
archs_config_str = args.archs or options("archs", sep=" ")
188188

189+
build_frontend = options("build-frontend", env_plat=False)
189190
environment_config = options("environment", table={"item": '{k}="{v}"', "sep": " "})
190191
before_all = options("before-all", sep=" && ")
191192
before_build = options("before-build", sep=" && ")
@@ -202,6 +203,11 @@ def main() -> None:
202203
os.environ.get("CIBW_PRERELEASE_PYTHONS", "0")
203204
)
204205

206+
if build_frontend not in BUILD_FRONTENDS:
207+
msg = f"cibuildwheel: Unrecognised build front end '{build_frontend}', only {BUILD_FRONTENDS} supported"
208+
print(msg, file=sys.stderr)
209+
sys.exit(2)
210+
205211
package_files = {"setup.py", "setup.cfg", "pyproject.toml"}
206212

207213
if not any(package_dir.joinpath(name).exists() for name in package_files):
@@ -310,7 +316,7 @@ def main() -> None:
310316
environment=environment,
311317
dependency_constraints=dependency_constraints,
312318
manylinux_images=manylinux_images or None,
313-
pypa_build=pypa_build,
319+
build_frontend=build_frontend,
314320
)
315321

316322
# Python is buffering by default when running on the CI platforms, giving problems interleaving subprocess call output with unflushed calls to 'print'

cibuildwheel/linux.py

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,34 +182,38 @@ def build(options: BuildOptions) -> None:
182182

183183
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
184184

185-
if options.pypa_build:
186-
config_setting = " ".join(verbosity_flags)
185+
if options.build_frontend == "pip":
187186
docker.call(
188187
[
189188
"python",
190189
"-m",
191-
"build",
190+
"pip",
191+
"wheel",
192192
container_package_dir,
193-
"--wheel",
194-
f"--outdir={built_wheel_dir}",
195-
f"--config-setting={config_setting}",
193+
f"--wheel-dir={built_wheel_dir}",
194+
"--no-deps",
195+
*verbosity_flags,
196196
],
197197
env=env,
198198
)
199-
else:
199+
elif options.build_frontend == "build":
200+
config_setting = " ".join(verbosity_flags)
200201
docker.call(
201202
[
202203
"python",
203204
"-m",
204-
"pip",
205-
"wheel",
205+
"build",
206206
container_package_dir,
207-
f"--wheel-dir={built_wheel_dir}",
208-
"--no-deps",
209-
*verbosity_flags,
207+
"--wheel",
208+
f"--outdir={built_wheel_dir}",
209+
f"--config-setting={config_setting}",
210210
],
211211
env=env,
212212
)
213+
else:
214+
raise RuntimeError(
215+
f"build_frontend {options.build_frontend!r} not understood"
216+
)
213217

214218
built_wheel = docker.glob(built_wheel_dir, "*.whl")[0]
215219

cibuildwheel/macos.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def setup_python(
179179
python_configuration: PythonConfiguration,
180180
dependency_constraint_flags: Sequence[PathOrStr],
181181
environment: ParsedEnvironment,
182-
pypa_build: bool,
182+
build_frontend: str,
183183
) -> Dict[str, str]:
184184

185185
implementation_id = python_configuration.identifier.split("-")[0]
@@ -311,31 +311,33 @@ def setup_python(
311311
env.setdefault("SDKROOT", arm64_compatible_sdks[0])
312312

313313
log.step("Installing build tools...")
314-
if pypa_build:
314+
if build_frontend == "pip":
315315
call(
316316
[
317317
"pip",
318318
"install",
319319
"--upgrade",
320+
"setuptools",
321+
"wheel",
320322
"delocate",
321-
"build[virtualenv]",
322323
*dependency_constraint_flags,
323324
],
324325
env=env,
325326
)
326-
else:
327+
elif build_frontend == "build":
327328
call(
328329
[
329330
"pip",
330331
"install",
331332
"--upgrade",
332-
"setuptools",
333-
"wheel",
334333
"delocate",
334+
"build[virtualenv]",
335335
*dependency_constraint_flags,
336336
],
337337
env=env,
338338
)
339+
else:
340+
raise RuntimeError(f"build_frontend {build_frontend!r} not understood")
339341

340342
return env
341343

@@ -376,7 +378,7 @@ def build(options: BuildOptions) -> None:
376378
config,
377379
dependency_constraint_flags,
378380
options.environment,
379-
options.pypa_build,
381+
options.build_frontend,
380382
)
381383

382384
if options.before_build:
@@ -393,7 +395,23 @@ def build(options: BuildOptions) -> None:
393395

394396
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
395397

396-
if options.pypa_build:
398+
if options.build_frontend == "pip":
399+
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
400+
# see https://github.com/pypa/cibuildwheel/pull/369
401+
call(
402+
[
403+
"python",
404+
"-m",
405+
"pip",
406+
"wheel",
407+
options.package_dir.resolve(),
408+
f"--wheel-dir={built_wheel_dir}",
409+
"--no-deps",
410+
*verbosity_flags,
411+
],
412+
env=env,
413+
)
414+
elif options.build_frontend == "build":
397415
config_setting = " ".join(verbosity_flags)
398416
build_env = dict(env)
399417
if options.dependency_constraints:
@@ -414,21 +432,7 @@ def build(options: BuildOptions) -> None:
414432
env=build_env,
415433
)
416434
else:
417-
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
418-
# see https://github.com/pypa/cibuildwheel/pull/369
419-
call(
420-
[
421-
"python",
422-
"-m",
423-
"pip",
424-
"wheel",
425-
options.package_dir.resolve(),
426-
f"--wheel-dir={built_wheel_dir}",
427-
"--no-deps",
428-
*verbosity_flags,
429-
],
430-
env=env,
431-
)
435+
raise RuntimeError(f"build_frontend {options.build_frontend!r} not understood")
432436

433437
built_wheel = next(built_wheel_dir.glob("*.whl"))
434438

cibuildwheel/resources/defaults.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ skip = ""
44
test-skip = ""
55

66
archs = ["auto"]
7+
build-frontend = "pip"
78
dependency-versions = "pinned"
89
environment = {}
910
build-verbosity = ""

cibuildwheel/util.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ class BuildOptions(NamedTuple):
220220
test_requires: List[str]
221221
test_extras: str
222222
build_verbosity: int
223-
pypa_build: bool
223+
build_frontend: str
224224

225225

226226
class NonPlatformWheelError(Exception):
@@ -312,9 +312,9 @@ def get_pip_version(env: Dict[str, str]) -> str:
312312
versions_output_text = subprocess.check_output(
313313
["python", "-m", "pip", "freeze", "--all"], universal_newlines=True, shell=shell, env=env
314314
)
315-
(pip_version,) = [
315+
(pip_version,) = (
316316
version[5:]
317317
for version in versions_output_text.strip().splitlines()
318318
if version.startswith("pip==")
319-
]
319+
)
320320
return pip_version

cibuildwheel/windows.py

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def setup_python(
115115
python_configuration: PythonConfiguration,
116116
dependency_constraint_flags: Sequence[PathOrStr],
117117
environment: ParsedEnvironment,
118-
pypa_build: bool,
118+
build_frontend: str,
119119
) -> Dict[str, str]:
120120

121121
nuget = Path("C:\\cibw\\nuget.exe")
@@ -218,12 +218,7 @@ def setup_python(
218218

219219
call(["pip", "--version"], env=env)
220220

221-
if pypa_build:
222-
call(
223-
["pip", "install", "--upgrade", "build[virtualenv]", *dependency_constraint_flags],
224-
env=env,
225-
)
226-
else:
221+
if build_frontend == "pip":
227222
call(
228223
[
229224
"pip",
@@ -235,6 +230,13 @@ def setup_python(
235230
],
236231
env=env,
237232
)
233+
elif build_frontend == "build":
234+
call(
235+
["pip", "install", "--upgrade", "build[virtualenv]", *dependency_constraint_flags],
236+
env=env,
237+
)
238+
else:
239+
raise RuntimeError(f"build_frontend {build_frontend!r} not understood")
238240

239241
return env
240242

@@ -272,7 +274,7 @@ def build(options: BuildOptions) -> None:
272274
config,
273275
dependency_constraint_flags,
274276
options.environment,
275-
options.pypa_build,
277+
options.build_frontend,
276278
)
277279

278280
# run the before_build command
@@ -290,7 +292,23 @@ def build(options: BuildOptions) -> None:
290292

291293
verbosity_flags = get_build_verbosity_extra_flags(options.build_verbosity)
292294

293-
if options.pypa_build:
295+
if options.build_frontend == "pip":
296+
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
297+
# see https://github.com/pypa/cibuildwheel/pull/369
298+
call(
299+
[
300+
"python",
301+
"-m",
302+
"pip",
303+
"wheel",
304+
options.package_dir.resolve(),
305+
f"--wheel-dir={built_wheel_dir}",
306+
"--no-deps",
307+
*get_build_verbosity_extra_flags(options.build_verbosity),
308+
],
309+
env=env,
310+
)
311+
elif options.build_frontend == "build":
294312
config_setting = " ".join(verbosity_flags)
295313
build_env = dict(env)
296314
if options.dependency_constraints:
@@ -311,21 +329,7 @@ def build(options: BuildOptions) -> None:
311329
env=build_env,
312330
)
313331
else:
314-
# Path.resolve() is needed. Without it pip wheel may try to fetch package from pypi.org
315-
# see https://github.com/pypa/cibuildwheel/pull/369
316-
call(
317-
[
318-
"python",
319-
"-m",
320-
"pip",
321-
"wheel",
322-
options.package_dir.resolve(),
323-
f"--wheel-dir={built_wheel_dir}",
324-
"--no-deps",
325-
*get_build_verbosity_extra_flags(options.build_verbosity),
326-
],
327-
env=env,
328-
)
332+
raise RuntimeError(f"build_frontend {options.build_frontend!r} not understood")
329333

330334
built_wheel = next(built_wheel_dir.glob("*.whl"))
331335

test/conftest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def pytest_collection_modifyitems(config, items) -> None:
2323
item.add_marker(skip_emulation)
2424

2525

26-
@pytest.fixture(params=[{"CIBW_PYPA_BUILD": "0"}, {"CIBW_PYPA_BUILD": "1"}], ids=["pip", "pypa"])
26+
@pytest.fixture(
27+
params=[{"CIBW_BUILD_FRONTEND": "pip"}, {"CIBW_BUILD_FRONTEND": "build"}], ids=["pip", "build"]
28+
)
2729
def build_mode(request) -> Dict[str, str]:
28-
return request.param
30+
return request.param # type: ignore

0 commit comments

Comments
 (0)