diff --git a/Cargo.lock b/Cargo.lock index bb39453709..094cd15605 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2012,6 +2012,7 @@ dependencies = [ "rustc-hash", "serde", "serde_json", + "shellexpand", "similar", "strum", "textwrap", diff --git a/crates/ruff_cli/Cargo.toml b/crates/ruff_cli/Cargo.toml index 6ac3e3bfa2..81e4bb290b 100644 --- a/crates/ruff_cli/Cargo.toml +++ b/crates/ruff_cli/Cargo.toml @@ -50,6 +50,7 @@ regex = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true } serde_json = { workspace = true } +shellexpand = { version = "3.0.0" } similar = { version = "2.2.1" } strum = { version = "0.24.1" } textwrap = { version = "0.16.0" } diff --git a/crates/ruff_cli/src/resolve.rs b/crates/ruff_cli/src/resolve.rs index c52166c6a5..40d3d809ca 100644 --- a/crates/ruff_cli/src/resolve.rs +++ b/crates/ruff_cli/src/resolve.rs @@ -1,7 +1,8 @@ -use std::path::Path; +use std::path::{Path, PathBuf}; use anyhow::Result; use path_absolutize::path_dedot; + use ruff::resolver::{ resolve_settings_with_processor, ConfigProcessor, PyprojectDiscovery, Relativity, }; @@ -29,8 +30,12 @@ pub fn resolve( // Second priority: the user specified a `pyproject.toml` file. Use that // `pyproject.toml` for _all_ configuration, and resolve paths relative to the // current working directory. (This matches ESLint's behavior.) - if let Some(pyproject) = config { - let settings = resolve_settings_with_processor(pyproject, &Relativity::Cwd, overrides)?; + if let Some(pyproject) = config + .map(|config| config.display().to_string()) + .map(|config| shellexpand::full(&config).map(|config| PathBuf::from(config.as_ref()))) + .transpose()? + { + let settings = resolve_settings_with_processor(&pyproject, &Relativity::Cwd, overrides)?; return Ok(PyprojectDiscovery::Fixed(settings)); }