From 61a1ebedec90e5735a30f0c49c390a54259b8739 Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Fri, 28 Mar 2025 12:31:52 -0400 Subject: [PATCH 1/3] fix: support wider range of verbosity settings on other build backends Signed-off-by: Henry Schreiner --- cibuildwheel/frontend.py | 6 ++++- docs/options.md | 11 +++++++-- unit_test/options_test.py | 48 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 3 deletions(-) diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index 8e6a2897f..fb4d3bc95 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -42,7 +42,11 @@ def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]: return ["-" + level * "v"] if level < 0: return ["-" + -level * "q"] - elif not 0 <= level < 2: + elif level > 1: + return ["-v"] + elif level < 0: + if frontend not in {"build", "build[uv]"}: + return ["-q"] msg = f"build_verbosity {level} is not supported for {frontend} frontend. Ignoring." log.warning(msg) return [] diff --git a/docs/options.md b/docs/options.md index 0c4ade208..8cf708a49 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1760,9 +1760,16 @@ export CIBW_DEBUG_TRACEBACK=TRUE ``` ### `CIBW_BUILD_VERBOSITY` {: #build-verbosity} -> Increase/decrease the output of pip wheel +> Increase/decrease the output of the build + +The setting vary a bit between build backends. + +* `-1`: Hide as much build output as possible; passes `-q` to the build backend. Not supported by `build`/`build[uv]`. +* `0`: The default. On pip, this hides the build output if the build succeeds, other build backends produce output from the build backend. +* `1`: Produces build backend output. On `pip`, this passes `-v`. Other backends do this by default. +* `2`: Produces extra output from resolving packages too. On `pip`, this passes `-vv`, other build backends use `-v`. +* `3`: Even more resolving output from pip with `-vvv`, other build backends continue to just pass `-v`. -A number from 1 to 3 to increase the level of verbosity (corresponding to invoking pip with `-v`, `-vv`, and `-vvv`), between -1 and -3 (`-q`, `-qq`, and `-qqq`), or just 0 (default verbosity). These flags are useful while debugging a build when the output of the actual build invoked by `pip wheel` is required. Has no effect on the `build` backend, which produces verbose output by default. Platform-specific environment variables are also available:
`CIBW_BUILD_VERBOSITY_MACOS` | `CIBW_BUILD_VERBOSITY_WINDOWS` | `CIBW_BUILD_VERBOSITY_LINUX` | `CIBW_BUILD_VERBOSITY_IOS` | `CIBW_BUILD_VERBOSITY_PYODIDE` diff --git a/unit_test/options_test.py b/unit_test/options_test.py index 143f7fdc0..b59c1fe5f 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -1,12 +1,16 @@ import os import platform as platform_module import textwrap +import unittest.mock from pathlib import Path +from typing import Literal import pytest from cibuildwheel import errors from cibuildwheel.bashlex_eval import local_environment_executor +from cibuildwheel.frontend import BuildFrontendConfig, get_build_frontend_extra_flags +from cibuildwheel.logger import Logger from cibuildwheel.options import ( CommandLineArguments, Options, @@ -570,3 +574,47 @@ def test_deprecated_image( assert f"{resolved_image!r}" in captured.err else: assert "Deprecated image" not in captured.err + + +@pytest.mark.parametrize( + ("frontend", "verbosity", "result"), + [ + ("pip", 3, ["-Ca", "-Cb", "-1", "-vvv"]), + ("pip", 2, ["-Ca", "-Cb", "-1", "-vv"]), + ("pip", -1, ["-Ca", "-Cb", "-1", "-q"]), + ("build", 0, ["-Ca", "-Cb", "-1"]), + ("build", 1, ["-Ca", "-Cb", "-1"]), + ("build", 2, ["-Ca", "-Cb", "-1", "-v"]), + ("build", 3, ["-Ca", "-Cb", "-1", "-v"]), + ("build[uv]", 3, ["-Ca", "-Cb", "-1", "-v"]), + ], +) +def test_get_build_frontend_extra_flags( + frontend: Literal["pip", "build", "build[uv]"], + verbosity: int, + result: list[str], + monkeypatch: pytest.MonkeyPatch, +) -> None: + mock_warning = unittest.mock.MagicMock() + monkeypatch.setattr(Logger, "warning", mock_warning) + build_frontend = BuildFrontendConfig(frontend, ["-1"]) + args = get_build_frontend_extra_flags( + build_frontend=build_frontend, verbosity_level=verbosity, config_settings="a b" + ) + + assert args == result + mock_warning.assert_not_called() + + +@pytest.mark.parametrize("frontend", ["build", "build[uv]"]) +def test_get_build_frontend_extra_flags_warning( + frontend: Literal["build", "build[uv]"], monkeypatch: pytest.MonkeyPatch +) -> None: + mock_warning = unittest.mock.MagicMock() + monkeypatch.setattr(Logger, "warning", mock_warning) + build_frontend = BuildFrontendConfig(frontend, ["-1"]) + args = get_build_frontend_extra_flags( + build_frontend=build_frontend, verbosity_level=-1, config_settings="a b" + ) + assert args == ["-Ca", "-Cb", "-1"] + mock_warning.assert_called_once() From bd583a2f031d8015d4505020c63d75f33b09c80b Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Sun, 30 Mar 2025 17:51:30 -0400 Subject: [PATCH 2/3] Apply suggestions from code review Co-authored-by: Matthieu Darbois --- cibuildwheel/frontend.py | 2 -- docs/options.md | 12 ++++++------ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index fb4d3bc95..d814a68bf 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -45,8 +45,6 @@ def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]: elif level > 1: return ["-v"] elif level < 0: - if frontend not in {"build", "build[uv]"}: - return ["-q"] msg = f"build_verbosity {level} is not supported for {frontend} frontend. Ignoring." log.warning(msg) return [] diff --git a/docs/options.md b/docs/options.md index 8cf708a49..f693d2cec 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1762,13 +1762,13 @@ export CIBW_DEBUG_TRACEBACK=TRUE ### `CIBW_BUILD_VERBOSITY` {: #build-verbosity} > Increase/decrease the output of the build -The setting vary a bit between build backends. +The setting vary a bit between build frontends. -* `-1`: Hide as much build output as possible; passes `-q` to the build backend. Not supported by `build`/`build[uv]`. -* `0`: The default. On pip, this hides the build output if the build succeeds, other build backends produce output from the build backend. -* `1`: Produces build backend output. On `pip`, this passes `-v`. Other backends do this by default. -* `2`: Produces extra output from resolving packages too. On `pip`, this passes `-vv`, other build backends use `-v`. -* `3`: Even more resolving output from pip with `-vvv`, other build backends continue to just pass `-v`. +* `-1`: Hide as much build output as possible; passes `-q` to the build frontend. Not supported by `build`/`build[uv]`. +* `0`: The default. On pip, this hides the build output if the build succeeds, other build frontends produce output from the build backend. +* `1`: Produces build backend output. On `pip`, this passes `-v`. Other frontends do this by default. +* `2`: Produces extra output from resolving packages too. On `pip`, this passes `-vv`, other build frontends use `-v`. +* `3`: Even more resolving output from pip with `-vvv`, other build frontends continue to just pass `-v`. Platform-specific environment variables are also available:
From e2a31603f731da633a477208f8d944bbbcce62ef Mon Sep 17 00:00:00 2001 From: Henry Schreiner Date: Mon, 31 Mar 2025 10:39:41 -0400 Subject: [PATCH 3/3] refactor: address review comments Signed-off-by: Henry Schreiner --- cibuildwheel/frontend.py | 17 ++++++++++------- docs/options.md | 31 +++++++++++++++++++++---------- unit_test/options_test.py | 4 ++-- 3 files changed, 33 insertions(+), 19 deletions(-) diff --git a/cibuildwheel/frontend.py b/cibuildwheel/frontend.py index d814a68bf..79796a1be 100644 --- a/cibuildwheel/frontend.py +++ b/cibuildwheel/frontend.py @@ -37,16 +37,19 @@ def options_summary(self) -> str | dict[str, str]: def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]: - if frontend == "pip": - if level > 0: - return ["-" + level * "v"] - if level < 0: + if level < 0: + if frontend == "pip": return ["-" + -level * "q"] - elif level > 1: - return ["-v"] - elif level < 0: + msg = f"build_verbosity {level} is not supported for {frontend} frontend. Ignoring." log.warning(msg) + + if level > 0: + if frontend == "pip": + return ["-" + level * "v"] + if level > 1: + return ["-" + (level - 1) * "v"] + return [] diff --git a/docs/options.md b/docs/options.md index f693d2cec..fe2adad84 100644 --- a/docs/options.md +++ b/docs/options.md @@ -1762,14 +1762,25 @@ export CIBW_DEBUG_TRACEBACK=TRUE ### `CIBW_BUILD_VERBOSITY` {: #build-verbosity} > Increase/decrease the output of the build -The setting vary a bit between build frontends. - -* `-1`: Hide as much build output as possible; passes `-q` to the build frontend. Not supported by `build`/`build[uv]`. -* `0`: The default. On pip, this hides the build output if the build succeeds, other build frontends produce output from the build backend. -* `1`: Produces build backend output. On `pip`, this passes `-v`. Other frontends do this by default. -* `2`: Produces extra output from resolving packages too. On `pip`, this passes `-vv`, other build frontends use `-v`. -* `3`: Even more resolving output from pip with `-vvv`, other build frontends continue to just pass `-v`. - +This setting controls `-v`/`-q` flags to the build frontend. Since there is +no communication between the build backend and the build frontend, build +messages from the build backend will always be shown with `1`; higher levels +will not produce more logging about the build itself. Other levels only affect +the build frontend output, which is usually things like resolving and +downloading dependencies. The settings are: + +| | build | pip | desc | +|-------------|-------|--------|----------------------------------| +| -2 | N/A | `-qq` | even more quiet, where supported | +| -1 | N/A | `-q` | quiet mode, where supported | +| 0 (default) | | | default for build tool | +| 1 | | `-v` | print backend output | +| 2 | `-v` | `-vv` | print log messages e.g. resolving info | +| 3 | `-vv` | `-vvv` | print even more debug info | + +Settings that are not supported for a specific frontend will log a warning. +The default build frontend is `build`, which does show build backend output by +default. Platform-specific environment variables are also available:
`CIBW_BUILD_VERBOSITY_MACOS` | `CIBW_BUILD_VERBOSITY_WINDOWS` | `CIBW_BUILD_VERBOSITY_LINUX` | `CIBW_BUILD_VERBOSITY_IOS` | `CIBW_BUILD_VERBOSITY_PYODIDE` @@ -1779,7 +1790,7 @@ Platform-specific environment variables are also available:
!!! tab examples "Environment variables" ```yaml - # Increase pip debugging output + # Ensure that the build backend output is present CIBW_BUILD_VERBOSITY: 1 ``` @@ -1787,7 +1798,7 @@ Platform-specific environment variables are also available:
```toml [tool.cibuildwheel] - # Increase pip debugging output + # Ensure that the build backend output is present build-verbosity = 1 ``` diff --git a/unit_test/options_test.py b/unit_test/options_test.py index b59c1fe5f..bcf242916 100644 --- a/unit_test/options_test.py +++ b/unit_test/options_test.py @@ -585,8 +585,8 @@ def test_deprecated_image( ("build", 0, ["-Ca", "-Cb", "-1"]), ("build", 1, ["-Ca", "-Cb", "-1"]), ("build", 2, ["-Ca", "-Cb", "-1", "-v"]), - ("build", 3, ["-Ca", "-Cb", "-1", "-v"]), - ("build[uv]", 3, ["-Ca", "-Cb", "-1", "-v"]), + ("build", 3, ["-Ca", "-Cb", "-1", "-vv"]), + ("build[uv]", 3, ["-Ca", "-Cb", "-1", "-vv"]), ], ) def test_get_build_frontend_extra_flags(