Omit origin when comparing requirements (#9570)

## Summary

I noticed that we consider two requirements to be different if they come
from different files. This seems like an oversight.
This commit is contained in:
Charlie Marsh
2024-12-02 18:22:13 -05:00
committed by GitHub
parent 02c105c3cb
commit 0e6b2d92b8
2 changed files with 43 additions and 4 deletions
+42 -3
View File
@@ -36,9 +36,7 @@ pub enum RequirementError {
///
/// The main change is using [`RequirementSource`] to represent all supported package sources over
/// [`VersionOrUrl`], which collapses all URL sources into a single stringly type.
#[derive(
Hash, Debug, Clone, Eq, PartialEq, Ord, PartialOrd, serde::Serialize, serde::Deserialize,
)]
#[derive(Debug, Clone, Ord, PartialOrd, serde::Serialize, serde::Deserialize)]
pub struct Requirement {
pub name: PackageName,
#[serde(skip_serializing_if = "Vec::is_empty", default)]
@@ -97,6 +95,47 @@ impl Requirement {
}
}
impl std::hash::Hash for Requirement {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
let Self {
name,
extras,
marker,
source,
origin: _,
} = self;
name.hash(state);
extras.hash(state);
marker.hash(state);
source.hash(state);
}
}
impl PartialEq for Requirement {
fn eq(&self, other: &Self) -> bool {
let Self {
name,
extras,
marker,
source,
origin: _,
} = self;
let Self {
name: other_name,
extras: other_extras,
marker: other_marker,
source: other_source,
origin: _,
} = other;
name == other_name
&& extras == other_extras
&& marker == other_marker
&& source == other_source
}
}
impl Eq for Requirement {}
impl From<Requirement> for uv_pep508::Requirement<VerbatimUrl> {
/// Convert a [`Requirement`] to a [`uv_pep508::Requirement`].
fn from(requirement: Requirement) -> Self {
+1 -1
View File
@@ -1974,7 +1974,7 @@ fn tool_install_requirements_txt_arguments() {
----- stdout -----
----- stderr -----
Installed 2 executables: black, blackd
`black` is already installed
"###);
let requirements_txt = context.temp_dir.child("requirements.txt");