Use relative paths for --find-links and local registries (#6566)

## Summary

See: https://github.com/astral-sh/uv/issues/6458
This commit is contained in:
Charlie Marsh 2024-08-24 22:41:47 -04:00 committed by GitHub
parent 3902bb498d
commit 7fa265a11b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 834 additions and 264 deletions

View file

@ -60,7 +60,7 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
path: impl AsRef<Path>,
working_dir: impl AsRef<Path>,
) -> Result<Self, Self::Err> {
let verbatim = VerbatimUrl::parse_path(&path, &working_dir)?;
let verbatim = VerbatimUrl::from_path(&path, &working_dir)?;
let verbatim_path = verbatim.as_path()?;
let is_dir = if let Ok(metadata) = verbatim_path.metadata() {
metadata.is_dir()
@ -89,7 +89,7 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
}
fn parse_absolute_path(path: impl AsRef<Path>) -> Result<Self, Self::Err> {
let verbatim = VerbatimUrl::parse_absolute_path(&path)?;
let verbatim = VerbatimUrl::from_absolute_path(&path)?;
let verbatim_path = verbatim.as_path()?;
let is_dir = if let Ok(metadata) = verbatim_path.metadata() {
metadata.is_dir()

View file

@ -507,7 +507,8 @@ impl RequirementSource {
ext,
url,
} => Ok(Self::Path {
install_path: relative_to(&install_path, path)?,
install_path: relative_to(&install_path, path)
.or_else(|_| std::path::absolute(install_path))?,
ext,
url,
}),
@ -516,7 +517,8 @@ impl RequirementSource {
editable,
url,
} => Ok(Self::Directory {
install_path: relative_to(&install_path, path)?,
install_path: relative_to(&install_path, path)
.or_else(|_| std::path::absolute(install_path))?,
editable,
url,
}),
@ -744,7 +746,7 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
// sources in the lockfile, we replace the URL anyway.
RequirementSourceWire::Path { path } => {
let path = PathBuf::from(path);
let url = VerbatimUrl::parse_path(&path, &*CWD)?;
let url = VerbatimUrl::from_path(&path, &*CWD)?;
Ok(Self::Path {
ext: DistExtension::from_path(path.as_path())
.map_err(|err| ParsedUrlError::MissingExtensionPath(path.clone(), err))?,
@ -754,7 +756,7 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
}
RequirementSourceWire::Directory { directory } => {
let directory = PathBuf::from(directory);
let url = VerbatimUrl::parse_path(&directory, &*CWD)?;
let url = VerbatimUrl::from_path(&directory, &*CWD)?;
Ok(Self::Directory {
install_path: directory,
editable: false,
@ -763,7 +765,7 @@ impl TryFrom<RequirementSourceWire> for RequirementSource {
}
RequirementSourceWire::Editable { editable } => {
let editable = PathBuf::from(editable);
let url = VerbatimUrl::parse_path(&editable, &*CWD)?;
let url = VerbatimUrl::from_path(&editable, &*CWD)?;
Ok(Self::Directory {
install_path: editable,
editable: true,
@ -788,7 +790,7 @@ pub fn redact_git_credentials(url: &mut Url) {
#[cfg(test)]
mod tests {
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use pep508_rs::{MarkerTree, VerbatimUrl};
@ -823,7 +825,7 @@ mod tests {
source: RequirementSource::Directory {
install_path: PathBuf::from(path),
editable: false,
url: VerbatimUrl::from_path(Path::new(path)).unwrap(),
url: VerbatimUrl::from_absolute_path(path).unwrap(),
},
origin: None,
};