Skip to content

Commit

Permalink
Support shell expansion for --config argument
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Feb 21, 2023
1 parent d93c581 commit 6b1700e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/ruff_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
Expand Down
12 changes: 9 additions & 3 deletions crates/ruff_cli/src/resolve.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
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,
};
use ruff::settings::configuration::Configuration;
use ruff::settings::{pyproject, AllSettings};
use shellexpand;

use crate::args::Overrides;

Expand All @@ -29,8 +31,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));
}

Expand Down

0 comments on commit 6b1700e

Please sign in to comment.