Skip to content

Commit e2c5f24

Browse files
committed
feat: adding enable
Signed-off-by: Henry Schreiner <[email protected]>
1 parent e18a6e9 commit e2c5f24

File tree

9 files changed

+189
-94
lines changed

9 files changed

+189
-94
lines changed

bin/generate_schema.py

+15
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@
2626
- append
2727
default: none
2828
description: How to inherit the parent's value.
29+
enable:
30+
enum:
31+
- cpython-free-threaded
32+
- cpython-prerelease
33+
- pypy
34+
description: A Python version or flavor to enable.
2935
additionalProperties: false
3036
description: cibuildwheel's settings.
3137
type: object
@@ -99,6 +105,13 @@
99105
default: pinned
100106
description: Specify how cibuildwheel controls the versions of the tools it uses
101107
type: string
108+
enable:
109+
description: Enable or disable certain builds.
110+
oneOf:
111+
- $ref: "#/$defs/enable"
112+
- type: array
113+
items:
114+
$ref: "#/$defs/enable"
102115
environment:
103116
description: Set environment variables needed during the build.
104117
type: string_table
@@ -110,6 +123,7 @@
110123
type: boolean
111124
default: false
112125
description: The project supports free-threaded builds of Python (PEP703)
126+
deprecated: Use the `enable` option instead.
113127
manylinux-aarch64-image:
114128
type: string
115129
description: Specify alternative manylinux / musllinux container images
@@ -261,6 +275,7 @@
261275
del non_global_options["skip"]
262276
del non_global_options["test-skip"]
263277
del non_global_options["free-threaded-support"]
278+
del non_global_options["enable"]
264279

265280
overrides["items"]["properties"]["select"]["oneOf"] = string_array
266281
overrides["items"]["properties"] |= non_global_options.copy()

cibuildwheel/options.py

+29-8
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
BuildFrontendConfig,
3131
BuildSelector,
3232
DependencyConstraints,
33+
EnableGroups,
3334
TestSelector,
3435
format_safe,
3536
resources_dir,
@@ -512,6 +513,7 @@ def get(
512513
env_plat: bool = True,
513514
option_format: OptionFormat | None = None,
514515
ignore_empty: bool = False,
516+
env_rule: InheritRule = InheritRule.NONE,
515517
) -> str:
516518
"""
517519
Get and return the value for the named option from environment,
@@ -543,8 +545,8 @@ def get(
543545
(o.options.get(name), o.inherit.get(name, InheritRule.NONE))
544546
for o in self.active_config_overrides
545547
],
546-
(self.env.get(envvar), InheritRule.NONE),
547-
(self.env.get(plat_envvar) if env_plat else None, InheritRule.NONE),
548+
(self.env.get(envvar), env_rule),
549+
(self.env.get(plat_envvar) if env_plat else None, env_rule),
548550
ignore_empty=ignore_empty,
549551
option_format=option_format,
550552
)
@@ -608,16 +610,37 @@ def globals(self) -> GlobalOptions:
608610
skip_config = self.reader.get("skip", env_plat=False, option_format=ListFormat(sep=" "))
609611
test_skip = self.reader.get("test-skip", env_plat=False, option_format=ListFormat(sep=" "))
610612

613+
allow_empty = args.allow_empty or strtobool(self.env.get("CIBW_ALLOW_EMPTY", "0"))
614+
615+
enable_groups = self.reader.get(
616+
"enable", env_plat=False, option_format=ListFormat(sep=" "), env_rule=InheritRule.APPEND
617+
)
618+
enable = {EnableGroups(group) for group in enable_groups.split()}
619+
611620
free_threaded_support = strtobool(
612621
self.reader.get("free-threaded-support", env_plat=False, ignore_empty=True)
613622
)
614623

615-
allow_empty = args.allow_empty or strtobool(self.env.get("CIBW_ALLOW_EMPTY", "0"))
616-
617624
prerelease_pythons = args.prerelease_pythons or strtobool(
618625
self.env.get("CIBW_PRERELEASE_PYTHONS", "0")
619626
)
620627

628+
if free_threaded_support or prerelease_pythons:
629+
msg = (
630+
"free-threaded-support and prerelease-pythons should be specified by enable instead"
631+
)
632+
if enable:
633+
raise OptionsReaderError(msg)
634+
log.warning(msg)
635+
636+
if free_threaded_support:
637+
enable.add(EnableGroups.CPythonFreeThreaded)
638+
if prerelease_pythons:
639+
enable.add(EnableGroups.CPythonPrerelease)
640+
641+
# For backwards compatibility, we are adding PyPy for now
642+
enable |= {EnableGroups.PyPy}
643+
621644
# This is not supported in tool.cibuildwheel, as it comes from a standard location.
622645
# Passing this in as an environment variable will override pyproject.toml, setup.cfg, or setup.py
623646
requires_python_str: str | None = (
@@ -633,15 +656,13 @@ def globals(self) -> GlobalOptions:
633656
build_config = args.only
634657
skip_config = ""
635658
architectures = Architecture.all_archs(self.platform)
636-
prerelease_pythons = True
637-
free_threaded_support = True
659+
enable = set(EnableGroups)
638660

639661
build_selector = BuildSelector(
640662
build_config=build_config,
641663
skip_config=skip_config,
642664
requires_python=requires_python,
643-
prerelease_pythons=prerelease_pythons,
644-
free_threaded_support=free_threaded_support,
665+
enable=frozenset(enable),
645666
)
646667
test_selector = TestSelector(skip_config=test_skip)
647668

cibuildwheel/resources/cibuildwheel.schema.json

+25-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,16 @@
1010
],
1111
"default": "none",
1212
"description": "How to inherit the parent's value."
13-
}
13+
},
14+
"enable": {
15+
"enum": [
16+
"cpython-eol",
17+
"cpython-free-threaded",
18+
"cpython-prerelease",
19+
"pypy-eol"
20+
]
21+
},
22+
"description": "A Python version or flavor to enable."
1423
},
1524
"additionalProperties": false,
1625
"description": "cibuildwheel's settings.",
@@ -228,6 +237,21 @@
228237
"type": "string",
229238
"title": "CIBW_DEPENDENCY_VERSIONS"
230239
},
240+
"enable": {
241+
"description": "Enable or disable certain builds.",
242+
"oneOf": [
243+
{
244+
"$ref": "#/$defs/enable"
245+
},
246+
{
247+
"type": "array",
248+
"items": {
249+
"$ref": "#/$defs/enable"
250+
}
251+
}
252+
],
253+
"title": "CIBW_ENABLE"
254+
},
231255
"environment": {
232256
"description": "Set environment variables needed during the build.",
233257
"oneOf": [

cibuildwheel/resources/defaults.toml

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ build = "*"
33
skip = ""
44
test-skip = ""
55
free-threaded-support = false
6+
enable = []
67

78
archs = ["auto"]
89
build-frontend = "default"

cibuildwheel/util.py

+24-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22

33
import contextlib
4+
import enum
45
import fnmatch
56
import itertools
67
import os
@@ -23,7 +24,7 @@
2324
from pathlib import Path, PurePath
2425
from tempfile import TemporaryDirectory
2526
from time import sleep
26-
from typing import Any, ClassVar, Final, Literal, TextIO, TypeVar
27+
from typing import Any, Final, Literal, TextIO, TypeVar
2728
from zipfile import ZipFile
2829

2930
import bracex
@@ -41,6 +42,7 @@
4142

4243
__all__ = [
4344
"MANYLINUX_ARCHS",
45+
"EnableGroups",
4446
"call",
4547
"chdir",
4648
"combine_constraints",
@@ -66,6 +68,16 @@
6668
test_fail_cwd_file: Final[Path] = resources_dir / "testing_temp_dir_file.py"
6769

6870

71+
class EnableGroups(enum.Enum):
72+
"""
73+
Groups of build selectors that are not enabled by default.
74+
"""
75+
76+
CPythonFreeThreaded = "cpython-free-threaded"
77+
CPythonPrerelease = "cpython-prerelease"
78+
PyPy = "pypy"
79+
80+
6981
MANYLINUX_ARCHS: Final[tuple[str, ...]] = (
7082
"x86_64",
7183
"i686",
@@ -247,12 +259,7 @@ class BuildSelector:
247259
build_config: str
248260
skip_config: str
249261
requires_python: SpecifierSet | None = None
250-
251-
# a pattern that skips prerelease versions, when include_prereleases is False.
252-
PRERELEASE_SKIP: ClassVar[str] = ""
253-
prerelease_pythons: bool = False
254-
255-
free_threaded_support: bool = False
262+
enable: frozenset[EnableGroups] = frozenset()
256263

257264
def __call__(self, build_id: str) -> bool:
258265
# Filter build selectors by python_requires if set
@@ -266,12 +273,16 @@ def __call__(self, build_id: str) -> bool:
266273
if not self.requires_python.contains(version):
267274
return False
268275

269-
# filter out the prerelease pythons if self.prerelease_pythons is False
270-
if not self.prerelease_pythons and selector_matches(self.PRERELEASE_SKIP, build_id):
276+
# filter out groups that are not enabled
277+
if EnableGroups.CPythonFreeThreaded not in self.enable and selector_matches(
278+
"cp3??t-*", build_id
279+
):
271280
return False
272-
273-
# filter out free threaded pythons if self.free_threaded_support is False
274-
if not self.free_threaded_support and selector_matches("*t-*", build_id):
281+
if EnableGroups.CPythonPrerelease not in self.enable and selector_matches(
282+
"cp314*", build_id
283+
):
284+
return False
285+
if EnableGroups.PyPy not in self.enable and selector_matches("pp*", build_id):
275286
return False
276287

277288
should_build = selector_matches(self.build_config, build_id)
@@ -284,8 +295,7 @@ def options_summary(self) -> Any:
284295
"build_config": self.build_config,
285296
"skip_config": self.skip_config,
286297
"requires_python": str(self.requires_python),
287-
"prerelease_pythons": self.prerelease_pythons,
288-
"free_threaded_support": self.free_threaded_support,
298+
"enable": sorted(group.value for group in self.enable),
289299
}
290300

291301

0 commit comments

Comments
 (0)