Skip to content

Commit 03ef236

Browse files
committed
Add quiet flag
1 parent 090cbf4 commit 03ef236

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/build/__main__.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
from functools import partial
2121
from typing import Any, NoReturn, TextIO
2222

23+
import pyproject_hooks
24+
2325
import build
2426

2527
from . import ProjectBuilder, _ctx
@@ -77,6 +79,9 @@ def _make_logger() -> _ctx.Logger:
7779
fill = partial(textwrap.fill, subsequent_indent=' ', width=max_terminal_width)
7880

7981
def log(message: str, *, origin: tuple[str, ...] | None = None) -> None:
82+
if _ctx.verbosity < 0:
83+
return
84+
8085
if origin is None:
8186
(first, *rest) = message.splitlines()
8287
_cprint('{bold}{}{reset}', fill(first, initial_indent='* '), file=sys.stderr)
@@ -174,7 +179,15 @@ def _build(
174179
skip_dependency_check: bool,
175180
installer: _env.Installer,
176181
) -> 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:
178191
return builder.build(distribution, outdir, config_settings)
179192

180193

@@ -376,10 +389,18 @@ def main_parser() -> argparse.ArgumentParser:
376389
action='version',
377390
version=f'build {build.__version__} ({",".join(build.__path__)})',
378391
)
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(
380402
'--verbose',
381403
'-v',
382-
dest='verbosity',
383404
action='count',
384405
default=0,
385406
help='increase verbosity',
@@ -486,7 +507,7 @@ def main(cli_args: Sequence[str], prog: str | None = None) -> None:
486507
parser.prog = prog
487508
args = parser.parse_args(cli_args)
488509

489-
_setup_cli(verbosity=args.verbosity)
510+
_setup_cli(verbosity=args.verbose or args.quiet)
490511

491512
config_settings = dict[str, Any]()
492513

@@ -524,7 +545,7 @@ def main(cli_args: Sequence[str], prog: str | None = None) -> None:
524545
skip_dependency_check=args.skip_dependency_check,
525546
installer=args.installer,
526547
)
527-
if built:
548+
if _ctx.verbosity >= 0 and built:
528549
artifact_list = _natural_language_list(
529550
['{underline}{}{reset}{bold}{green}'.format(artifact, **_styles.get()) for artifact in built]
530551
)

src/build/_ctx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def log_subprocess_error(error: subprocess.CalledProcessError) -> None:
4141
def run_subprocess(cmd: Sequence[StrPath], cwd: str | None = None, env: Mapping[str, str] | None = None) -> None:
4242
verbosity = VERBOSITY.get()
4343

44-
if verbosity:
44+
if verbosity > 0:
4545
import concurrent.futures
4646

4747
log = LOGGER.get()

0 commit comments

Comments
 (0)