|
20 | 20 | from functools import partial |
21 | 21 | from typing import Any, NoReturn, TextIO |
22 | 22 |
|
| 23 | +import pyproject_hooks |
| 24 | + |
23 | 25 | import build |
24 | 26 |
|
25 | 27 | from . import ProjectBuilder, _ctx |
@@ -77,6 +79,9 @@ def _make_logger() -> _ctx.Logger: |
77 | 79 | fill = partial(textwrap.fill, subsequent_indent=' ', width=max_terminal_width) |
78 | 80 |
|
79 | 81 | def log(message: str, *, origin: tuple[str, ...] | None = None) -> None: |
| 82 | + if _ctx.verbosity < 0: |
| 83 | + return |
| 84 | + |
80 | 85 | if origin is None: |
81 | 86 | (first, *rest) = message.splitlines() |
82 | 87 | _cprint('{bold}{}{reset}', fill(first, initial_indent='* '), file=sys.stderr) |
@@ -174,7 +179,15 @@ def _build( |
174 | 179 | skip_dependency_check: bool, |
175 | 180 | installer: _env.Installer, |
176 | 181 | ) -> str: |
177 | | - with _bootstrap_build_env(isolation, srcdir, distribution, config_settings, skip_dependency_check, installer) as builder: |
| 182 | + with _bootstrap_build_env( |
| 183 | + isolation, |
| 184 | + srcdir, |
| 185 | + distribution, |
| 186 | + config_settings, |
| 187 | + skip_dependency_check, |
| 188 | + installer, |
| 189 | + pyproject_hooks.quiet_subprocess_runner if _ctx.verbosity < 0 else None, |
| 190 | + ) as builder: |
178 | 191 | return builder.build(distribution, outdir, config_settings) |
179 | 192 |
|
180 | 193 |
|
@@ -376,10 +389,18 @@ def main_parser() -> argparse.ArgumentParser: |
376 | 389 | action='version', |
377 | 390 | version=f'build {build.__version__} ({",".join(build.__path__)})', |
378 | 391 | ) |
379 | | - global_group.add_argument( |
| 392 | + verbosity_exclusive_group = global_group.add_mutually_exclusive_group() |
| 393 | + verbosity_exclusive_group.add_argument( |
| 394 | + '--quiet', |
| 395 | + '-q', |
| 396 | + action='store_const', |
| 397 | + const=-1, |
| 398 | + default=0, |
| 399 | + help='reduce verbosity', |
| 400 | + ) |
| 401 | + verbosity_exclusive_group.add_argument( |
380 | 402 | '--verbose', |
381 | 403 | '-v', |
382 | | - dest='verbosity', |
383 | 404 | action='count', |
384 | 405 | default=0, |
385 | 406 | help='increase verbosity', |
@@ -486,7 +507,7 @@ def main(cli_args: Sequence[str], prog: str | None = None) -> None: |
486 | 507 | parser.prog = prog |
487 | 508 | args = parser.parse_args(cli_args) |
488 | 509 |
|
489 | | - _setup_cli(verbosity=args.verbosity) |
| 510 | + _setup_cli(verbosity=args.verbose or args.quiet) |
490 | 511 |
|
491 | 512 | config_settings = dict[str, Any]() |
492 | 513 |
|
@@ -524,7 +545,7 @@ def main(cli_args: Sequence[str], prog: str | None = None) -> None: |
524 | 545 | skip_dependency_check=args.skip_dependency_check, |
525 | 546 | installer=args.installer, |
526 | 547 | ) |
527 | | - if built: |
| 548 | + if _ctx.verbosity >= 0 and built: |
528 | 549 | artifact_list = _natural_language_list( |
529 | 550 | ['{underline}{}{reset}{bold}{green}'.format(artifact, **_styles.get()) for artifact in built] |
530 | 551 | ) |
|
0 commit comments