Support shell expansion in `extend` paths (#1323)

This commit is contained in:
Charlie Marsh 2022-12-21 20:46:38 -05:00 committed by GitHub
parent 66a6c81ebf
commit bf5fec342c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 3 deletions

10
Cargo.lock generated
View File

@ -1890,6 +1890,7 @@ dependencies = [
"rustpython-parser", "rustpython-parser",
"serde", "serde",
"serde_json", "serde_json",
"shellexpand",
"strum", "strum",
"strum_macros", "strum_macros",
"test-case", "test-case",
@ -2116,6 +2117,15 @@ dependencies = [
"serde", "serde",
] ]
[[package]]
name = "shellexpand"
version = "3.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd1c7ddea665294d484c39fd0c0d2b7e35bbfe10035c5fe1854741a57f6880e1"
dependencies = [
"dirs 4.0.0",
]
[[package]] [[package]]
name = "similar" name = "similar"
version = "2.2.1" version = "2.2.1"

View File

@ -50,6 +50,7 @@ rustpython-common = { git = "https://github.com/RustPython/RustPython.git", rev
rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "c01f014b1269eedcf4bdb45d5fbc62ae2beecf31" } rustpython-parser = { features = ["lalrpop"], git = "https://github.com/RustPython/RustPython.git", rev = "c01f014b1269eedcf4bdb45d5fbc62ae2beecf31" }
serde = { version = "1.0.147", features = ["derive"] } serde = { version = "1.0.147", features = ["derive"] }
serde_json = { version = "1.0.87" } serde_json = { version = "1.0.87" }
shellexpand = { version = "3.0.0" }
strum = { version = "0.24.1", features = ["strum_macros"] } strum = { version = "0.24.1", features = ["strum_macros"] }
strum_macros = { version = "0.24.3" } strum_macros = { version = "0.24.3" }
textwrap = { version = "0.16.0" } textwrap = { version = "0.16.0" }

View File

@ -1632,7 +1632,8 @@ exclude = [".venv"]
#### [`extend`](#extend) #### [`extend`](#extend)
A path to a local `pyproject.toml` file to merge into this configuration. A path to a local `pyproject.toml` file to merge into this configuration. User home
directory and environment variables will be expanded.
To resolve the current `pyproject.toml` file, Ruff will first resolve this base To resolve the current `pyproject.toml` file, Ruff will first resolve this base
configuration file, then merge in any properties defined in the current configuration configuration file, then merge in any properties defined in the current configuration

View File

@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use glob::{glob, GlobError, Paths, PatternError}; use glob::{glob, GlobError, Paths, PatternError};
use regex::Regex; use regex::Regex;
use shellexpand;
use crate::checks_gen::CheckCodePrefix; use crate::checks_gen::CheckCodePrefix;
use crate::cli::{collect_per_file_ignores, Overrides}; use crate::cli::{collect_per_file_ignores, Overrides};
@ -78,7 +79,14 @@ impl Configuration {
}) })
.collect() .collect()
}), }),
extend: options.extend.map(PathBuf::from), extend: options
.extend
.map(|extend| {
let extend = shellexpand::full(&extend);
extend.map(|extend| PathBuf::from(extend.as_ref()))
})
.transpose()
.map_err(|e| anyhow!("Invalid `extend` value: {e}"))?,
extend_exclude: options extend_exclude: options
.extend_exclude .extend_exclude
.map(|paths| { .map(|paths| {

View File

@ -67,7 +67,8 @@ pub struct Options {
pub exclude: Option<Vec<String>>, pub exclude: Option<Vec<String>>,
#[option( #[option(
doc = r#" doc = r#"
A path to a local `pyproject.toml` file to merge into this configuration. A path to a local `pyproject.toml` file to merge into this configuration. User home
directory and environment variables will be expanded.
To resolve the current `pyproject.toml` file, Ruff will first resolve this base To resolve the current `pyproject.toml` file, Ruff will first resolve this base
configuration file, then merge in any properties defined in the current configuration configuration file, then merge in any properties defined in the current configuration