Skip to content

Commit

Permalink
Fix contraints output
Browse files Browse the repository at this point in the history
  • Loading branch information
palfrey committed Apr 26, 2024
1 parent cf170e5 commit 9655e91
Show file tree
Hide file tree
Showing 33 changed files with 374 additions and 236 deletions.
16 changes: 8 additions & 8 deletions crates/distribution-types/src/resolution.rs
Expand Up @@ -83,22 +83,22 @@ impl From<Dist> for Requirement {
),
)),
marker: None,
path: None,
source: None,
},

Dist::Built(BuiltDist::DirectUrl(wheel)) => Self {
name: wheel.filename.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(wheel.url)),
marker: None,
path: None,
source: None,
},
Dist::Built(BuiltDist::Path(wheel)) => Self {
name: wheel.filename.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(wheel.url)),
marker: None,
path: None,
source: None,
},
Dist::Source(SourceDist::Registry(sdist)) => Self {
name: sdist.filename.name,
Expand All @@ -109,28 +109,28 @@ impl From<Dist> for Requirement {
),
)),
marker: None,
path: None,
source: None,
},
Dist::Source(SourceDist::DirectUrl(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
source: None,
},
Dist::Source(SourceDist::Git(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
source: None,
},
Dist::Source(SourceDist::Path(sdist)) => Self {
name: sdist.name,
extras: vec![],
version_or_url: Some(pep508_rs::VersionOrUrl::Url(sdist.url)),
marker: None,
path: None,
source: None,
},
}
}
Expand All @@ -147,7 +147,7 @@ impl From<InstalledDist> for Requirement {
)),
)),
marker: None,
path: None,
source: None,
}
}
}
Expand Down
11 changes: 6 additions & 5 deletions crates/pep508-rs/src/lib.rs
Expand Up @@ -43,6 +43,7 @@ pub use marker::{
};
use pep440_rs::{TrackedFromStr, Version, VersionSpecifier, VersionSpecifiers};
use uv_fs::normalize_url_path;
use uv_normalize::Source;
// Parity with the crates.io version of pep508_rs
use crate::verbatim_url::VerbatimUrlError;
#[cfg(feature = "non-pep508-extensions")]
Expand Down Expand Up @@ -144,8 +145,8 @@ pub struct Requirement {
/// `requests [security,tests] >= 2.8.1, == 2.8.* ; python_version > "3.8"`.
/// Those are a nested and/or tree.
pub marker: Option<MarkerTree>,
/// Path of the original file (where existing)
pub path: Option<String>,
/// Source of the original file (where existing)
pub source: Option<Source>,
}

impl Display for Requirement {
Expand Down Expand Up @@ -1316,7 +1317,7 @@ fn parse_pep508_requirement(
extras,
version_or_url: requirement_kind,
marker,
path: source.map(|p| p.to_string_lossy().to_string()),
source: source.map(|p| Source::Requirement(p.to_string_lossy().to_string())),
})
}

Expand Down Expand Up @@ -1517,7 +1518,7 @@ mod tests {
operator: MarkerOperator::LessThan,
r_value: MarkerValue::QuotedString("2.7".to_string()),
})),
path: None,
source: None,
};
assert_eq!(requests, expected);
}
Expand Down Expand Up @@ -1741,7 +1742,7 @@ mod tests {
extras: vec![],
marker: None,
version_or_url: Some(VersionOrUrl::Url(VerbatimUrl::from_str(url).unwrap())),
path: None,
source: None,
};
assert_eq!(pip_url, expected);
}
Expand Down
56 changes: 39 additions & 17 deletions crates/requirements-txt/src/lib.rs
Expand Up @@ -55,7 +55,7 @@ use uv_client::BaseClient;
use uv_client::BaseClientBuilder;
use uv_configuration::{NoBinary, NoBuild, PackageNameSpecifier};
use uv_fs::{normalize_url_path, Simplified};
use uv_normalize::ExtraName;
use uv_normalize::{ExtraName, Source};
use uv_warnings::warn_user;

mod requirement;
Expand Down Expand Up @@ -495,7 +495,10 @@ impl RequirementsTxt {
// _requirements_, but we don't want to support that.
for entry in sub_constraints.requirements {
match entry.requirement {
RequirementsTxtRequirement::Pep508(requirement) => {
RequirementsTxtRequirement::Pep508(mut requirement) => {
if let Some(Source::Requirement(ref name)) = requirement.source {
requirement.source.replace(Source::Constraint(name.clone()));
}
data.constraints.push(requirement);
}
RequirementsTxtRequirement::Unnamed(_) => {
Expand All @@ -506,7 +509,12 @@ impl RequirementsTxt {
}
}
}
data.constraints.extend(sub_constraints.constraints);
for mut constraint in sub_constraints.constraints {
if let Some(Source::Requirement(ref name)) = constraint.source {
constraint.source.replace(Source::Constraint(name.clone()));
}
data.constraints.push(constraint);
}
}
RequirementsTxtStatement::RequirementEntry(requirement_entry) => {
data.requirements.push(requirement_entry);
Expand Down Expand Up @@ -1768,8 +1776,10 @@ mod test {
extras: [],
version_or_url: None,
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/subdir/sibling.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/subdir/sibling.txt",
),
),
},
),
Expand Down Expand Up @@ -1833,8 +1843,10 @@ mod test {
extras: [],
version_or_url: None,
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/requirements.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/requirements.txt",
),
),
},
),
Expand Down Expand Up @@ -2026,8 +2038,10 @@ mod test {
extras: [],
version_or_url: None,
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/./sibling.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/./sibling.txt",
),
),
},
),
Expand Down Expand Up @@ -2056,8 +2070,10 @@ mod test {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/requirements.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/requirements.txt",
),
),
},
),
Expand Down Expand Up @@ -2088,8 +2104,10 @@ mod test {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/requirements.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/requirements.txt",
),
),
},
),
Expand Down Expand Up @@ -2120,8 +2138,10 @@ mod test {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/requirements.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/requirements.txt",
),
),
},
),
Expand Down Expand Up @@ -2150,8 +2170,10 @@ mod test {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/requirements.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/requirements.txt",
),
),
},
),
Expand Down
Expand Up @@ -24,8 +24,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down Expand Up @@ -54,8 +56,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down Expand Up @@ -84,8 +88,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down Expand Up @@ -114,8 +120,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down Expand Up @@ -144,8 +152,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down Expand Up @@ -174,8 +184,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/basic.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/basic.txt",
),
),
},
),
Expand Down
Expand Up @@ -24,8 +24,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/constraints-a.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/constraints-a.txt",
),
),
},
),
Expand Down Expand Up @@ -54,8 +56,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/constraints-b.txt",
source: Some(
Constraint(
"<REQUIREMENTS_DIR>/constraints-b.txt",
),
),
},
Requirement {
Expand All @@ -76,8 +80,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/constraints-b.txt",
source: Some(
Constraint(
"<REQUIREMENTS_DIR>/constraints-b.txt",
),
),
},
],
Expand Down
Expand Up @@ -24,8 +24,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/constraints-b.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/constraints-b.txt",
),
),
},
),
Expand Down Expand Up @@ -54,8 +56,10 @@ RequirementsTxt {
),
),
marker: None,
path: Some(
"<REQUIREMENTS_DIR>/constraints-b.txt",
source: Some(
Requirement(
"<REQUIREMENTS_DIR>/constraints-b.txt",
),
),
},
),
Expand Down

0 comments on commit 9655e91

Please sign in to comment.