Don't require --platform when running on a development machine

Historically, we required `--platform` when running cibuildwheel outside of CI, because cibuildwheel would attempt to globally install Python interpreters and some packages.

That was fixed in https://github.com/pypa/cibuildwheel/pull/974 a couple of years ago. As a result, there's no reason to require --platform these days, the `auto` behaviour is perfectly fine for dev machines.

It also makes running tests locally simpler, one can just do `pytest test/test_0_basic.py` (or `nox -s tests -- test/test_0_basic.py`) and not have to worry about setting CIBW_PLATFORM most of the time.
This commit is contained in:
Joe Rickerby
2024-01-21 18:24:43 +00:00
parent 23a6e88b0c
commit 4db49f5485
5 changed files with 38 additions and 84 deletions
-3
View File
@@ -1,3 +0,0 @@
#!/bin/bash
CIBW_PLATFORM=linux pytest "$@"
+6 -21
View File
@@ -49,10 +49,9 @@ def main() -> None:
default=None, default=None,
help=""" help="""
Platform to build for. Use this option to override the Platform to build for. Use this option to override the
auto-detected platform or to run cibuildwheel on your development auto-detected platform. Specifying "macos" or "windows" only works
machine. Specifying "macos" or "windows" only works on that on that operating system, but "linux" works on all three, as long
operating system, but "linux" works on all three, as long as as Docker/Podman is installed. Default: auto.
Docker/Podman is installed. Default: auto.
""", """,
) )
@@ -184,20 +183,7 @@ def _compute_platform_only(only: str) -> PlatformName:
sys.exit(2) sys.exit(2)
def _compute_platform_ci() -> PlatformName: def _compute_platform_auto() -> PlatformName:
if detect_ci_provider() is None:
print(
textwrap.dedent(
"""
cibuildwheel: Unable to detect platform. cibuildwheel should run on your CI server;
Travis CI, AppVeyor, Azure Pipelines, GitHub Actions, CircleCI, Gitlab, and Cirrus CI
are supported. You can run on your development machine or other CI providers
using the --platform argument. Check --help output for more information.
"""
),
file=sys.stderr,
)
sys.exit(2)
if sys.platform.startswith("linux"): if sys.platform.startswith("linux"):
return "linux" return "linux"
elif sys.platform == "darwin": elif sys.platform == "darwin":
@@ -206,8 +192,7 @@ def _compute_platform_ci() -> PlatformName:
return "windows" return "windows"
else: else:
print( print(
'cibuildwheel: Unable to detect platform from "sys.platform" in a CI environment. You can run ' 'cibuildwheel: Unable to detect platform from "sys.platform". cibuildwheel doesn\'t support building wheels for this platform. You might be able to build for a different platform using the --platform argument. Check --help output for more information.',
"cibuildwheel using the --platform argument. Check --help output for more information.",
file=sys.stderr, file=sys.stderr,
) )
sys.exit(2) sys.exit(2)
@@ -238,7 +223,7 @@ def _compute_platform(args: CommandLineArguments) -> PlatformName:
elif platform_option_value != "auto": elif platform_option_value != "auto":
return typing.cast(PlatformName, platform_option_value) return typing.cast(PlatformName, platform_option_value)
return _compute_platform_ci() return _compute_platform_auto()
class PlatformModule(Protocol): class PlatformModule(Protocol):
+4 -2
View File
@@ -184,7 +184,7 @@ Options: `auto` `linux` `macos` `windows`
Default: `auto` Default: `auto`
`auto` will auto-detect platform using environment variables, such as `TRAVIS_OS_NAME`/`APPVEYOR`/`CIRCLECI`. `auto` will build wheels for the current platform.
- For `linux`, you need [Docker or Podman](#container-engine) running, on Linux, macOS, or Windows. - For `linux`, you need [Docker or Podman](#container-engine) running, on Linux, macOS, or Windows.
- For `macos` and `windows`, you need to be running on the respective system, with a working compiler toolchain installed - Xcode Command Line tools for macOS, and MSVC for Windows. - For `macos` and `windows`, you need to be running on the respective system, with a working compiler toolchain installed - Xcode Command Line tools for macOS, and MSVC for Windows.
@@ -192,7 +192,7 @@ Default: `auto`
This option can also be set using the [command-line option](#command-line) `--platform`. This option is not available in the `pyproject.toml` config. This option can also be set using the [command-line option](#command-line) `--platform`. This option is not available in the `pyproject.toml` config.
!!! tip !!! tip
You can use this option to locally debug your cibuildwheel config, instead of pushing to CI to test every change. For example: You can use this option to locally debug your cibuildwheel config on Linux, instead of pushing to CI to test every change. For example:
```bash ```bash
export CIBW_BUILD='cp37-*' export CIBW_BUILD='cp37-*'
@@ -200,6 +200,8 @@ This option can also be set using the [command-line option](#command-line) `--pl
cibuildwheel --platform linux . cibuildwheel --platform linux .
``` ```
Linux builds are the easiest to test locally, because all the build tools are supplied in the container, and they run exactly the same locally as in CI.
This is even more convenient if you store your cibuildwheel config in [`pyproject.toml`](#configuration-file). This is even more convenient if you store your cibuildwheel config in [`pyproject.toml`](#configuration-file).
You can also run a single identifier with `--only <identifier>`. This will You can also run a single identifier with `--only <identifier>`. This will
+10 -41
View File
@@ -11,45 +11,14 @@ locally to quickly iterate and track down issues without even touching CI.
Install cibuildwheel and run a build like this: Install cibuildwheel and run a build like this:
!!! tab "Linux" ```sh
# using pipx (https://github.com/pypa/pipx)
pipx run cibuildwheel
Using [pipx](https://github.com/pypa/pipx): # or,
```sh pip install cibuildwheel
pipx run cibuildwheel --platform linux cibuildwheel
``` ```
Or,
```sh
pip install cibuildwheel
cibuildwheel --platform linux
```
!!! tab "macOS"
Using [pipx](https://github.com/pypa/pipx):
```sh
pipx run cibuildwheel --platform macos
```
Or,
```sh
pip install cibuildwheel
cibuildwheel --platform macos
```
!!! tab "Windows"
Using [pipx](https://github.com/pypa/pipx):
```bat
pipx run cibuildwheel --platform windows
```
Or,
```bat
pip install cibuildwheel
cibuildwheel --platform windows
```
You should see the builds taking place. You can experiment with options using environment variables or pyproject.toml. You should see the builds taking place. You can experiment with options using environment variables or pyproject.toml.
@@ -63,7 +32,7 @@ You should see the builds taking place. You can experiment with options using en
# run a command to set up the build system # run a command to set up the build system
export CIBW_BEFORE_ALL='apt install libpng-dev' export CIBW_BEFORE_ALL='apt install libpng-dev'
cibuildwheel --platform linux cibuildwheel
``` ```
> CMD (Windows) > CMD (Windows)
@@ -71,7 +40,7 @@ You should see the builds taking place. You can experiment with options using en
```bat ```bat
set CIBW_BEFORE_ALL='apt install libpng-dev' set CIBW_BEFORE_ALL='apt install libpng-dev'
cibuildwheel --platform linux cibuildwheel
``` ```
!!! tab "pyproject.toml" !!! tab "pyproject.toml"
@@ -88,7 +57,7 @@ You should see the builds taking place. You can experiment with options using en
Then invoke cibuildwheel, like: Then invoke cibuildwheel, like:
```console ```console
cibuildwheel --platform linux cibuildwheel
``` ```
### Linux builds ### Linux builds
+16 -15
View File
@@ -10,25 +10,26 @@ from cibuildwheel.architecture import Architecture
from ..conftest import MOCK_PACKAGE_DIR from ..conftest import MOCK_PACKAGE_DIR
def test_unknown_platform_non_ci(monkeypatch, capsys): @pytest.mark.parametrize("option_value", [None, "auto"])
monkeypatch.delenv("CI", raising=False) def test_platform_unset_or_auto(monkeypatch, intercepted_build_args, option_value):
monkeypatch.delenv("BITRISE_BUILD_NUMBER", raising=False) if option_value is None:
monkeypatch.delenv("AZURE_HTTP_USER_AGENT", raising=False)
monkeypatch.delenv("TRAVIS", raising=False)
monkeypatch.delenv("APPVEYOR", raising=False)
monkeypatch.delenv("GITHUB_ACTIONS", raising=False)
monkeypatch.delenv("GITLAB_CI", raising=False)
monkeypatch.delenv("CIRCLECI", raising=False)
monkeypatch.delenv("CIRRUS_CI", raising=False)
monkeypatch.delenv("CIBW_PLATFORM", raising=False) monkeypatch.delenv("CIBW_PLATFORM", raising=False)
else:
monkeypatch.setenv("CIBW_PLATFORM", option_value)
with pytest.raises(SystemExit) as exit:
main() main()
assert exit.value.code == 2
_, err = capsys.readouterr()
assert "cibuildwheel: Unable to detect platform." in err options = intercepted_build_args.args[0]
assert "cibuildwheel should run on your CI server" in err
# check that the platform was auto detected to build for the current system
if sys.platform.startswith("linux"):
assert options.platform == "linux"
elif sys.platform == "darwin":
assert options.platform == "macos"
elif sys.platform == "win32":
assert options.platform == "windows"
else:
pytest.fail(f"Unknown platform: {sys.platform}")
def test_unknown_platform_on_ci(monkeypatch, capsys): def test_unknown_platform_on_ci(monkeypatch, capsys):