Skip to content

Include commit_id and requested_revision in direct_url.json #10862

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

Merged
merged 1 commit into from
Jan 22, 2025
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
2 changes: 1 addition & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion crates/uv-distribution-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ uv-pep508 = { workspace = true }
uv-platform-tags = { workspace = true }
uv-pypi-types = { workspace = true }

anyhow = { workspace = true }
arcstr = { workspace = true }
bitflags = { workspace = true }
fs-err = { workspace = true }
Expand Down
98 changes: 31 additions & 67 deletions crates/uv-distribution-types/src/cached.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
use std::path::{Path, PathBuf};

use anyhow::{anyhow, Result};

use uv_cache_info::CacheInfo;
use uv_distribution_filename::WheelFilename;
use uv_normalize::PackageName;
use uv_pep508::VerbatimUrl;
use uv_pypi_types::{HashDigest, ParsedDirectoryUrl};
use uv_pypi_types::{HashDigest, VerbatimParsedUrl};

use crate::{
BuiltDist, Dist, DistributionMetadata, Hashed, InstalledMetadata, InstalledVersion, Name,
Expand All @@ -33,10 +30,8 @@ pub struct CachedRegistryDist {
#[derive(Debug, Clone, Hash, PartialEq, Eq)]
pub struct CachedDirectUrlDist {
pub filename: WheelFilename,
pub url: VerbatimUrl,
pub url: VerbatimParsedUrl,
pub path: PathBuf,
pub editable: bool,
pub r#virtual: bool,
pub hashes: Vec<HashDigest>,
pub cache_info: CacheInfo,
}
Expand All @@ -59,21 +54,23 @@ impl CachedDist {
}),
Dist::Built(BuiltDist::DirectUrl(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Built(BuiltDist::Path(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Registry(_dist)) => Self::Registry(CachedRegistryDist {
filename,
Expand All @@ -83,39 +80,43 @@ impl CachedDist {
}),
Dist::Source(SourceDist::DirectUrl(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Git(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Path(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Directory(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url,
},
hashes,
cache_info,
path,
editable: dist.editable,
r#virtual: dist.r#virtual,
}),
}
}
Expand All @@ -137,26 +138,10 @@ impl CachedDist {
}

/// Return the [`ParsedUrl`] of the distribution, if it exists.
pub fn parsed_url(&self) -> Result<Option<ParsedUrl>> {
pub fn parsed_url(&self) -> Option<&ParsedUrl> {
match self {
Self::Registry(_) => Ok(None),
Self::Url(dist) => {
if dist.editable {
assert_eq!(dist.url.scheme(), "file", "{}", dist.url);
let path = dist
.url
.to_file_path()
.map_err(|()| anyhow!("Invalid path in file URL"))?;
Ok(Some(ParsedUrl::Directory(ParsedDirectoryUrl {
url: dist.url.raw().clone(),
install_path: path,
editable: dist.editable,
r#virtual: dist.r#virtual,
})))
} else {
Ok(Some(ParsedUrl::try_from(dist.url.to_url())?))
}
}
Self::Registry(_) => None,
Self::Url(dist) => Some(&dist.url.parsed_url),
}
}

Expand All @@ -175,27 +160,6 @@ impl Hashed for CachedRegistryDist {
}
}

impl CachedDirectUrlDist {
/// Initialize a [`CachedDirectUrlDist`] from a [`WheelFilename`], [`url::Url`], and [`Path`].
pub fn from_url(
filename: WheelFilename,
url: VerbatimUrl,
hashes: Vec<HashDigest>,
cache_info: CacheInfo,
path: PathBuf,
) -> Self {
Self {
filename,
url,
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}
}
}

impl Name for CachedRegistryDist {
fn name(&self) -> &PackageName {
&self.filename.name
Expand Down Expand Up @@ -225,7 +189,7 @@ impl DistributionMetadata for CachedRegistryDist {

impl DistributionMetadata for CachedDirectUrlDist {
fn version_or_url(&self) -> VersionOrUrlRef {
VersionOrUrlRef::Url(&self.url)
VersionOrUrlRef::Url(&self.url.verbatim)
}
}

Expand All @@ -246,7 +210,7 @@ impl InstalledMetadata for CachedRegistryDist {

impl InstalledMetadata for CachedDirectUrlDist {
fn installed_version(&self) -> InstalledVersion {
InstalledVersion::Url(&self.url, &self.filename.version)
InstalledVersion::Url(&self.url.verbatim, &self.filename.version)
}
}

Expand Down
72 changes: 71 additions & 1 deletion crates/uv-distribution-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ use uv_git::GitUrl;
use uv_normalize::PackageName;
use uv_pep440::Version;
use uv_pep508::{Pep508Url, VerbatimUrl};
use uv_pypi_types::{ParsedUrl, VerbatimParsedUrl};
use uv_pypi_types::{
ParsedArchiveUrl, ParsedDirectoryUrl, ParsedGitUrl, ParsedPathUrl, ParsedUrl, VerbatimParsedUrl,
};

pub use crate::annotation::*;
pub use crate::any::*;
Expand Down Expand Up @@ -662,6 +664,74 @@ impl RegistryBuiltDist {
}
}

impl DirectUrlBuiltDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Archive(ParsedArchiveUrl::from_source(
(*self.location).clone(),
None,
DistExtension::Wheel,
))
}
}

impl PathBuiltDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Path(ParsedPathUrl::from_source(
self.install_path.clone(),
DistExtension::Wheel,
self.url.to_url(),
))
}
}

impl PathSourceDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Path(ParsedPathUrl::from_source(
self.install_path.clone(),
DistExtension::Source(self.ext),
self.url.to_url(),
))
}
}

impl DirectUrlSourceDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Archive(ParsedArchiveUrl::from_source(
(*self.location).clone(),
self.subdirectory.clone(),
DistExtension::Source(self.ext),
))
}
}

impl GitSourceDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Git(ParsedGitUrl::from_source(
self.git.repository().clone(),
self.git.reference().clone(),
self.git.precise(),
self.subdirectory.clone(),
))
}
}

impl DirectorySourceDist {
/// Return the [`ParsedUrl`] for the distribution.
pub fn parsed_url(&self) -> ParsedUrl {
ParsedUrl::Directory(ParsedDirectoryUrl::from_source(
self.install_path.clone(),
self.editable,
self.r#virtual,
self.url.to_url(),
))
}
}

impl Name for RegistryBuiltWheel {
fn name(&self) -> &PackageName {
&self.filename.name
Expand Down
64 changes: 44 additions & 20 deletions crates/uv-distribution/src/index/cached_wheel.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
use std::path::Path;

use crate::archive::Archive;
use crate::{HttpArchivePointer, LocalArchivePointer};
use uv_cache::{Cache, CacheBucket, CacheEntry};
use uv_cache_info::CacheInfo;
use uv_distribution_filename::WheelFilename;
use uv_distribution_types::{CachedDirectUrlDist, CachedRegistryDist, Hashed};
use uv_pep508::VerbatimUrl;
use uv_pypi_types::HashDigest;
use uv_distribution_types::{
CachedDirectUrlDist, CachedRegistryDist, DirectUrlSourceDist, DirectorySourceDist,
GitSourceDist, Hashed, PathSourceDist,
};
use uv_pypi_types::{HashDigest, VerbatimParsedUrl};

use crate::archive::Archive;
use crate::{HttpArchivePointer, LocalArchivePointer};

#[derive(Debug, Clone)]
pub struct CachedWheel {
Expand Down Expand Up @@ -53,40 +56,61 @@ impl CachedWheel {
}
}

/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`].
pub fn into_url_dist(self, url: VerbatimUrl) -> CachedDirectUrlDist {
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
/// [`DirectUrlSourceDist`].
pub fn into_url_dist(self, dist: &DirectUrlSourceDist) -> CachedDirectUrlDist {
CachedDirectUrlDist {
filename: self.filename,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url.clone(),
},
path: self.entry.into_path_buf(),
hashes: self.hashes,
cache_info: self.cache_info,
}
}

/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
/// [`PathSourceDist`].
pub fn into_path_dist(self, dist: &PathSourceDist) -> CachedDirectUrlDist {
CachedDirectUrlDist {
filename: self.filename,
url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url.clone(),
},
path: self.entry.into_path_buf(),
editable: false,
r#virtual: false,
hashes: self.hashes,
cache_info: self.cache_info,
}
}

/// Convert a [`CachedWheel`] into an editable [`CachedDirectUrlDist`].
pub fn into_editable(self, url: VerbatimUrl) -> CachedDirectUrlDist {
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
/// [`DirectorySourceDist`].
pub fn into_directory_dist(self, dist: &DirectorySourceDist) -> CachedDirectUrlDist {
CachedDirectUrlDist {
filename: self.filename,
url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url.clone(),
},
path: self.entry.into_path_buf(),
editable: true,
r#virtual: false,
hashes: self.hashes,
cache_info: self.cache_info,
}
}

/// Convert a [`CachedWheel`] into an editable [`CachedDirectUrlDist`].
pub fn into_virtual(self, url: VerbatimUrl) -> CachedDirectUrlDist {
/// Convert a [`CachedWheel`] into a [`CachedDirectUrlDist`] by merging in the given
/// [`GitSourceDist`].
pub fn into_git_dist(self, dist: &GitSourceDist) -> CachedDirectUrlDist {
CachedDirectUrlDist {
filename: self.filename,
url,
url: VerbatimParsedUrl {
parsed_url: dist.parsed_url(),
verbatim: dist.url.clone(),
},
path: self.entry.into_path_buf(),
editable: false,
r#virtual: true,
hashes: self.hashes,
cache_info: self.cache_info,
}
Expand Down
Loading
Loading