Skip to content

Commit

Permalink
Show settings path in --show-settings output
Browse files Browse the repository at this point in the history
  • Loading branch information
dhruvmanila committed May 3, 2023
1 parent 64b7280 commit b264067
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
6 changes: 5 additions & 1 deletion crates/ruff/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,11 @@ pub fn resolve_scoped_settings(
) -> Result<(PathBuf, AllSettings)> {
let configuration = resolve_configuration(pyproject, relativity, processor)?;
let project_root = relativity.resolve(pyproject);
let settings = AllSettings::from_configuration(configuration, &project_root)?;
let settings = AllSettings::from_configuration(
configuration,
&project_root,
Some(pyproject.to_path_buf()),
)?;
Ok((project_root, settings))
}

Expand Down
13 changes: 12 additions & 1 deletion crates/ruff/src/settings/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use strum::IntoEnumIterator;
use ruff_cache::cache_dir;
use ruff_macros::CacheKey;

use crate::fs;
use crate::registry::{Rule, RuleNamespace, RuleSet, INCOMPATIBLE_CODES};
use crate::rule_selector::{RuleSelector, Specificity};
use crate::rules::{
Expand Down Expand Up @@ -43,10 +44,15 @@ const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
pub struct AllSettings {
pub cli: CliSettings,
pub lib: Settings,
settings_path: Option<PathBuf>,
}

impl AllSettings {
pub fn from_configuration(config: Configuration, project_root: &Path) -> Result<Self> {
pub fn from_configuration(
config: Configuration,
project_root: &Path,
settings_path: Option<PathBuf>,
) -> Result<Self> {
Ok(Self {
cli: CliSettings {
cache_dir: config
Expand All @@ -60,8 +66,13 @@ impl AllSettings {
update_check: config.update_check.unwrap_or_default(),
},
lib: Settings::from_configuration(config, project_root)?,
settings_path: settings_path.map(fs::normalize_path),
})
}

pub fn settings_path(&self) -> Option<&Path> {
self.settings_path.as_deref()
}
}

#[derive(Debug, Default, Clone)]
Expand Down
6 changes: 5 additions & 1 deletion crates/ruff_cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ mod test {

let diagnostics = run(
&[root_path.join("valid.ipynb")],
&PyprojectDiscovery::Fixed(AllSettings::from_configuration(configuration, &root_path)?),
&PyprojectDiscovery::Fixed(AllSettings::from_configuration(
configuration,
&root_path,
None,
)?),
&overrides,
Cache::Disabled,
Noqa::Enabled,
Expand Down
3 changes: 3 additions & 0 deletions crates/ruff_cli/src/commands/show_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ pub fn show_settings(

let mut stdout = BufWriter::new(io::stdout().lock());
writeln!(stdout, "Resolved settings for: {path:?}")?;
if let Some(settings_path) = pyproject_strategy.top_level_settings().settings_path() {
writeln!(stdout, "Settings path: {settings_path:?}")?;
}
writeln!(stdout, "{settings:#?}")?;

Ok(())
Expand Down
4 changes: 2 additions & 2 deletions crates/ruff_cli/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn resolve(
if isolated {
let mut config = Configuration::default();
overrides.process_config(&mut config);
let settings = AllSettings::from_configuration(config, &path_dedot::CWD)?;
let settings = AllSettings::from_configuration(config, &path_dedot::CWD, None)?;
return Ok(PyprojectDiscovery::Fixed(settings));
}

Expand Down Expand Up @@ -68,6 +68,6 @@ pub fn resolve(
// as the "default" settings.)
let mut config = Configuration::default();
overrides.process_config(&mut config);
let settings = AllSettings::from_configuration(config, &path_dedot::CWD)?;
let settings = AllSettings::from_configuration(config, &path_dedot::CWD, None)?;
Ok(PyprojectDiscovery::Hierarchical(settings))
}

0 comments on commit b264067

Please sign in to comment.