Add a dedicated struct for source annotations (#3478)

This commit is contained in:
Charlie Marsh 2024-05-09 00:40:35 -04:00 committed by GitHub
parent 8bcb2365bf
commit f16cbfda7e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
30 changed files with 177 additions and 149 deletions

View file

@ -149,14 +149,14 @@ pub struct Requirement<T: Pep508Url = VerbatimUrl> {
/// Those are a nested and/or tree.
pub marker: Option<MarkerTree>,
/// The source file containing the requirement.
pub path: Option<PathBuf>,
pub source: Option<PathBuf>,
}
impl Requirement {
/// Set the source file containing the requirement.
#[must_use]
pub fn with_source(self, path: Option<PathBuf>) -> Self {
Self { path, ..self }
pub fn with_source(self, source: Option<PathBuf>) -> Self {
Self { source, ..self }
}
}
@ -492,7 +492,7 @@ impl<T: Pep508Url> Requirement<T> {
extras,
version_or_url,
marker,
path,
source,
} = self;
Requirement {
name,
@ -505,7 +505,7 @@ impl<T: Pep508Url> Requirement<T> {
Some(VersionOrUrl::Url(url)) => Some(VersionOrUrl::Url(U::from(url))),
},
marker,
path,
source,
}
}
}
@ -1029,7 +1029,7 @@ fn parse_pep508_requirement<T: Pep508Url>(
extras,
version_or_url: requirement_kind,
marker,
path: None,
source: None,
})
}
@ -1171,7 +1171,7 @@ mod tests {
operator: MarkerOperator::LessThan,
r_value: MarkerValue::QuotedString("2.7".to_string()),
})),
path: None,
source: None,
};
assert_eq!(requests, expected);
}
@ -1397,7 +1397,7 @@ mod tests {
extras: vec![],
marker: None,
version_or_url: Some(VersionOrUrl::Url(Url::parse(url).unwrap())),
path: None,
source: None,
};
assert_eq!(pip_url, expected);
}

View file

@ -31,7 +31,7 @@ pub struct UnnamedRequirement {
/// Those are a nested and/or tree.
pub marker: Option<MarkerTree>,
/// The source file containing the requirement.
pub path: Option<PathBuf>,
pub source: Option<PathBuf>,
}
impl UnnamedRequirement {
@ -46,8 +46,8 @@ impl UnnamedRequirement {
/// Set the source file containing the requirement.
#[must_use]
pub fn with_source(self, path: Option<PathBuf>) -> Self {
Self { path, ..self }
pub fn with_source(self, source: Option<PathBuf>) -> Self {
Self { source, ..self }
}
}
@ -167,7 +167,7 @@ fn parse_unnamed_requirement(
url,
extras,
marker,
path: None,
source: None,
})
}