mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-29 19:17:26 +00:00
Remove Optional from with_origin API (#3482)
This commit is contained in:
parent
3e4365301e
commit
b6bb2ac548
6 changed files with 21 additions and 11 deletions
|
|
@ -157,8 +157,11 @@ pub struct Requirement<T: Pep508Url = VerbatimUrl> {
|
||||||
impl Requirement {
|
impl Requirement {
|
||||||
/// Set the source file containing the requirement.
|
/// Set the source file containing the requirement.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_origin(self, origin: Option<RequirementOrigin>) -> Self {
|
pub fn with_origin(self, origin: RequirementOrigin) -> Self {
|
||||||
Self { origin, ..self }
|
Self {
|
||||||
|
origin: Some(origin),
|
||||||
|
..self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -55,8 +55,11 @@ impl UnnamedRequirement {
|
||||||
|
|
||||||
/// Set the source file containing the requirement.
|
/// Set the source file containing the requirement.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_origin(self, origin: Option<RequirementOrigin>) -> Self {
|
pub fn with_origin(self, origin: RequirementOrigin) -> Self {
|
||||||
Self { origin, ..self }
|
Self {
|
||||||
|
origin: Some(origin),
|
||||||
|
..self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -826,7 +826,11 @@ fn parse_requirement_and_hashes(
|
||||||
|
|
||||||
let requirement = RequirementsTxtRequirement::parse(requirement, working_dir)
|
let requirement = RequirementsTxtRequirement::parse(requirement, working_dir)
|
||||||
.map(|requirement| {
|
.map(|requirement| {
|
||||||
requirement.with_origin(source.map(Path::to_path_buf).map(RequirementOrigin::File))
|
if let Some(source) = source {
|
||||||
|
requirement.with_origin(RequirementOrigin::File(source.to_path_buf()))
|
||||||
|
} else {
|
||||||
|
requirement
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.map_err(|err| match err {
|
.map_err(|err| match err {
|
||||||
RequirementsTxtRequirementError::ParsedUrl(err) => {
|
RequirementsTxtRequirementError::ParsedUrl(err) => {
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ pub enum RequirementsTxtRequirement {
|
||||||
impl RequirementsTxtRequirement {
|
impl RequirementsTxtRequirement {
|
||||||
/// Set the source file containing the requirement.
|
/// Set the source file containing the requirement.
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn with_origin(self, origin: Option<RequirementOrigin>) -> Self {
|
pub fn with_origin(self, origin: RequirementOrigin) -> Self {
|
||||||
match self {
|
match self {
|
||||||
Self::Named(requirement) => Self::Named(requirement.with_origin(origin)),
|
Self::Named(requirement) => Self::Named(requirement.with_origin(origin)),
|
||||||
Self::Unnamed(requirement) => Self::Unnamed(requirement.with_origin(origin)),
|
Self::Unnamed(requirement) => Self::Unnamed(requirement.with_origin(origin)),
|
||||||
|
|
|
||||||
|
|
@ -333,9 +333,9 @@ pub(crate) fn lower_requirements(
|
||||||
let dependencies = dependencies
|
let dependencies = dependencies
|
||||||
.iter()
|
.iter()
|
||||||
.map(|dependency| {
|
.map(|dependency| {
|
||||||
let requirement = pep508_rs::Requirement::from_str(dependency)?.with_origin(Some(
|
let requirement = pep508_rs::Requirement::from_str(dependency)?.with_origin(
|
||||||
RequirementOrigin::Project(pyproject_path.to_path_buf(), project_name.clone()),
|
RequirementOrigin::Project(pyproject_path.to_path_buf(), project_name.clone()),
|
||||||
));
|
);
|
||||||
let name = requirement.name.clone();
|
let name = requirement.name.clone();
|
||||||
lower_requirement(
|
lower_requirement(
|
||||||
requirement,
|
requirement,
|
||||||
|
|
@ -356,10 +356,10 @@ pub(crate) fn lower_requirements(
|
||||||
.iter()
|
.iter()
|
||||||
.map(|dependency| {
|
.map(|dependency| {
|
||||||
let requirement = pep508_rs::Requirement::from_str(dependency)?.with_origin(
|
let requirement = pep508_rs::Requirement::from_str(dependency)?.with_origin(
|
||||||
Some(RequirementOrigin::Project(
|
RequirementOrigin::Project(
|
||||||
pyproject_path.to_path_buf(),
|
pyproject_path.to_path_buf(),
|
||||||
project_name.clone(),
|
project_name.clone(),
|
||||||
)),
|
),
|
||||||
);
|
);
|
||||||
let name = requirement.name.clone();
|
let name = requirement.name.clone();
|
||||||
lower_requirement(
|
lower_requirement(
|
||||||
|
|
|
||||||
|
|
@ -154,7 +154,7 @@ impl<'a, Context: BuildContext> SourceTreeResolver<'a, Context> {
|
||||||
ExtrasSpecification::None => Ok(metadata
|
ExtrasSpecification::None => Ok(metadata
|
||||||
.requires_dist
|
.requires_dist
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|requirement| requirement.with_origin(Some(origin.clone())))
|
.map(|requirement| requirement.with_origin(origin.clone()))
|
||||||
.collect()),
|
.collect()),
|
||||||
ExtrasSpecification::All => Ok(metadata
|
ExtrasSpecification::All => Ok(metadata
|
||||||
.requires_dist
|
.requires_dist
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue