Skip to content

Commit 04c9427

Browse files
authored
Test enable groups as specified by PR labels (pypa#2357)
* Allow CIBW_ENABLE to control the wheels built in testing * Set CIBW_ENABLE using PR labels * Add docs * Build everything on the main branch * Add CIBW_ENABLE=all option This was mostly for use in the `main` building case, because otherwise it's maybe a bit too easy to forget to update this file when adding an enable group * Remove dead code * Make unit tests robust to the value of CIBW_ENABLE * Fix tests that explicitly choose pypy * Fix test expectation * Don't expect impossible wheels in expected_wheels * Simplify logic in expected_wheels * CircleCI- run with CIBW_ENABLE=all only on the main branch * Azure pipelines - run with CIBW_ENABLE=all on main branch * Update gitlab to run CIBW_ENABLE=all on main * Set CIBW_ENABLE=all on travis - it only runs on main anyway * Fix job name error on CircleCI * Fix tests for graalpy * Update the test configuration to use the label * Remove duplication of default value. Make it affect sample build too * Move the action to after deps are installed * GraalPy workaround for this assumption * Make unit test resilient to changing CIBW_ENABLE
1 parent edbd234 commit 04c9427

File tree

15 files changed

+204
-82
lines changed

15 files changed

+204
-82
lines changed

.circleci/config.yml

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
version: 2
1+
version: 2.1
2+
3+
commands:
4+
cibw_prepare_environment:
5+
description: "Prepare the environment for testing."
6+
steps:
7+
- run:
8+
name: Prepare the environment.
9+
command: bash .circleci/prepare.sh
10+
cibw_run_tests:
11+
description: "Runs tests, with CIBW_ENABLE=all on the main branch"
12+
steps:
13+
- run:
14+
name: Test
15+
command: |
16+
if [ "${CIRCLE_BRANCH}" == "main" ]; then
17+
echo "INFO: Exporting CIBW_ENABLE=all for main branch test run."
18+
export CIBW_ENABLE=all
19+
else
20+
echo "INFO: CIBW_ENABLE not set for this branch test run."
21+
fi
22+
23+
venv/bin/python ./bin/run_tests.py
24+
no_output_timeout: 30m
225

326
jobs:
4-
osx-python3.12:
27+
osx-python312:
528
macos:
629
xcode: 15.4.0
730
resource_class: macos.m1.medium.gen1
831
environment:
932
PYTHON: python3
1033
steps:
1134
- checkout
35+
- cibw_prepare_environment
36+
- cibw_run_tests
1237

13-
- run:
14-
name: Prepare the environment.
15-
command: bash .circleci/prepare.sh
16-
- run:
17-
name: Test.
18-
command: venv/bin/python ./bin/run_tests.py
19-
no_output_timeout: 30m
20-
21-
linux-python3.12:
38+
linux-python312:
2239
docker:
2340
- image: cimg/python:3.12
2441
environment:
@@ -29,14 +46,8 @@ jobs:
2946
steps:
3047
- checkout
3148
- setup_remote_docker
32-
33-
- run:
34-
name: Prepare the environment.
35-
command: bash .circleci/prepare.sh
36-
- run:
37-
name: Test.
38-
command: venv/bin/python ./bin/run_tests.py
39-
no_output_timeout: 30m
49+
- cibw_prepare_environment
50+
- cibw_run_tests
4051

4152
linux-aarch64:
4253
machine:
@@ -49,19 +60,13 @@ jobs:
4960
PYTEST_ADDOPTS: -k "unit_test or main_tests or test_0_basic or test_docker_images"
5061
steps:
5162
- checkout
52-
53-
- run:
54-
name: Prepare the environment.
55-
command: bash .circleci/prepare.sh
56-
- run:
57-
name: Test.
58-
command: venv/bin/python ./bin/run_tests.py
59-
no_output_timeout: 30m
63+
- cibw_prepare_environment
64+
- cibw_run_tests
6065

6166
workflows:
6267
version: 2
6368
all-tests:
6469
jobs:
65-
- osx-python3.12
66-
- linux-python3.12
70+
- osx-python312
71+
- linux-python312
6772
- linux-aarch64

.github/workflows/test.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ on:
66
- main
77
- 2.x
88
pull_request:
9+
types:
10+
- opened
11+
- synchronize
12+
- reopened
13+
- labeled
914
paths-ignore:
1015
- 'docs/**'
1116
- .pre-commit-config.yaml
@@ -68,6 +73,26 @@ jobs:
6873
run: |
6974
uv sync --no-dev --group test
7075
76+
- uses: joerick/pr-labels-action@v1.0.9
77+
- name: Set CIBW_ENABLE
78+
shell: bash
79+
run: |
80+
if [[ "${{ github.ref_name }}" == "main" ]]; then
81+
CIBW_ENABLE=all
82+
else
83+
# get the default CIBW_ENABLE value from the test module
84+
CIBW_ENABLE=$(uv run --no-sync python -c 'import sys, test.conftest as c; sys.stdout.write(c.DEFAULT_CIBW_ENABLE)')
85+
86+
# if this is a PR, check for labels
87+
if [[ -n "$GITHUB_PR_LABEL_CI_PYPY" ]]; then
88+
CIBW_ENABLE+=" pypy"
89+
fi
90+
if [[ -n "$GITHUB_PR_LABEL_CI_GRAALPY" ]]; then
91+
CIBW_ENABLE+=" graalpy"
92+
fi
93+
fi
94+
echo "CIBW_ENABLE=${CIBW_ENABLE}" >> $GITHUB_ENV
95+
7196
- name: Generate a sample project
7297
run: |
7398
uv run --no-sync -m test.test_projects test.test_0_basic.basic_project sample_proj
@@ -80,7 +105,6 @@ jobs:
80105
env:
81106
CIBW_ARCHS_MACOS: x86_64 universal2 arm64
82107
CIBW_BUILD_FRONTEND: 'build[uv]'
83-
CIBW_ENABLE: "cpython-prerelease cpython-freethreading pypy graalpy"
84108

85109
- name: Run a sample build (GitHub Action, only)
86110
uses: ./

.gitlab-ci.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ linux:
1313
# skip all but the basic tests
1414
# (comment the below line in a PR to debug a Gitlab-specific issue)
1515
PYTEST_ADDOPTS: -k "unit_test or test_0_basic" --suppress-no-test-exit-code
16+
rules:
17+
- if: '$CI_COMMIT_BRANCH == "main"'
18+
variables:
19+
CIBW_ENABLE: "all"
1620
script:
1721
- curl -sSL https://get.docker.com/ | sh
1822
- docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
@@ -26,6 +30,10 @@ windows:
2630
PYTEST_ADDOPTS: -k "unit_test or test_0_basic" --suppress-no-test-exit-code
2731
before_script:
2832
- choco install python -y --version 3.12.4
33+
rules:
34+
- if: '$CI_COMMIT_BRANCH == "main"'
35+
variables:
36+
CIBW_ENABLE: "all"
2937
script:
3038
- py -m pip install dependency-groups
3139
- py -m pip install -e. pytest-custom-exit-code $(py -m dependency_groups test)
@@ -37,6 +45,10 @@ macos:
3745
image: macos-14-xcode-15
3846
variables:
3947
PYTEST_ADDOPTS: -k "unit_test or test_0_basic" --suppress-no-test-exit-code
48+
rules:
49+
- if: '$CI_COMMIT_BRANCH == "main"'
50+
variables:
51+
CIBW_ENABLE: "all"
4052
script:
4153
- python3 -m pip install dependency-groups
4254
- python3 -m dependency_groups test | xargs python3 -m pip install -e. pytest-custom-exit-code

.travis.yml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@ jobs:
1414
- name: Linux | x86_64 + i686 | Python 3.12
1515
python: 3.12
1616
services: docker
17-
env: PYTHON=python
17+
env:
18+
- PYTHON=python
19+
- CIBW_ENABLE=all
1820

1921
- name: Linux | arm64 | Python 3.12
2022
python: 3.12
2123
services: docker
2224
arch: arm64
23-
env: PYTHON=python
25+
env:
26+
- PYTHON=python
27+
- CIBW_ENABLE=all
2428

2529
- name: Linux | ppc64le | Python 3.12
2630
python: 3.12
@@ -32,6 +36,7 @@ jobs:
3236
# skip test_manylinuxXXXX_only, it uses too much disk space
3337
# c.f. https://travis-ci.community/t/running-out-of-disk-space-quota-when-using-docker-on-ppc64le/11634
3438
- PYTEST_ADDOPTS='-k "not test_manylinuxXXXX_only"'
39+
- CIBW_ENABLE=all
3540

3641
- name: Windows | x86_64 | Python 3.12
3742
os: windows
@@ -40,13 +45,16 @@ jobs:
4045
- choco upgrade python3 -y --version 3.12.8 --limit-output --params "/InstallDir:C:\\Python312"
4146
env:
4247
- PYTHON=C:\\Python312\\python
48+
- CIBW_ENABLE=all
4349

4450
- name: Linux | s390x | Python 3.12
4551
python: 3.12
4652
services: docker
4753
arch: s390x
4854
allow_failure: True
49-
env: PYTHON=python
55+
env:
56+
- PYTHON=python
57+
- CIBW_ENABLE=all
5058

5159
install:
5260
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all; fi

azure-pipelines.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ jobs:
1616
docker run --rm --privileged docker.io/tonistiigi/binfmt:latest --install all
1717
python -m pip install dependency-groups
1818
python -m dependency_groups test | xargs python -m pip install -e.
19+
if [ "$(Build.SourceBranch)" = "refs/heads/main" ]; then
20+
echo "INFO: Exporting CIBW_ENABLE=all for main branch test run."
21+
export CIBW_ENABLE=all
22+
else
23+
echo "INFO: CIBW_ENABLE not set for this branch ($(Build.SourceBranch))."
24+
fi
1925
python ./bin/run_tests.py
2026
2127
- job: macos_311
@@ -28,6 +34,12 @@ jobs:
2834
- bash: |
2935
python -m pip install dependency-groups
3036
python -m dependency_groups test | xargs python -m pip install -e.
37+
if [ "$(Build.SourceBranch)" = "refs/heads/main" ]; then
38+
echo "INFO: Exporting CIBW_ENABLE=all for main branch test run."
39+
export CIBW_ENABLE=all
40+
else
41+
echo "INFO: CIBW_ENABLE not set for this branch ($(Build.SourceBranch))."
42+
fi
3143
python ./bin/run_tests.py
3244
3345
- job: windows_311
@@ -40,4 +52,10 @@ jobs:
4052
- bash: |
4153
python -m pip install dependency-groups
4254
python -m dependency_groups test | xargs python -m pip install -e.
55+
if [ "$(Build.SourceBranch)" = "refs/heads/main" ]; then
56+
echo "INFO: Exporting CIBW_ENABLE=all for main branch test run."
57+
export CIBW_ENABLE=all
58+
else
59+
echo "INFO: CIBW_ENABLE not set for this branch ($(Build.SourceBranch))."
60+
fi
4361
python ./bin/run_tests.py

cibuildwheel/options.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,10 @@ def globals(self) -> GlobalOptions:
634634
"enable", env_plat=False, option_format=ListFormat(sep=" "), env_rule=InheritRule.APPEND
635635
)
636636
try:
637-
enable = {EnableGroup(group) for group in enable_groups.split()}
638-
enable.update(EnableGroup(command_line_group) for command_line_group in args.enable)
637+
enable = {
638+
*EnableGroup.parse_option_value(enable_groups),
639+
*EnableGroup.parse_option_value(" ".join(args.enable)),
640+
}
639641
except ValueError as e:
640642
msg = f"Failed to parse enable group. {e}. Valid group names are: {', '.join(g.value for g in EnableGroup)}"
641643
raise errors.ConfigurationError(msg) from e

cibuildwheel/selector.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ class EnableGroup(StrEnum):
3939
def all_groups(cls) -> frozenset["EnableGroup"]:
4040
return frozenset(cls)
4141

42+
@classmethod
43+
def parse_option_value(cls, value: str) -> frozenset["EnableGroup"]:
44+
"""
45+
Parses a string of space-separated values into a set of EnableGroup
46+
members. The string may contain group names or "all".
47+
"""
48+
result = set()
49+
for group in value.strip().split():
50+
if group == "all":
51+
return cls.all_groups()
52+
try:
53+
result.add(cls(group))
54+
except ValueError:
55+
msg = f"Unknown enable group: {group}"
56+
raise ValueError(msg) from None
57+
return frozenset(result)
58+
4259

4360
@dataclass(frozen=True, kw_only=True)
4461
class BuildSelector:

docs/contributing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ A few notes-
8282

8383
- Running the macOS integration tests requires _system installs_ of Python from python.org for all the versions that are tested. We won't attempt to install these when running locally, but you can do so manually using the URL in the error message that is printed when the install is not found.
8484

85+
- The 'enable groups' run by default are just 'cpython-prerelease' and 'cpython-freethreading'. You can add other groups like pypy or graalpy by setting the [CIBW_ENABLE](options.md#enable) environment variable. On GitHub PRs, you can add a label to the PR to enable these groups.
86+
8587
#### Running pytest directly
8688

8789
More advanced users might prefer to invoke pytest directly. Set up a [dev environment](#setting-up-a-dev-environment), then,

docs/options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ values are:
324324
are disabled by default as they can't be uploaded to PyPI and a PEP will most likely
325325
be required before this can happen.
326326
- `graalpy`: Enable GraalPy.
327-
327+
- `all`: Enable all of the above.
328328

329329
!!! caution
330330
`cpython-prerelease` is provided for testing purposes only. It is not

test/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import subprocess
34
from collections.abc import Generator
45

@@ -12,6 +13,9 @@
1213

1314
from .utils import EMULATED_ARCHS, platform
1415

16+
# default to just cpython
17+
DEFAULT_CIBW_ENABLE = "cpython-freethreading cpython-prerelease cpython-experimental-riscv64"
18+
1519

1620
def pytest_addoption(parser: pytest.Parser) -> None:
1721
parser.addoption(
@@ -29,6 +33,8 @@ def pytest_addoption(parser: pytest.Parser) -> None:
2933
help="macOS cp38 uses the universal2 installer",
3034
)
3135

36+
os.environ.setdefault("CIBW_ENABLE", DEFAULT_CIBW_ENABLE)
37+
3238

3339
def docker_warmup(request: pytest.FixtureRequest) -> None:
3440
machine = request.config.getoption("--run-emulation", default=None)

0 commit comments

Comments
 (0)