mirror of https://github.com/astral-sh/ruff
Add a no-parallel mode
This commit is contained in:
parent
a8c1915e2e
commit
d436cd560a
|
|
@ -95,6 +95,9 @@ pub struct CheckArgs {
|
||||||
/// Ignore any `# noqa` comments.
|
/// Ignore any `# noqa` comments.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
ignore_noqa: bool,
|
ignore_noqa: bool,
|
||||||
|
/// Run in a single thread, rather than using all available cores.
|
||||||
|
#[clap(long, hide = true)]
|
||||||
|
no_parallel: bool,
|
||||||
/// Output serialization format for violations.
|
/// Output serialization format for violations.
|
||||||
#[arg(long, value_enum, env = "RUFF_FORMAT")]
|
#[arg(long, value_enum, env = "RUFF_FORMAT")]
|
||||||
pub format: Option<SerializationFormat>,
|
pub format: Option<SerializationFormat>,
|
||||||
|
|
@ -267,6 +270,7 @@ pub struct CheckArgs {
|
||||||
conflicts_with = "show_settings",
|
conflicts_with = "show_settings",
|
||||||
// Unsupported default-command arguments.
|
// Unsupported default-command arguments.
|
||||||
conflicts_with = "ignore_noqa",
|
conflicts_with = "ignore_noqa",
|
||||||
|
conflicts_with = "no_parallel",
|
||||||
conflicts_with = "statistics",
|
conflicts_with = "statistics",
|
||||||
conflicts_with = "stdin_filename",
|
conflicts_with = "stdin_filename",
|
||||||
conflicts_with = "watch",
|
conflicts_with = "watch",
|
||||||
|
|
@ -282,6 +286,7 @@ pub struct CheckArgs {
|
||||||
conflicts_with = "show_settings",
|
conflicts_with = "show_settings",
|
||||||
// Unsupported default-command arguments.
|
// Unsupported default-command arguments.
|
||||||
conflicts_with = "ignore_noqa",
|
conflicts_with = "ignore_noqa",
|
||||||
|
conflicts_with = "no_parallel",
|
||||||
conflicts_with = "statistics",
|
conflicts_with = "statistics",
|
||||||
conflicts_with = "stdin_filename",
|
conflicts_with = "stdin_filename",
|
||||||
conflicts_with = "watch",
|
conflicts_with = "watch",
|
||||||
|
|
@ -296,6 +301,7 @@ pub struct CheckArgs {
|
||||||
// conflicts_with = "show_settings",
|
// conflicts_with = "show_settings",
|
||||||
// Unsupported default-command arguments.
|
// Unsupported default-command arguments.
|
||||||
conflicts_with = "ignore_noqa",
|
conflicts_with = "ignore_noqa",
|
||||||
|
conflicts_with = "no_parallel",
|
||||||
conflicts_with = "statistics",
|
conflicts_with = "statistics",
|
||||||
conflicts_with = "stdin_filename",
|
conflicts_with = "stdin_filename",
|
||||||
conflicts_with = "watch",
|
conflicts_with = "watch",
|
||||||
|
|
@ -371,6 +377,7 @@ impl CheckArgs {
|
||||||
ignore_noqa: self.ignore_noqa,
|
ignore_noqa: self.ignore_noqa,
|
||||||
isolated: self.isolated,
|
isolated: self.isolated,
|
||||||
no_cache: self.no_cache,
|
no_cache: self.no_cache,
|
||||||
|
no_parallel: self.no_parallel,
|
||||||
show_files: self.show_files,
|
show_files: self.show_files,
|
||||||
show_settings: self.show_settings,
|
show_settings: self.show_settings,
|
||||||
statistics: self.statistics,
|
statistics: self.statistics,
|
||||||
|
|
@ -435,6 +442,7 @@ pub struct Arguments {
|
||||||
pub ignore_noqa: bool,
|
pub ignore_noqa: bool,
|
||||||
pub isolated: bool,
|
pub isolated: bool,
|
||||||
pub no_cache: bool,
|
pub no_cache: bool,
|
||||||
|
pub no_parallel: bool,
|
||||||
pub show_files: bool,
|
pub show_files: bool,
|
||||||
pub show_settings: bool,
|
pub show_settings: bool,
|
||||||
pub statistics: bool,
|
pub statistics: bool,
|
||||||
|
|
|
||||||
|
|
@ -140,6 +140,7 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
|
||||||
};
|
};
|
||||||
let cache = !cli.no_cache;
|
let cache = !cli.no_cache;
|
||||||
let noqa = !cli.ignore_noqa;
|
let noqa = !cli.ignore_noqa;
|
||||||
|
let parallel = !cli.no_parallel;
|
||||||
let mut printer_flags = PrinterFlags::empty();
|
let mut printer_flags = PrinterFlags::empty();
|
||||||
if !(cli.diff || fix_only) {
|
if !(cli.diff || fix_only) {
|
||||||
printer_flags |= PrinterFlags::SHOW_VIOLATIONS;
|
printer_flags |= PrinterFlags::SHOW_VIOLATIONS;
|
||||||
|
|
@ -155,6 +156,14 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
|
||||||
warn_user_once!("Detected debug build without --no-cache.");
|
warn_user_once!("Detected debug build without --no-cache.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !parallel {
|
||||||
|
// If we're not running in parallel, we need to set up a single-threaded
|
||||||
|
// executor.
|
||||||
|
rayon::ThreadPoolBuilder::new()
|
||||||
|
.num_threads(1)
|
||||||
|
.build_global()?;
|
||||||
|
}
|
||||||
|
|
||||||
if cli.add_noqa {
|
if cli.add_noqa {
|
||||||
if !matches!(autofix, fix::FixMode::None) {
|
if !matches!(autofix, fix::FixMode::None) {
|
||||||
warn_user_once!("--fix is incompatible with --add-noqa.");
|
warn_user_once!("--fix is incompatible with --add-noqa.");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue