mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 12:55:05 +00:00
Include package inference during --add-noqa command (#2832)
This commit is contained in:
parent
e2051ef72f
commit
46c184600f
2 changed files with 20 additions and 5 deletions
|
@ -8,7 +8,7 @@ use rayon::prelude::*;
|
|||
|
||||
use ruff::linter::add_noqa_to_path;
|
||||
use ruff::resolver::PyprojectDiscovery;
|
||||
use ruff::{resolver, warn_user_once};
|
||||
use ruff::{packaging, resolver, warn_user_once};
|
||||
|
||||
use crate::args::Overrides;
|
||||
use crate::iterators::par_iter;
|
||||
|
@ -30,13 +30,28 @@ pub fn add_noqa(
|
|||
return Ok(0);
|
||||
}
|
||||
|
||||
// Discover the package root for each Python file.
|
||||
let package_roots = packaging::detect_package_roots(
|
||||
&paths
|
||||
.iter()
|
||||
.flatten()
|
||||
.map(ignore::DirEntry::path)
|
||||
.collect::<Vec<_>>(),
|
||||
&resolver,
|
||||
pyproject_strategy,
|
||||
);
|
||||
|
||||
let start = Instant::now();
|
||||
let modifications: usize = par_iter(&paths)
|
||||
.flatten()
|
||||
.filter_map(|entry| {
|
||||
let path = entry.path();
|
||||
let package = path
|
||||
.parent()
|
||||
.and_then(|parent| package_roots.get(parent))
|
||||
.and_then(|package| *package);
|
||||
let settings = resolver.resolve(path, pyproject_strategy);
|
||||
match add_noqa_to_path(path, settings) {
|
||||
match add_noqa_to_path(path, package, settings) {
|
||||
Ok(count) => Some(count),
|
||||
Err(e) => {
|
||||
error!("Failed to add noqa to {}: {e}", path.to_string_lossy());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue