Make formatter output quiet on success (#29467)

## Why

`just fmt` is quite noisy even on successful runs.

## What

Only print output when a formatter fails.

- Buffer output from each formatter and print only a failed command and
its diagnostics.
- Prefix the `justfile` driver invocations with `@` so Just does not
echo the command itself.
- Retain rustfmt stderr on failure and cover silent-success and
failure-reporting behavior.

## Validation

- Confirmed `just fmt` and `just fmt-check` both exit successfully with
empty stdout and stderr.
This commit is contained in:
Adam Perry @ OpenAI
2026-06-22 17:55:49 -07:00
committed by GitHub
Unverified
parent e65e480e0d
commit ff31ba8d0a
3 changed files with 85 additions and 30 deletions
+12 -26
View File
@@ -18,7 +18,6 @@ REPO_ROOT = Path(__file__).resolve().parents[1]
class Command:
args: tuple[str, ...]
cwd: Path = REPO_ROOT
discard_stderr: bool = False
@dataclass(frozen=True)
@@ -45,13 +44,7 @@ def rust_formatter_group(*, check: bool) -> FormatterGroup:
args = ["cargo", "fmt", "--", "--config", "imports_granularity=Item"]
if check:
args.append("--check")
# Stable rustfmt repeats a nightly-only `imports_granularity` warning
# for each crate, so suppress that expected stderr noise.
command = Command(
tuple(args),
REPO_ROOT / "codex-rs",
discard_stderr=True,
)
command = Command(tuple(args), REPO_ROOT / "codex-rs")
return FormatterGroup("Rust", (command,))
@@ -152,31 +145,27 @@ def formatter_groups(*, check: bool) -> tuple[FormatterGroup, ...]:
def run_formatter_group(group: FormatterGroup) -> FormatterResult:
"""Run one formatter group sequentially and return its buffered output."""
output: list[str] = []
for command in group.commands:
output.append(f"$ {shlex.join(command.args)}\n")
try:
process = subprocess.run(
command.args,
cwd=command.cwd,
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL
if command.discard_stderr
else subprocess.STDOUT,
stderr=subprocess.STDOUT,
text=True,
check=False,
)
except OSError as error:
output.append(f"{error}\n")
return FormatterResult(group.name, "".join(output), 1)
output = f"$ {shlex.join(command.args)}\n{error}\n"
return FormatterResult(group.name, output, 1)
output.append(process.stdout)
if process.stdout and not process.stdout.endswith("\n"):
output.append("\n")
if process.returncode != 0:
return FormatterResult(group.name, "".join(output), process.returncode)
output = f"$ {shlex.join(command.args)}\n{process.stdout}"
if process.stdout and not process.stdout.endswith("\n"):
output += "\n"
return FormatterResult(group.name, output, process.returncode)
return FormatterResult(group.name, "".join(output), 0)
return FormatterResult(group.name, "", 0)
def main() -> int:
@@ -191,16 +180,13 @@ def main() -> int:
failures: list[str] = []
with ThreadPoolExecutor(max_workers=len(groups)) as executor:
futures = {}
for group in groups:
print(f"Starting {group.name} formatter...", flush=True)
futures[executor.submit(run_formatter_group, group)] = group.name
futures = [executor.submit(run_formatter_group, group) for group in groups]
for future in as_completed(futures):
result = future.result()
print(f"==> {result.name} formatter finished")
print(result.output, end="")
if result.returncode != 0:
failures.append(result.name)
print(f"==> {result.name} formatter failed", file=sys.stderr)
print(result.output, end="", file=sys.stderr)
if failures:
print(f"Formatting failed: {', '.join(failures)}", file=sys.stderr)