Add a no-parallel mode

This commit is contained in:
Charlie Marsh 2023-03-13 16:16:59 -04:00
parent a8c1915e2e
commit d436cd560a
2 changed files with 17 additions and 0 deletions

View File

@ -95,6 +95,9 @@ pub struct CheckArgs {
/// Ignore any `# noqa` comments.
#[arg(long)]
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.
#[arg(long, value_enum, env = "RUFF_FORMAT")]
pub format: Option<SerializationFormat>,
@ -267,6 +270,7 @@ pub struct CheckArgs {
conflicts_with = "show_settings",
// Unsupported default-command arguments.
conflicts_with = "ignore_noqa",
conflicts_with = "no_parallel",
conflicts_with = "statistics",
conflicts_with = "stdin_filename",
conflicts_with = "watch",
@ -282,6 +286,7 @@ pub struct CheckArgs {
conflicts_with = "show_settings",
// Unsupported default-command arguments.
conflicts_with = "ignore_noqa",
conflicts_with = "no_parallel",
conflicts_with = "statistics",
conflicts_with = "stdin_filename",
conflicts_with = "watch",
@ -296,6 +301,7 @@ pub struct CheckArgs {
// conflicts_with = "show_settings",
// Unsupported default-command arguments.
conflicts_with = "ignore_noqa",
conflicts_with = "no_parallel",
conflicts_with = "statistics",
conflicts_with = "stdin_filename",
conflicts_with = "watch",
@ -371,6 +377,7 @@ impl CheckArgs {
ignore_noqa: self.ignore_noqa,
isolated: self.isolated,
no_cache: self.no_cache,
no_parallel: self.no_parallel,
show_files: self.show_files,
show_settings: self.show_settings,
statistics: self.statistics,
@ -435,6 +442,7 @@ pub struct Arguments {
pub ignore_noqa: bool,
pub isolated: bool,
pub no_cache: bool,
pub no_parallel: bool,
pub show_files: bool,
pub show_settings: bool,
pub statistics: bool,

View File

@ -140,6 +140,7 @@ fn check(args: CheckArgs, log_level: LogLevel) -> Result<ExitStatus> {
};
let cache = !cli.no_cache;
let noqa = !cli.ignore_noqa;
let parallel = !cli.no_parallel;
let mut printer_flags = PrinterFlags::empty();
if !(cli.diff || fix_only) {
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.");
}
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 !matches!(autofix, fix::FixMode::None) {
warn_user_once!("--fix is incompatible with --add-noqa.");