Avoid adding extras when expanding constraints (#3232)

## Summary

See the diff in the tests. If you have a constraint with an extra, we
should respect it, but we shouldn't _add_ the extra to the requirements.
This commit is contained in:
Charlie Marsh
2024-04-23 22:00:27 -04:00
committed by GitHub
parent c7d7b07408
commit 8b711d2e4d
2 changed files with 14 additions and 24 deletions
+13 -21
View File
@@ -50,10 +50,10 @@ impl PubGrubDependencies {
.into_iter()
.map(|extra| to_pubgrub(requirement, Some(extra), urls, locals)),
) {
let (mut package, version) = result?;
let (package, version) = result?;
// Detect self-dependencies.
if let PubGrubPackage::Package(name, extra, ..) = &mut package {
if let PubGrubPackage::Package(name, extra, ..) = &package {
if source_name.is_some_and(|source_name| source_name == name) {
// Allow, e.g., `black` to depend on `black[colorama]`.
if source_extra == extra.as_ref() {
@@ -76,29 +76,21 @@ impl PubGrubDependencies {
continue;
}
// Add the package, plus any extra variants.
for result in std::iter::once(to_pubgrub(constraint, None, urls, locals)).chain(
constraint
.extras
.clone()
.into_iter()
.map(|extra| to_pubgrub(constraint, Some(extra), urls, locals)),
) {
let (mut package, version) = result?;
// Add the package.
let (package, version) = to_pubgrub(constraint, None, urls, locals)?;
// Detect self-dependencies.
if let PubGrubPackage::Package(name, extra, ..) = &mut package {
if source_name.is_some_and(|source_name| source_name == name) {
// Allow, e.g., `black` to depend on `black[colorama]`.
if source_extra == extra.as_ref() {
warn!("{name} has a dependency on itself");
continue;
}
// Detect self-dependencies.
if let PubGrubPackage::Package(name, extra, ..) = &package {
if source_name.is_some_and(|source_name| source_name == name) {
// Allow, e.g., `black` to depend on `black[colorama]`.
if source_extra == extra.as_ref() {
warn!("{name} has a dependency on itself");
continue;
}
}
dependencies.push((package.clone(), version.clone()));
}
dependencies.push((package.clone(), version.clone()));
}
}
}
+1 -3
View File
@@ -323,13 +323,11 @@ fn compile_constraint_extra() -> Result<()> {
# via
# jinja2
# werkzeug
python-dotenv==1.0.1
# via flask
werkzeug==3.0.1
# via flask
----- stderr -----
Resolved 8 packages in [TIME]
Resolved 7 packages in [TIME]
"###
);