Better formatter CLI verbose output (#7129)

This commit is contained in:
konsti 2023-09-05 00:25:16 +02:00 committed by GitHub
parent 154fe7bdcc
commit 0465b03282
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 34 deletions

View file

@ -64,7 +64,7 @@ shellexpand = { workspace = true }
similar = { workspace = true }
strum = { workspace = true, features = [] }
thiserror = { workspace = true }
tracing = { workspace = true }
tracing = { workspace = true, features = ["log"] }
walkdir = { version = "2.3.2" }
wild = { version = "2" }

View file

@ -8,10 +8,10 @@ use std::time::Instant;
use anyhow::Result;
use colored::Colorize;
use log::{debug, warn};
use rayon::iter::Either::{Left, Right};
use rayon::iter::{IntoParallelIterator, ParallelIterator};
use thiserror::Error;
use tracing::{debug, warn};
use ruff::fs;
use ruff::logging::LogLevel;
@ -61,12 +61,14 @@ pub(crate) fn format(
let start = Instant::now();
let (results, errors): (Vec<_>, Vec<_>) = paths
.into_par_iter()
.filter_map(|entry| match entry {
.filter_map(|entry| {
match entry {
Ok(entry) => {
let path = entry.path();
let SourceType::Python(source_type @ (PySourceType::Python | PySourceType::Stub)) =
SourceType::from(path)
let SourceType::Python(
source_type @ (PySourceType::Python | PySourceType::Stub),
) = SourceType::from(path)
else {
// Ignore any non-Python files.
return None;
@ -75,16 +77,22 @@ pub(crate) fn format(
let line_length = resolver.resolve(path, &pyproject_config).line_length;
let options = PyFormatOptions::from_source_type(source_type)
.with_line_width(LineWidth::from(NonZeroU16::from(line_length)));
debug!("Formatting {} with {:?}", path.display(), options);
Some(format_path(path, options, mode))
}
Err(err) => Some(Err(FormatCommandError::Ignore(err))),
}
})
.partition_map(|result| match result {
Ok(diagnostic) => Left(diagnostic),
Err(err) => Right(err),
});
let duration = start.elapsed();
debug!("Formatted files in: {:?}", duration);
debug!(
"Formatted {} files in {:.2?}",
results.len() + errors.len(),
duration
);
let summary = FormatResultSummary::new(results, mode);

View file

@ -54,12 +54,12 @@ impl<'a> Printer<'a> {
/// Prints the passed in element as well as all its content,
/// starting at the specified indentation level
#[tracing::instrument(name = "Printer::print", skip_all)]
pub fn print_with_indent(
mut self,
document: &'a Document,
indent: u16,
) -> PrintResult<Printed> {
tracing::debug_span!("Printer::print").in_scope(move || {
let mut stack = PrintCallStack::new(PrintElementArgs::new(Indention::Level(indent)));
let mut queue: PrintQueue<'a> = PrintQueue::new(document.as_ref());
@ -79,7 +79,6 @@ impl<'a> Printer<'a> {
self.state.source_markers,
self.state.verbatim_markers,
))
})
}
/// Prints a single element and push the following elements to queue