Avoid parsing the root configuration twice (#10625)

This commit is contained in:
Micha Reiser 2024-05-01 11:28:30 +02:00 committed by GitHub
parent 068e22d382
commit 376fb71a7f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 37 additions and 30 deletions

View file

@ -335,6 +335,12 @@ pub fn python_files_in_path<'a>(
// Search for `pyproject.toml` files in all parent directories.
let mut resolver = Resolver::new(pyproject_config);
let mut seen = FxHashSet::default();
// Insert the path to the root configuration to avoid parsing the configuration a second time.
if let Some(config_path) = &pyproject_config.path {
seen.insert(config_path.parent().unwrap());
}
if resolver.is_hierarchical() {
for path in &paths {
for ancestor in path.ancestors() {
@ -343,8 +349,12 @@ pub fn python_files_in_path<'a>(
let (root, settings) =
resolve_scoped_settings(&pyproject, Relativity::Parent, transformer)?;
resolver.add(root, settings);
// We found the closest configuration.
break;
}
} else {
// We already visited this ancestor, we can stop here.
break;
}
}
}