fix ENH: Allow setting default output-format in pyproject.toml / pyrefly.toml #2688#2786
fix ENH: Allow setting default output-format in pyproject.toml / pyrefly.toml #2688#2786asukaminato0721 wants to merge 1 commit intofacebook:mainfrom
Conversation
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
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-formatas a project-level config option. - Add
output_formattoConfigFile(TOML/pyproject parsing) with tests. - Update
pyrefly checkCLI handling to treat--output-formatas 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.
| 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() | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| handle.path(), | ||
| ); | ||
| self.output.baseline = config.baseline.clone(); | ||
| self.output.inherit_defaults_from_config(&config); |
There was a problem hiding this comment.
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.
| self.output.inherit_defaults_from_config(&config); | |
| self.output | |
| .refresh_from_config_when_not_overridden( | |
| cli_provided_baseline, | |
| cli_provided_output_format, | |
| &config, | |
| ); |
| @@ -19,6 +19,7 @@ use std::time::Instant; | |||
| use anyhow::Context; | |||
| use anyhow::Result; | |||
| use anyhow::anyhow; | |||
There was a problem hiding this comment.
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.
| use anyhow::anyhow; | |
| use anyhow::anyhow; | |
| #[cfg(feature = "cli")] |
| #[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, | ||
| } |
There was a problem hiding this comment.
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.
| @@ -210,8 +223,8 @@ struct OutputArgs { | |||
| #[arg(long, short = 'o', value_name = "OUTPUT_FILE")] | |||
| output: Option<PathBuf>, | |||
| /// Set the error output format. | |||
There was a problem hiding this comment.
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.
| /// 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. |
This comment has been minimized.
This comment has been minimized.
|
According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅ |
Summary
Fixes #2688
output-format is now a recognized project-level config option in both
pyrefly.tomland[tool.pyrefly]inpyproject.toml, and pyrefly check will inherit it only when--output-formatis not set on the CLI.Test Plan
add test