mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-28 04:45:01 +00:00
Show settings path in --show-settings
output (#4199)
This commit is contained in:
parent
37aae666c7
commit
59d40f9f81
9 changed files with 152 additions and 102 deletions
|
@ -12,7 +12,7 @@ use ruff_text_size::{TextRange, TextSize};
|
|||
|
||||
use ruff::message::Message;
|
||||
use ruff::registry::Rule;
|
||||
use ruff::resolver::PyprojectDiscovery;
|
||||
use ruff::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
use ruff::settings::{flags, AllSettings};
|
||||
use ruff::{fs, packaging, resolver, warn_user_once, IOError};
|
||||
use ruff_diagnostics::Diagnostic;
|
||||
|
@ -27,7 +27,7 @@ use crate::panic::catch_unwind;
|
|||
/// Run the linter over a collection of files.
|
||||
pub fn run(
|
||||
files: &[PathBuf],
|
||||
pyproject_strategy: &PyprojectDiscovery,
|
||||
pyproject_config: &PyprojectConfig,
|
||||
overrides: &Overrides,
|
||||
cache: flags::Cache,
|
||||
noqa: flags::Noqa,
|
||||
|
@ -35,7 +35,7 @@ pub fn run(
|
|||
) -> Result<Diagnostics> {
|
||||
// Collect all the Python files to check.
|
||||
let start = Instant::now();
|
||||
let (paths, resolver) = resolver::python_files_in_path(files, pyproject_strategy, overrides)?;
|
||||
let (paths, resolver) = resolver::python_files_in_path(files, pyproject_config, overrides)?;
|
||||
let duration = start.elapsed();
|
||||
debug!("Identified files to lint in: {:?}", duration);
|
||||
|
||||
|
@ -52,12 +52,12 @@ pub fn run(
|
|||
}
|
||||
}
|
||||
|
||||
match &pyproject_strategy {
|
||||
PyprojectDiscovery::Fixed(settings) => {
|
||||
init_cache(&settings.cli.cache_dir);
|
||||
match pyproject_config.strategy {
|
||||
PyprojectDiscoveryStrategy::Fixed => {
|
||||
init_cache(&pyproject_config.settings.cli.cache_dir);
|
||||
}
|
||||
PyprojectDiscovery::Hierarchical(default) => {
|
||||
for settings in std::iter::once(default).chain(resolver.iter()) {
|
||||
PyprojectDiscoveryStrategy::Hierarchical => {
|
||||
for settings in std::iter::once(&pyproject_config.settings).chain(resolver.iter()) {
|
||||
init_cache(&settings.cli.cache_dir);
|
||||
}
|
||||
}
|
||||
|
@ -72,7 +72,7 @@ pub fn run(
|
|||
.map(ignore::DirEntry::path)
|
||||
.collect::<Vec<_>>(),
|
||||
&resolver,
|
||||
pyproject_strategy,
|
||||
pyproject_config,
|
||||
);
|
||||
|
||||
let start = Instant::now();
|
||||
|
@ -86,7 +86,7 @@ pub fn run(
|
|||
.parent()
|
||||
.and_then(|parent| package_roots.get(parent))
|
||||
.and_then(|package| *package);
|
||||
let settings = resolver.resolve_all(path, pyproject_strategy);
|
||||
let settings = resolver.resolve_all(path, pyproject_config);
|
||||
|
||||
lint_path(path, package, settings, cache, noqa, autofix).map_err(|e| {
|
||||
(Some(path.to_owned()), {
|
||||
|
@ -116,7 +116,7 @@ pub fn run(
|
|||
fs::relativize_path(path).bold(),
|
||||
":".bold()
|
||||
);
|
||||
let settings = resolver.resolve(path, pyproject_strategy);
|
||||
let settings = resolver.resolve(path, pyproject_config);
|
||||
if settings.rules.enabled(Rule::IOError) {
|
||||
let file =
|
||||
SourceFileBuilder::new(path.to_string_lossy().as_ref(), "").finish();
|
||||
|
@ -196,7 +196,7 @@ mod test {
|
|||
use path_absolutize::Absolutize;
|
||||
|
||||
use ruff::logging::LogLevel;
|
||||
use ruff::resolver::PyprojectDiscovery;
|
||||
use ruff::resolver::{PyprojectConfig, PyprojectDiscoveryStrategy};
|
||||
use ruff::settings::configuration::{Configuration, RuleSelection};
|
||||
use ruff::settings::flags::FixMode;
|
||||
use ruff::settings::flags::{Cache, Noqa};
|
||||
|
@ -238,7 +238,11 @@ mod test {
|
|||
|
||||
let diagnostics = run(
|
||||
&[root_path.join("valid.ipynb")],
|
||||
&PyprojectDiscovery::Fixed(AllSettings::from_configuration(configuration, &root_path)?),
|
||||
&PyprojectConfig::new(
|
||||
PyprojectDiscoveryStrategy::Fixed,
|
||||
AllSettings::from_configuration(configuration, &root_path)?,
|
||||
None,
|
||||
),
|
||||
&overrides,
|
||||
Cache::Disabled,
|
||||
Noqa::Enabled,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue