Skip to content

fix ENH: Allow setting default output-format in pyproject.toml / pyrefly.toml #2688#2786

Open
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2688
Open

fix ENH: Allow setting default output-format in pyproject.toml / pyrefly.toml #2688#2786
asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
asukaminato0721:2688

Conversation

@asukaminato0721
Copy link
Contributor

Summary

Fixes #2688

output-format is now a recognized project-level config option in both pyrefly.toml and [tool.pyrefly] in pyproject.toml, and pyrefly check will inherit it only when --output-format is not set on the CLI.

Test Plan

add test

@meta-cla meta-cla bot added the cla signed label Mar 12, 2026
@github-actions

This comment has been minimized.

@asukaminato0721 asukaminato0721 marked this pull request as ready for review March 12, 2026 18:59
Copilot AI review requested due to automatic review settings March 12, 2026 19:00
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds support for configuring output-format at the project level so pyrefly check uses it when the CLI --output-format flag is not provided.

Changes:

  • Document output-format as a project-level config option.
  • Add output_format to ConfigFile (TOML/pyproject parsing) with tests.
  • Update pyrefly check CLI handling to treat --output-format as optional and inherit from config.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
website/docs/configuration.mdx Documents new output-format configuration option and precedence rules.
pyrefly/lib/commands/check.rs Changes CLI arg to Option, inherits config defaults, and threads chosen format into output writing; adds tests.
crates/pyrefly_config/src/config.rs Introduces OutputFormat in config schema and parses/serializes output-format; updates config parsing tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +311 to +324
impl OutputArgs {
fn inherit_defaults_from_config(&mut self, config: &ConfigFile) {
if self.baseline.is_none() {
self.baseline = config.baseline.clone();
}
if self.output_format.is_none() {
self.output_format = config.output_format.map(OutputFormat::from);
}
}

fn output_format(&self) -> OutputFormat {
self.output_format.clone().unwrap_or_default()
}
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit_defaults_from_config only fills fields when they are None, but the watch-mode loop comment says it should 'pick up config file changes'. After the first iteration, inherited values become Some(...) and will no longer update if the config changes (unless the CLI explicitly set them). To preserve hot-reload behavior, update the loop to overwrite baseline / output_format from config when !cli_provided_* (even if currently Some), or add a dedicated method (e.g. refresh_from_config_when_not_overridden(cli_provided_baseline, cli_provided_output_format, config)) that can overwrite existing values.

Copilot uses AI. Check for mistakes.
handle.path(),
);
self.output.baseline = config.baseline.clone();
self.output.inherit_defaults_from_config(&config);
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit_defaults_from_config only fills fields when they are None, but the watch-mode loop comment says it should 'pick up config file changes'. After the first iteration, inherited values become Some(...) and will no longer update if the config changes (unless the CLI explicitly set them). To preserve hot-reload behavior, update the loop to overwrite baseline / output_format from config when !cli_provided_* (even if currently Some), or add a dedicated method (e.g. refresh_from_config_when_not_overridden(cli_provided_baseline, cli_provided_output_format, config)) that can overwrite existing values.

Suggested change
self.output.inherit_defaults_from_config(&config);
self.output
.refresh_from_config_when_not_overridden(
cli_provided_baseline,
cli_provided_output_format,
&config,
);

Copilot uses AI. Check for mistakes.
@@ -19,6 +19,7 @@ use std::time::Instant;
use anyhow::Context;
use anyhow::Result;
use anyhow::anyhow;
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the config crate depend on clap just to derive ValueEnum. If pyrefly_config is intended to be a general-purpose library (used beyond the CLI), pulling clap into it increases coupling and can add compile-time overhead. Consider keeping the config enum purely serde-driven and performing string/enum mapping in the CLI crate (or feature-gating the ValueEnum derive behind a cli feature) to keep config parsing concerns separate from CLI concerns.

Suggested change
use anyhow::anyhow;
use anyhow::anyhow;
#[cfg(feature = "cli")]

Copilot uses AI. Check for mistakes.
Comment on lines +101 to +125
#[derive(
Debug,
PartialEq,
Eq,
Deserialize,
Serialize,
Clone,
Copy,
Default,
ValueEnum
)]
#[serde(rename_all = "kebab-case")]
pub enum OutputFormat {
/// Minimal text output, one line per error
MinText,
#[default]
/// Full, verbose text output
FullText,
/// JSON output
Json,
/// Emit GitHub Actions workflow commands
Github,
/// Only show error count, omitting individual errors
OmitErrors,
}
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes the config crate depend on clap just to derive ValueEnum. If pyrefly_config is intended to be a general-purpose library (used beyond the CLI), pulling clap into it increases coupling and can add compile-time overhead. Consider keeping the config enum purely serde-driven and performing string/enum mapping in the CLI crate (or feature-gating the ValueEnum derive behind a cli feature) to keep config parsing concerns separate from CLI concerns.

Copilot uses AI. Check for mistakes.
@@ -210,8 +223,8 @@ struct OutputArgs {
#[arg(long, short = 'o', value_name = "OUTPUT_FILE")]
output: Option<PathBuf>,
/// Set the error output format.
Copy link

Copilot AI Mar 12, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that --output-format is optional (so config can supply it), the CLI help text no longer communicates the effective default (full-text) and precedence (CLI overrides config). Update the doc comment/arg help to explicitly state the default and that the config output-format is used only when the flag is absent, so behavior matches what’s documented in the website docs.

Suggested change
/// Set the error output format.
/// Set the error output format.
///
/// Defaults to `full-text` when neither this flag nor a config
/// `output-format` is provided. If both are set, this flag overrides
/// the config. The config `output-format` is only used when this
/// flag is omitted.

Copilot uses AI. Check for mistakes.
@github-actions

This comment has been minimized.

@github-actions
Copy link

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ENH: Allow setting default output-format in pyproject.toml / pyrefly.toml

2 participants