Skip to content

Commit 2aaa489

Browse files
henryiiimayeut
andauthored
fix: support wider range of verbosity settings on other build backends (#2339)
* fix: support wider range of verbosity settings on other build backends Signed-off-by: Henry Schreiner <[email protected]> * Apply suggestions from code review Co-authored-by: Matthieu Darbois <[email protected]> * refactor: address review comments Signed-off-by: Henry Schreiner <[email protected]> --------- Signed-off-by: Henry Schreiner <[email protected]> Co-authored-by: Matthieu Darbois <[email protected]>
1 parent 6c426a3 commit 2aaa489

File tree

3 files changed

+81
-10
lines changed

3 files changed

+81
-10
lines changed

cibuildwheel/frontend.py

+10-5
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,19 @@ def options_summary(self) -> str | dict[str, str]:
3737

3838

3939
def _get_verbosity_flags(level: int, frontend: BuildFrontendName) -> list[str]:
40-
if frontend == "pip":
41-
if level > 0:
42-
return ["-" + level * "v"]
43-
if level < 0:
40+
if level < 0:
41+
if frontend == "pip":
4442
return ["-" + -level * "q"]
45-
elif not 0 <= level < 2:
43+
4644
msg = f"build_verbosity {level} is not supported for {frontend} frontend. Ignoring."
4745
log.warning(msg)
46+
47+
if level > 0:
48+
if frontend == "pip":
49+
return ["-" + level * "v"]
50+
if level > 1:
51+
return ["-" + (level - 1) * "v"]
52+
4853
return []
4954

5055

docs/options.md

+23-5
Original file line numberDiff line numberDiff line change
@@ -1760,9 +1760,27 @@ export CIBW_DEBUG_TRACEBACK=TRUE
17601760
```
17611761

17621762
### `CIBW_BUILD_VERBOSITY` {: #build-verbosity}
1763-
> Increase/decrease the output of pip wheel
1764-
1765-
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.
1763+
> Increase/decrease the output of the build
1764+
1765+
This setting controls `-v`/`-q` flags to the build frontend. Since there is
1766+
no communication between the build backend and the build frontend, build
1767+
messages from the build backend will always be shown with `1`; higher levels
1768+
will not produce more logging about the build itself. Other levels only affect
1769+
the build frontend output, which is usually things like resolving and
1770+
downloading dependencies. The settings are:
1771+
1772+
| | build | pip | desc |
1773+
|-------------|-------|--------|----------------------------------|
1774+
| -2 | N/A | `-qq` | even more quiet, where supported |
1775+
| -1 | N/A | `-q` | quiet mode, where supported |
1776+
| 0 (default) | | | default for build tool |
1777+
| 1 | | `-v` | print backend output |
1778+
| 2 | `-v` | `-vv` | print log messages e.g. resolving info |
1779+
| 3 | `-vv` | `-vvv` | print even more debug info |
1780+
1781+
Settings that are not supported for a specific frontend will log a warning.
1782+
The default build frontend is `build`, which does show build backend output by
1783+
default.
17661784

17671785
Platform-specific environment variables are also available:<br/>
17681786
`CIBW_BUILD_VERBOSITY_MACOS` | `CIBW_BUILD_VERBOSITY_WINDOWS` | `CIBW_BUILD_VERBOSITY_LINUX` | `CIBW_BUILD_VERBOSITY_IOS` | `CIBW_BUILD_VERBOSITY_PYODIDE`
@@ -1772,15 +1790,15 @@ Platform-specific environment variables are also available:<br/>
17721790
!!! tab examples "Environment variables"
17731791

17741792
```yaml
1775-
# Increase pip debugging output
1793+
# Ensure that the build backend output is present
17761794
CIBW_BUILD_VERBOSITY: 1
17771795
```
17781796

17791797
!!! tab examples "pyproject.toml"
17801798

17811799
```toml
17821800
[tool.cibuildwheel]
1783-
# Increase pip debugging output
1801+
# Ensure that the build backend output is present
17841802
build-verbosity = 1
17851803
```
17861804

unit_test/options_test.py

+48
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import os
22
import platform as platform_module
33
import textwrap
4+
import unittest.mock
45
from pathlib import Path
6+
from typing import Literal
57

68
import pytest
79

810
from cibuildwheel import errors
911
from cibuildwheel.bashlex_eval import local_environment_executor
12+
from cibuildwheel.frontend import BuildFrontendConfig, get_build_frontend_extra_flags
13+
from cibuildwheel.logger import Logger
1014
from cibuildwheel.options import (
1115
CommandLineArguments,
1216
Options,
@@ -570,3 +574,47 @@ def test_deprecated_image(
570574
assert f"{resolved_image!r}" in captured.err
571575
else:
572576
assert "Deprecated image" not in captured.err
577+
578+
579+
@pytest.mark.parametrize(
580+
("frontend", "verbosity", "result"),
581+
[
582+
("pip", 3, ["-Ca", "-Cb", "-1", "-vvv"]),
583+
("pip", 2, ["-Ca", "-Cb", "-1", "-vv"]),
584+
("pip", -1, ["-Ca", "-Cb", "-1", "-q"]),
585+
("build", 0, ["-Ca", "-Cb", "-1"]),
586+
("build", 1, ["-Ca", "-Cb", "-1"]),
587+
("build", 2, ["-Ca", "-Cb", "-1", "-v"]),
588+
("build", 3, ["-Ca", "-Cb", "-1", "-vv"]),
589+
("build[uv]", 3, ["-Ca", "-Cb", "-1", "-vv"]),
590+
],
591+
)
592+
def test_get_build_frontend_extra_flags(
593+
frontend: Literal["pip", "build", "build[uv]"],
594+
verbosity: int,
595+
result: list[str],
596+
monkeypatch: pytest.MonkeyPatch,
597+
) -> None:
598+
mock_warning = unittest.mock.MagicMock()
599+
monkeypatch.setattr(Logger, "warning", mock_warning)
600+
build_frontend = BuildFrontendConfig(frontend, ["-1"])
601+
args = get_build_frontend_extra_flags(
602+
build_frontend=build_frontend, verbosity_level=verbosity, config_settings="a b"
603+
)
604+
605+
assert args == result
606+
mock_warning.assert_not_called()
607+
608+
609+
@pytest.mark.parametrize("frontend", ["build", "build[uv]"])
610+
def test_get_build_frontend_extra_flags_warning(
611+
frontend: Literal["build", "build[uv]"], monkeypatch: pytest.MonkeyPatch
612+
) -> None:
613+
mock_warning = unittest.mock.MagicMock()
614+
monkeypatch.setattr(Logger, "warning", mock_warning)
615+
build_frontend = BuildFrontendConfig(frontend, ["-1"])
616+
args = get_build_frontend_extra_flags(
617+
build_frontend=build_frontend, verbosity_level=-1, config_settings="a b"
618+
)
619+
assert args == ["-Ca", "-Cb", "-1"]
620+
mock_warning.assert_called_once()

0 commit comments

Comments
 (0)