Always include package names for Git and HTTPS dependencies (#3821)

## Summary

Related to https://github.com/astral-sh/uv/issues/3818. We should
_always_ include the package name if we know it's not a file path, even
if it starts with an environment variable.
This commit is contained in:
Charlie Marsh 2024-05-24 10:01:38 -04:00 committed by GitHub
parent 73f67089e1
commit 999d072ae9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 73 additions and 35 deletions

View file

@ -284,6 +284,16 @@ impl InstalledDist {
Self::LegacyEditable(dist) => Some(&dist.target_url),
}
}
/// Return true if the distribution refers to a local file or directory.
pub fn is_local(&self) -> bool {
match self {
Self::Registry(_) => false,
Self::Url(dist) => matches!(&*dist.direct_url, DirectUrl::LocalDirectory { .. }),
Self::EggInfo(_) => false,
Self::LegacyEditable(_) => true,
}
}
}
impl DistributionMetadata for InstalledDist {

View file

@ -427,6 +427,14 @@ impl Dist {
}
}
/// Return true if the distribution refers to a local file or directory.
pub fn is_local(&self) -> bool {
match self {
Self::Source(dist) => dist.is_local(),
Self::Built(dist) => dist.is_local(),
}
}
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
@ -452,6 +460,11 @@ impl Dist {
}
impl BuiltDist {
/// Return true if the distribution refers to a local file or directory.
pub fn is_local(&self) -> bool {
matches!(self, Self::Path(_))
}
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {
@ -510,6 +523,11 @@ impl SourceDist {
}
}
/// Return true if the distribution refers to a local file or directory.
pub fn is_local(&self) -> bool {
matches!(self, Self::Directory(_) | Self::Path(_))
}
/// Returns the path to the source distribution, if it's a local distribution.
pub fn as_path(&self) -> Option<&Path> {
match self {

View file

@ -45,6 +45,14 @@ impl ResolvedDist {
}
}
/// Return true if the distribution refers to a local file or directory.
pub fn is_local(&self) -> bool {
match self {
Self::Installable(dist) => dist.is_local(),
Self::Installed(dist) => dist.is_local(),
}
}
/// Returns the [`IndexUrl`], if the distribution is from a registry.
pub fn index(&self) -> Option<&IndexUrl> {
match self {