From 4ed88dd245c29a170725167b1ee679a1bc17ca62 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 20 Sep 2022 12:26:32 -0400 Subject: [PATCH] Follow-up fixes to path absolution (#235) --- src/fs.rs | 8 +------- src/pyproject.rs | 9 +++++---- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/src/fs.rs b/src/fs.rs index 72ba732ca5..5d61701617 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -66,7 +66,7 @@ pub fn iter_python_files<'a>( let exclude_simple = exclude .iter() .all(|pattern| matches!(pattern, FilePattern::Simple(_))); - let extend_exclude_simple = exclude + let extend_exclude_simple = extend_exclude .iter() .all(|pattern| matches!(pattern, FilePattern::Simple(_))); @@ -114,9 +114,6 @@ pub fn iter_python_files<'a>( /// Convert any path to an absolute path (based on the current working directory). pub fn normalize_path(path: &Path) -> PathBuf { - if path == Path::new(".") || path == Path::new("..") { - return path.to_path_buf(); - } if let Ok(path) = path.absolutize() { return path.to_path_buf(); } @@ -125,9 +122,6 @@ pub fn normalize_path(path: &Path) -> PathBuf { /// Convert any path to an absolute path (based on the specified project root). pub fn normalize_path_to(path: &Path, project_root: &Path) -> PathBuf { - if path == Path::new(".") || path == Path::new("..") { - return path.to_path_buf(); - } if let Ok(path) = path.absolutize_from(project_root) { return path.to_path_buf(); } diff --git a/src/pyproject.rs b/src/pyproject.rs index 8e65e04a65..7b3a6d8151 100644 --- a/src/pyproject.rs +++ b/src/pyproject.rs @@ -1,9 +1,8 @@ -use std::ops::Deref; use std::path::{Path, PathBuf}; use anyhow::Result; use common_path::common_path_all; -use path_absolutize::path_dedot; +use path_absolutize::Absolutize; use serde::Deserialize; use crate::checks::CheckCode; @@ -78,8 +77,10 @@ fn find_user_pyproject_toml() -> Option { } pub fn find_project_root(sources: &[PathBuf]) -> Option { - let cwd = path_dedot::CWD.deref(); - let absolute_sources: Vec = sources.iter().map(|source| cwd.join(source)).collect(); + let absolute_sources: Vec = sources + .iter() + .flat_map(|source| source.absolutize().map(|path| path.to_path_buf())) + .collect(); if let Some(prefix) = common_path_all(absolute_sources.iter().map(PathBuf::as_path)) { for directory in prefix.ancestors() { if directory.join(".git").is_dir() {