Show URLs and version together for installed, URL-based dependencies (#690)

The snapshot test changes will give you a sense for the impact of the
change and the output formatting.

Closes https://github.com/astral-sh/puffin/issues/686.
This commit is contained in:
Charlie Marsh 2023-12-18 17:21:37 -05:00 committed by GitHub
parent 365c860e27
commit 31afb39a10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 228 additions and 93 deletions

View file

@ -71,3 +71,49 @@ pub enum VcsKind {
Bzr,
Svn,
}
impl std::fmt::Display for VcsKind {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
VcsKind::Git => write!(f, "git"),
VcsKind::Hg => write!(f, "hg"),
VcsKind::Bzr => write!(f, "bzr"),
VcsKind::Svn => write!(f, "svn"),
}
}
}
impl From<DirectUrl> for Url {
fn from(value: DirectUrl) -> Self {
match value {
DirectUrl::LocalDirectory { url, .. } => url,
DirectUrl::ArchiveUrl {
mut url,
subdirectory,
archive_info: _,
} => {
if let Some(subdirectory) = subdirectory {
url.set_fragment(Some(&format!("subdirectory={}", subdirectory.display())));
}
url
}
DirectUrl::VcsUrl {
url,
vcs_info,
subdirectory,
} => {
let mut url =
Url::parse(&format!("{}+{}", vcs_info.vcs, url)).expect("VCS URL is invalid");
if let Some(commit_id) = vcs_info.commit_id {
url.set_path(&format!("{}@{commit_id}", url.path()));
} else if let Some(requested_revision) = vcs_info.requested_revision {
url.set_path(&format!("{}@{requested_revision}", url.path()));
}
if let Some(subdirectory) = subdirectory {
url.set_fragment(Some(&format!("subdirectory={}", subdirectory.display())));
}
url
}
}
}
}