Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a proxy layer for extras #3100

Merged
merged 1 commit into from
Apr 19, 2024
Merged

Add a proxy layer for extras #3100

merged 1 commit into from
Apr 19, 2024

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Apr 17, 2024

Given requirements like:

black==23.1.0
black[colorama]

The resolver will (on main) add a dependency on Black, and then try to use the most recent version of Black to satisfy black[colorama]. For sake of example, assume black==24.0.0 is the most recent version. Once the selects this most recent version, it'll fetch the metadata, then return the dependencies for black==24.0.0 with the colorama extra enabled. Finally, it will tack on black==24.0.0 (a dependency on the base package). The resolver will then detect a conflict between black==23.1.0 and black==24.0.0, and throw out black[colorama]==24.0.0, trying to next most-recent version.

This is both wasteful and can cause problems, since we're fetching metadata for versions that will never satisfy the resolver. In the apache-airflow[all] case, I also ran into an issue whereby we were attempting to build very old versions of apache-airflow due to apache-airflow[pandas], which in turn led to resolution failures.

The solution proposed here is that we create a new proxy package with exactly two dependencies: one on black and one of black[colorama]. Both of these packages must be at the same version as the proxy package, so the resolver knows much earlier that (in the above example) the extra variant must match 23.1.0.

@zanieb
Copy link
Member

zanieb commented Apr 17, 2024

I like where this is going

@charliermarsh
Copy link
Member Author

I think the ideas here are sound but need a packse test and more documentation around the concepts.

@charliermarsh charliermarsh changed the base branch from main to charlie/ex-test April 17, 2024 21:06
@charliermarsh charliermarsh force-pushed the charlie/extras branch 2 times, most recently from 647afcf to e0ea9f6 Compare April 17, 2024 21:15
@charliermarsh charliermarsh marked this pull request as ready for review April 17, 2024 21:15
@charliermarsh charliermarsh added the bug Something isn't working label Apr 17, 2024
Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome.

PubGrubPackage::Package(package_name.clone(), Some(extra.clone()), url.clone()),
Range::singleton(version.clone()),
),
])),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I like it.

Copy link
Member

@konstin konstin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@Eh2406
Copy link

Eh2406 commented Apr 18, 2024

This looks like a clever lowering. I'd love to talk it over to see if it helps with a similar problem with "features" in cargo. I was planing to use pubgrub-rs/pubgrub#124 for the "features" problem, and would love to compare.

Base automatically changed from charlie/ex-test to main April 19, 2024 00:47
charliermarsh added a commit that referenced this pull request Apr 19, 2024
## Summary

This PR adds a test that currently leads to an error, but should
successfully resolve as of #3100.

The core idea is that if we have a pinned package, we shouldn't try to
build other versions of that package if we have an unconstrained variant
with an extra.
@charliermarsh charliermarsh enabled auto-merge (squash) April 19, 2024 00:48
@charliermarsh charliermarsh merged commit 2e88bb6 into main Apr 19, 2024
38 checks passed
@charliermarsh charliermarsh deleted the charlie/extras branch April 19, 2024 01:05
charliermarsh added a commit that referenced this pull request Jun 7, 2024
## Summary

This PR adds a lowering similar to that seen in
#3100, but this time, for markers.
Like `PubGrubPackageInner::Extra`, we now have
`PubGrubPackageInner::Marker`. The dependencies of the `Marker` are
`PubGrubPackageInner::Package` with and without the marker.

As an example of why this is useful: assume we have `urllib3>=1.22.0` as
a direct dependency. Later, we see `urllib3 ; python_version > '3.7'` as
a transitive dependency. As-is, we might (for some reason) pick a very
old version of `urllib3` to satisfy `urllib3 ; python_version > '3.7'`,
then attempt to fetch its dependencies, which could even involve
building a very old version of `urllib3 ; python_version > '3.7'`. Once
we fetch the dependencies, we would see that `urllib3` at the same
version is _also_ a dependency (because we tack it on). In the new
scheme though, as soon as we "choose" the very old version of `urllib3 ;
python_version > '3.7'`, we'd then see that `urllib3` (the base package)
is also a dependency; so we see a conflict before we even fetch the
dependencies of the old variant.

With this, I can successfully resolve the case in #4099.

Closes #4099.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants