mirror of https://github.com/astral-sh/ruff
Find user configuration even if there’s no project directory (#216)
This commit is contained in:
parent
9bdb922c75
commit
b8f878df5e
|
|
@ -10,8 +10,8 @@ use crate::checks::CheckCode;
|
|||
use crate::fs;
|
||||
|
||||
pub fn load_config(paths: &[PathBuf]) -> Config {
|
||||
match find_project_root(paths) {
|
||||
Some(project_root) => match find_pyproject_toml(&project_root) {
|
||||
let project_root = find_project_root(paths);
|
||||
match find_pyproject_toml(project_root.as_deref()) {
|
||||
Some(path) => {
|
||||
debug!("Found pyproject.toml at: {:?}", path);
|
||||
match parse_pyproject_toml(&path) {
|
||||
|
|
@ -27,8 +27,6 @@ pub fn load_config(paths: &[PathBuf]) -> Config {
|
|||
}
|
||||
}
|
||||
None => Default::default(),
|
||||
},
|
||||
None => Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -57,11 +55,14 @@ fn parse_pyproject_toml(path: &Path) -> Result<PyProject> {
|
|||
toml::from_str(&contents).map_err(|e| e.into())
|
||||
}
|
||||
|
||||
fn find_pyproject_toml(path: &Path) -> Option<PathBuf> {
|
||||
fn find_pyproject_toml(path: Option<&Path>) -> Option<PathBuf> {
|
||||
if let Some(path) = path {
|
||||
let path_pyproject_toml = path.join("pyproject.toml");
|
||||
if path_pyproject_toml.is_file() {
|
||||
return Some(path_pyproject_toml);
|
||||
}
|
||||
}
|
||||
|
||||
find_user_pyproject_toml()
|
||||
}
|
||||
|
||||
|
|
@ -252,7 +253,8 @@ other-attribute = 1
|
|||
.expect("Unable to find project root.");
|
||||
assert_eq!(project_root, cwd.join("resources/test/fixtures"));
|
||||
|
||||
let path = find_pyproject_toml(&project_root).expect("Unable to find pyproject.toml.");
|
||||
let path =
|
||||
find_pyproject_toml(Some(&project_root)).expect("Unable to find pyproject.toml.");
|
||||
assert_eq!(path, cwd.join("resources/test/fixtures/pyproject.toml"));
|
||||
|
||||
let pyproject = parse_pyproject_toml(&path)?;
|
||||
|
|
|
|||
Loading…
Reference in New Issue