Change a few methods to take AsRef<Path>
This commit is contained in:
@@ -64,7 +64,7 @@ pub fn relativize_path(path: &Path) -> Cow<str> {
|
||||
}
|
||||
|
||||
/// Read a file's contents from disk.
|
||||
pub(crate) fn read_file(path: &Path) -> Result<String> {
|
||||
pub(crate) fn read_file<P: AsRef<Path>>(path: P) -> Result<String> {
|
||||
let file = File::open(path)?;
|
||||
let mut buf_reader = BufReader::new(file);
|
||||
let mut contents = String::new();
|
||||
|
||||
@@ -28,13 +28,13 @@ impl Pyproject {
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_pyproject_toml(path: &Path) -> Result<Pyproject> {
|
||||
fn parse_pyproject_toml<P: AsRef<Path>>(path: P) -> Result<Pyproject> {
|
||||
let contents = fs::read_file(path)?;
|
||||
toml::from_str(&contents).map_err(std::convert::Into::into)
|
||||
}
|
||||
|
||||
/// Return `true` if a `pyproject.toml` contains a `[tool.ruff]` section.
|
||||
pub fn has_ruff_section(path: &Path) -> Result<bool> {
|
||||
pub fn has_ruff_section<P: AsRef<Path>>(path: P) -> Result<bool> {
|
||||
let pyproject = parse_pyproject_toml(path)?;
|
||||
Ok(pyproject.tool.and_then(|tool| tool.ruff).is_some())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user