mirror of
https://github.com/astral-sh/uv.git
synced 2025-08-04 02:48:17 +00:00
Use unambiguous relative paths in uv export
(#7378)
This commit is contained in:
parent
c1888364b5
commit
54f171c80a
2 changed files with 19 additions and 13 deletions
|
@ -1,7 +1,8 @@
|
|||
use std::borrow::Cow;
|
||||
use std::collections::hash_map::Entry;
|
||||
use std::collections::VecDeque;
|
||||
use std::fmt::Formatter;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::path::{Component, Path, PathBuf};
|
||||
|
||||
use either::Either;
|
||||
use petgraph::visit::IntoNodeReferences;
|
||||
|
@ -191,20 +192,14 @@ impl std::fmt::Display for RequirementsTxtExport<'_> {
|
|||
write!(f, "{} @ {}", package.id.name, url)?;
|
||||
}
|
||||
Source::Path(path) | Source::Directory(path) => {
|
||||
if path.as_os_str().is_empty() {
|
||||
write!(f, ".")?;
|
||||
} else if path.is_absolute() {
|
||||
if path.is_absolute() {
|
||||
write!(f, "{}", Url::from_file_path(path).unwrap())?;
|
||||
} else {
|
||||
write!(f, "{}", path.portable_display())?;
|
||||
write!(f, "{}", anchor(path).portable_display())?;
|
||||
}
|
||||
}
|
||||
Source::Editable(path) => {
|
||||
if path.as_os_str().is_empty() {
|
||||
write!(f, "-e .")?;
|
||||
} else {
|
||||
write!(f, "-e {}", path.portable_display())?;
|
||||
}
|
||||
write!(f, "-e {}", anchor(path).portable_display())?;
|
||||
}
|
||||
Source::Virtual(_) => {
|
||||
continue;
|
||||
|
@ -252,3 +247,14 @@ impl<'lock> From<&'lock Package> for NodeComparator<'lock> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Modify a relative [`Path`] to anchor it at the current working directory.
|
||||
///
|
||||
/// For example, given `foo/bar`, returns `./foo/bar`.
|
||||
fn anchor(path: &Path) -> Cow<'_, Path> {
|
||||
match path.components().next() {
|
||||
None => Cow::Owned(PathBuf::from(".")),
|
||||
Some(Component::CurDir | Component::ParentDir) => Cow::Borrowed(path),
|
||||
_ => Cow::Owned(PathBuf::from("./").join(path)),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue