fix: Emit a more useful error if an extend points at a non-existent ruff.toml file. (#3417)

This commit is contained in:
DanCardin 2023-03-09 14:55:09 -05:00 committed by GitHub
parent bd05a8a74d
commit 08ec11a31e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 9 deletions

View file

@ -127,7 +127,8 @@ pub fn resolve_configuration(
}
// Resolve the current path.
let options = pyproject::load_options(&path)?;
let options = pyproject::load_options(&path)
.map_err(|err| anyhow!("Failed to parse `{}`: {}", path.to_string_lossy(), err))?;
let project_root = relativity.resolve(&path);
let configuration = Configuration::from_options(options, &project_root)?;

View file

@ -2,7 +2,7 @@
use std::path::{Path, PathBuf};
use anyhow::{anyhow, Result};
use anyhow::Result;
use serde::{Deserialize, Serialize};
use crate::settings::options::Options;
@ -113,13 +113,7 @@ pub fn find_user_settings_toml() -> Option<PathBuf> {
/// Load `Options` from a `pyproject.toml` or `ruff.toml` file.
pub fn load_options<P: AsRef<Path>>(path: P) -> Result<Options> {
if path.as_ref().ends_with("pyproject.toml") {
let pyproject = parse_pyproject_toml(&path).map_err(|err| {
anyhow!(
"Failed to parse `{}`: {}",
path.as_ref().to_string_lossy(),
err
)
})?;
let pyproject = parse_pyproject_toml(&path)?;
Ok(pyproject
.tool
.and_then(|tool| tool.ruff)