Support shell expansion for --config argument (#3107)

This commit is contained in:
Charlie Marsh 2023-02-21 18:33:41 -05:00 committed by GitHub
parent 18800c6884
commit 9645790a8b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 3 deletions

1
Cargo.lock generated
View file

@ -2012,6 +2012,7 @@ dependencies = [
"rustc-hash", "rustc-hash",
"serde", "serde",
"serde_json", "serde_json",
"shellexpand",
"similar", "similar",
"strum", "strum",
"textwrap", "textwrap",

View file

@ -50,6 +50,7 @@ regex = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
shellexpand = { version = "3.0.0" }
similar = { version = "2.2.1" } similar = { version = "2.2.1" }
strum = { version = "0.24.1" } strum = { version = "0.24.1" }
textwrap = { version = "0.16.0" } textwrap = { version = "0.16.0" }

View file

@ -1,7 +1,8 @@
use std::path::Path; use std::path::{Path, PathBuf};
use anyhow::Result; use anyhow::Result;
use path_absolutize::path_dedot; use path_absolutize::path_dedot;
use ruff::resolver::{ use ruff::resolver::{
resolve_settings_with_processor, ConfigProcessor, PyprojectDiscovery, Relativity, 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 // Second priority: the user specified a `pyproject.toml` file. Use that
// `pyproject.toml` for _all_ configuration, and resolve paths relative to the // `pyproject.toml` for _all_ configuration, and resolve paths relative to the
// current working directory. (This matches ESLint's behavior.) // current working directory. (This matches ESLint's behavior.)
if let Some(pyproject) = config { if let Some(pyproject) = config
let settings = resolve_settings_with_processor(pyproject, &Relativity::Cwd, overrides)?; .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)); return Ok(PyprojectDiscovery::Fixed(settings));
} }