Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only use relative paths in lockfile #6490

Merged
merged 7 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/distribution-types/src/buildable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ impl<'a> From<&'a PathSourceDist> for PathSourceUrl<'a> {
pub struct DirectorySourceUrl<'a> {
pub url: &'a Url,
pub install_path: Cow<'a, Path>,
pub lock_path: Cow<'a, Path>,
pub editable: bool,
}

Expand All @@ -187,7 +186,6 @@ impl<'a> From<&'a DirectorySourceDist> for DirectorySourceUrl<'a> {
Self {
url: &dist.url,
install_path: Cow::Borrowed(&dist.install_path),
lock_path: Cow::Borrowed(&dist.lock_path),
editable: dist.editable,
}
}
Expand Down
3 changes: 1 addition & 2 deletions crates/distribution-types/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,7 @@ impl CachedDist {
.map_err(|()| anyhow!("Invalid path in file URL"))?;
Ok(Some(ParsedUrl::Directory(ParsedDirectoryUrl {
url: dist.url.raw().clone(),
install_path: path.clone(),
lock_path: path,
install_path: path,
editable: dist.editable,
})))
} else {
Expand Down
33 changes: 6 additions & 27 deletions crates/distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
//!
//! Since we read this information from [`direct_url.json`](https://packaging.python.org/en/latest/specifications/direct-url-data-structure/), it doesn't match the information [`Dist`] exactly.
use std::borrow::Cow;
use std::path;
use std::path::{Path, PathBuf};
use std::str::FromStr;

Expand Down Expand Up @@ -237,10 +238,6 @@ pub struct PathBuiltDist {
pub filename: WheelFilename,
/// The absolute path to the wheel which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the wheel
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
/// The URL as it was provided by the user.
pub url: VerbatimUrl,
}
Expand Down Expand Up @@ -298,10 +295,6 @@ pub struct PathSourceDist {
pub name: PackageName,
/// The absolute path to the distribution which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
/// The file extension, e.g. `tar.gz`, `zip`, etc.
pub ext: SourceDistExtension,
/// The URL as it was provided by the user.
Expand All @@ -314,10 +307,6 @@ pub struct DirectorySourceDist {
pub name: PackageName,
/// The absolute path to the distribution which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
/// Whether the package should be installed in editable mode.
pub editable: bool,
/// The URL as it was provided by the user.
Expand Down Expand Up @@ -369,11 +358,10 @@ impl Dist {
name: PackageName,
url: VerbatimUrl,
install_path: &Path,
lock_path: &Path,
ext: DistExtension,
) -> Result<Dist, Error> {
// Convert to an absolute path.
let install_path = std::path::absolute(install_path)?;
let install_path = path::absolute(install_path)?;

// Normalize the path.
let install_path = normalize_absolute_path(&install_path)?;
Expand All @@ -398,14 +386,12 @@ impl Dist {
Ok(Self::Built(BuiltDist::Path(PathBuiltDist {
filename,
install_path,
lock_path: lock_path.to_path_buf(),
url,
})))
}
DistExtension::Source(ext) => Ok(Self::Source(SourceDist::Path(PathSourceDist {
name,
install_path,
lock_path: lock_path.to_path_buf(),
ext,
url,
}))),
Expand All @@ -417,11 +403,10 @@ impl Dist {
name: PackageName,
url: VerbatimUrl,
install_path: &Path,
lock_path: &Path,
editable: bool,
) -> Result<Dist, Error> {
// Convert to an absolute path.
let install_path = std::path::absolute(install_path)?;
let install_path = path::absolute(install_path)?;

// Normalize the path.
let install_path = normalize_absolute_path(&install_path)?;
Expand All @@ -435,7 +420,6 @@ impl Dist {
Ok(Self::Source(SourceDist::Directory(DirectorySourceDist {
name,
install_path,
lock_path: lock_path.to_path_buf(),
editable,
url,
})))
Expand Down Expand Up @@ -466,18 +450,13 @@ impl Dist {
archive.subdirectory,
archive.ext,
),
ParsedUrl::Path(file) => Self::from_file_url(
name,
url.verbatim,
&file.install_path,
&file.lock_path,
file.ext,
),
ParsedUrl::Path(file) => {
Self::from_file_url(name, url.verbatim, &file.install_path, file.ext)
}
ParsedUrl::Directory(directory) => Self::from_directory_url(
name,
url.verbatim,
&directory.install_path,
&directory.lock_path,
directory.editable,
),
ParsedUrl::Git(git) => {
Expand Down
3 changes: 0 additions & 3 deletions crates/distribution-types/src/resolution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,6 @@ impl From<&ResolvedDist> for Requirement {
}
Dist::Built(BuiltDist::Path(wheel)) => RequirementSource::Path {
install_path: wheel.install_path.clone(),
lock_path: wheel.lock_path.clone(),
url: wheel.url.clone(),
ext: DistExtension::Wheel,
},
Expand Down Expand Up @@ -214,13 +213,11 @@ impl From<&ResolvedDist> for Requirement {
},
Dist::Source(SourceDist::Path(sdist)) => RequirementSource::Path {
install_path: sdist.install_path.clone(),
lock_path: sdist.lock_path.clone(),
url: sdist.url.clone(),
ext: DistExtension::Source(sdist.ext),
},
Dist::Source(SourceDist::Directory(sdist)) => RequirementSource::Directory {
install_path: sdist.install_path.clone(),
lock_path: sdist.lock_path.clone(),
url: sdist.url.clone(),
editable: sdist.editable,
},
Expand Down
30 changes: 2 additions & 28 deletions crates/pypi-types/src/parsed_url.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
ParsedUrl::Directory(ParsedDirectoryUrl {
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
editable: false,
})
} else {
ParsedUrl::Path(ParsedPathUrl {
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
ext: DistExtension::from_path(&path).map_err(|err| {
ParsedUrlError::MissingExtensionPath(path.as_ref().to_path_buf(), err)
})?,
Expand All @@ -102,14 +100,12 @@ impl UnnamedRequirementUrl for VerbatimParsedUrl {
ParsedUrl::Directory(ParsedDirectoryUrl {
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
editable: false,
})
} else {
ParsedUrl::Path(ParsedPathUrl {
url: verbatim.to_url(),
install_path: verbatim.as_path()?,
lock_path: path.as_ref().to_path_buf(),
ext: DistExtension::from_path(&path).map_err(|err| {
ParsedUrlError::MissingExtensionPath(path.as_ref().to_path_buf(), err)
})?,
Expand Down Expand Up @@ -187,26 +183,16 @@ pub struct ParsedPathUrl {
pub url: Url,
/// The absolute path to the distribution which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
/// The file extension, e.g. `tar.gz`, `zip`, etc.
pub ext: DistExtension,
}

impl ParsedPathUrl {
/// Construct a [`ParsedPathUrl`] from a path requirement source.
pub fn from_source(
install_path: PathBuf,
lock_path: PathBuf,
ext: DistExtension,
url: Url,
) -> Self {
pub fn from_source(install_path: PathBuf, ext: DistExtension, url: Url) -> Self {
Self {
url,
install_path,
lock_path,
ext,
}
}
Expand All @@ -221,25 +207,15 @@ pub struct ParsedDirectoryUrl {
pub url: Url,
/// The absolute path to the distribution which we use for installing.
pub install_path: PathBuf,
/// The absolute path or path relative to the workspace root pointing to the distribution
/// which we use for locking. Unlike `given` on the verbatim URL all environment variables
/// are resolved, and unlike the install path, we did not yet join it on the base directory.
pub lock_path: PathBuf,
pub editable: bool,
}

impl ParsedDirectoryUrl {
/// Construct a [`ParsedDirectoryUrl`] from a path requirement source.
pub fn from_source(
install_path: PathBuf,
lock_path: PathBuf,
editable: bool,
url: Url,
) -> Self {
pub fn from_source(install_path: PathBuf, editable: bool, url: Url) -> Self {
Self {
url,
install_path,
lock_path,
editable,
}
}
Expand Down Expand Up @@ -393,7 +369,6 @@ impl TryFrom<Url> for ParsedUrl {
Ok(Self::Directory(ParsedDirectoryUrl {
url,
install_path: path.clone(),
lock_path: path,
editable: false,
}))
} else {
Expand All @@ -402,7 +377,6 @@ impl TryFrom<Url> for ParsedUrl {
ext: DistExtension::from_path(&path)
.map_err(|err| ParsedUrlError::MissingExtensionPath(path.clone(), err))?,
install_path: path.clone(),
lock_path: path,
}))
}
} else {
Expand Down
Loading
Loading