Follow-up fixes to path absolution (#235)

This commit is contained in:
Charlie Marsh 2022-09-20 12:26:32 -04:00 committed by GitHub
parent 09b926fd59
commit 4ed88dd245
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 11 deletions

View File

@ -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();
}

View File

@ -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<PathBuf> {
}
pub fn find_project_root(sources: &[PathBuf]) -> Option<PathBuf> {
let cwd = path_dedot::CWD.deref();
let absolute_sources: Vec<PathBuf> = sources.iter().map(|source| cwd.join(source)).collect();
let absolute_sources: Vec<PathBuf> = 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() {