Skip to content

Commit

Permalink
Add support for path deps in git
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Dec 21, 2024
1 parent ddc290f commit 8705c37
Show file tree
Hide file tree
Showing 32 changed files with 1,627 additions and 302 deletions.
1 change: 1 addition & 0 deletions crates/uv-client/src/registry_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ impl RegistryClient {
}
}
}
BuiltDist::GitPath(_) => panic!("GitPath should not be passed to wheel_metadata"),
BuiltDist::DirectUrl(wheel) => {
self.wheel_metadata_no_pep658(
&wheel.filename,
Expand Down
48 changes: 40 additions & 8 deletions crates/uv-distribution-types/src/buildable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use uv_pep508::VerbatimUrl;

use uv_normalize::PackageName;

use crate::{DirectorySourceDist, GitSourceDist, Name, PathSourceDist, SourceDist};
use crate::{
DirectorySourceDist, GitDirectorySourceDist, GitPathSourceDist, Name, PathSourceDist,
SourceDist,
};

/// A reference to a source that can be built into a built distribution.
///
Expand Down Expand Up @@ -88,7 +91,8 @@ impl std::fmt::Display for BuildableSource<'_> {
#[derive(Debug, Clone)]
pub enum SourceUrl<'a> {
Direct(DirectSourceUrl<'a>),
Git(GitSourceUrl<'a>),
GitDirectory(GitDirectorySourceUrl<'a>),
GitPath(GitPathSourceUrl<'a>),
Path(PathSourceUrl<'a>),
Directory(DirectorySourceUrl<'a>),
}
Expand All @@ -98,7 +102,8 @@ impl SourceUrl<'_> {
pub fn url(&self) -> &Url {
match self {
Self::Direct(dist) => dist.url,
Self::Git(dist) => dist.url,
Self::GitDirectory(dist) => dist.url,
Self::GitPath(dist) => dist.url,
Self::Path(dist) => dist.url,
Self::Directory(dist) => dist.url,
}
Expand All @@ -122,7 +127,8 @@ impl std::fmt::Display for SourceUrl<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::Direct(url) => write!(f, "{url}"),
Self::Git(url) => write!(f, "{url}"),
Self::GitDirectory(url) => write!(f, "{url}"),
Self::GitPath(url) => write!(f, "{url}"),
Self::Path(url) => write!(f, "{url}"),
Self::Directory(url) => write!(f, "{url}"),
}
Expand All @@ -143,22 +149,48 @@ impl std::fmt::Display for DirectSourceUrl<'_> {
}

#[derive(Debug, Clone)]
pub struct GitSourceUrl<'a> {
pub struct GitPathSourceUrl<'a> {
/// The URL with the revision and path fragment.
pub url: &'a VerbatimUrl,
pub git: &'a GitUrl,
pub path: Cow<'a, Path>,
pub ext: SourceDistExtension,
}

impl std::fmt::Display for GitPathSourceUrl<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{url}", url = self.url)
}
}

impl<'a> From<&'a GitPathSourceDist> for GitPathSourceUrl<'a> {
fn from(dist: &'a GitPathSourceDist) -> Self {
Self {
url: &dist.url,
git: &dist.git,
path: Cow::Borrowed(&dist.install_path),
ext: dist.ext,
}
}
}

#[derive(Debug, Clone)]
pub struct GitDirectorySourceUrl<'a> {
/// The URL with the revision and subdirectory fragment.
pub url: &'a VerbatimUrl,
pub git: &'a GitUrl,
/// The URL without the revision and subdirectory fragment.
pub subdirectory: Option<&'a Path>,
}

impl std::fmt::Display for GitSourceUrl<'_> {
impl std::fmt::Display for GitDirectorySourceUrl<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{url}", url = self.url)
}
}

impl<'a> From<&'a GitSourceDist> for GitSourceUrl<'a> {
fn from(dist: &'a GitSourceDist) -> Self {
impl<'a> From<&'a GitDirectorySourceDist> for GitDirectorySourceUrl<'a> {
fn from(dist: &'a GitDirectorySourceDist) -> Self {
Self {
url: &dist.url,
git: &dist.git,
Expand Down
20 changes: 19 additions & 1 deletion crates/uv-distribution-types/src/cached.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,15 @@ impl CachedDist {
editable: false,
r#virtual: false,
}),
Dist::Built(BuiltDist::GitPath(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Registry(_dist)) => Self::Registry(CachedRegistryDist {
filename,
path,
Expand All @@ -90,7 +99,16 @@ impl CachedDist {
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::Git(dist)) => Self::Url(CachedDirectUrlDist {
Dist::Source(SourceDist::GitDirectory(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
hashes,
cache_info,
path,
editable: false,
r#virtual: false,
}),
Dist::Source(SourceDist::GitPath(dist)) => Self::Url(CachedDirectUrlDist {
filename,
url: dist.url,
hashes,
Expand Down
12 changes: 12 additions & 0 deletions crates/uv-distribution-types/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,15 @@ pub trait Hashed {
}
}
}

impl Hashed for Vec<HashDigest> {
fn hashes(&self) -> &[HashDigest] {
self
}
}

impl Hashed for &[HashDigest] {
fn hashes(&self) -> &[HashDigest] {
self
}
}
Loading

0 comments on commit 8705c37

Please sign in to comment.