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

Move conflicting dependencies into PubGrub #1796

Merged
merged 1 commit into from Feb 22, 2024
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Feb 21, 2024

Summary

This revives a PR from long ago (#383 and astral-sh/pubgrub#24) that modifies how we deal with dependencies that are declared multiple times within a single package.

To quote from the originating PR:

Uses an experimental pubgrub branch (#370) that allows us to handle multiple version ranges for a single dependency to the solver which results in better error messages because the derivation tree contains all of the relevant versions. Previously, the version ranges were merged (by us) in the resolver before handing them to pubgrub since only one range could be provided per package. Since we don't merge the versions anymore, we no longer give the solver an empty range for conflicting requirements; instead the solver comes to that conclusion from the provided versions. You can see the improved error message for direct dependencies in this snapshot.

The main issue with that PR was around its handling of URL dependencies, so this PR also refactors how we handle those. Previously, we stored URL dependencies on PubGrubPackage, but they were omitted from the hash and equality implementations of PubGrubPackage. This led to some really careful codepaths wherein we had to ensure that we always visited URLs before non-URL packages, so that the URL-inclusive versions were included in any hashmaps, etc. I considered preserving this approach, but it would require us to rely on lots of internal details of PubGrub (since we'd now be relying on PubGrub to merge those packages in the "right" order).

So, instead, we now always set the URL on a given package, whenever that package was given a URL upfront. I think this is easier to reason about: if the user provided a URL for flask, then we should just always add the URL for flask. If we see some other URL for flask, we error, like before. If we see some unknown URL for flask, we error, like before.

Closes #1522.

Closes #1821.

Closes #1615.

@charliermarsh
Copy link
Member Author

(No reviews yet, this doesn't pass the test suite.)

@charliermarsh
Copy link
Member Author

\cc @zanieb for visibility.

@charliermarsh charliermarsh force-pushed the charlie/transitive branch 9 times, most recently from 40304a0 to e5368db Compare February 21, 2024 18:12
@charliermarsh charliermarsh requested review from zanieb and removed request for zanieb February 21, 2024 18:19
@charliermarsh charliermarsh force-pushed the charlie/transitive branch 5 times, most recently from 2ccd7c9 to b5fc027 Compare February 21, 2024 19:21
@charliermarsh charliermarsh marked this pull request as ready for review February 21, 2024 19:24
╰─▶ Because only albatross==1.0.0 is available and albatross==1.0.0 depends on crow>=2.0.0b1, we can conclude that all versions of albatross depend on crow>=2.0.0b1.
And because only crow<2.0.0b1 is available, we can conclude that all versions of albatross depend on crow>3.0.0.
And because bluebird==1.0.0 depends on crow and only bluebird==1.0.0 is available, we can conclude that all versions of albatross and all versions of bluebird are incompatible.
And because you require albatross and you require bluebird, we can conclude that the requirements are unsatisfiable.
Copy link
Member Author

Choose a reason for hiding this comment

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

I believe these are generally the result of dependencies being presented to PubGrub in a different order.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah it's a little weird but a known issue.

@charliermarsh charliermarsh added the bug Something isn't working label Feb 21, 2024
@charliermarsh charliermarsh force-pushed the charlie/transitive branch 3 times, most recently from b22f853 to 9573239 Compare February 21, 2024 19:27
Comment on lines 1279 to 1281
× No solution found when resolving dependencies:
╰─▶ your requirements cannot be used because there are conflicting URLs for
package `werkzeug`:
- https://files.pythonhosted.org/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl
- https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl
error: There are conflicting URLs for package `werkzeug`:
- https://files.pythonhosted.org/packages/bd/24/11c3ea5a7e866bf2d97f0501d0b4b1c9bbeade102bb4b588f0d2919a5212/Werkzeug-2.0.1-py3-none-any.whl
- https://files.pythonhosted.org/packages/ff/1d/960bb4017c68674a1cb099534840f18d3def3ce44aed12b5ed8b78e0153e/Werkzeug-2.0.0-py3-none-any.whl
Copy link
Member

Choose a reason for hiding this comment

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

Is this an improvement? Should we clarify that the URLs come from the provided requirements?

Comment on lines -1601 to +1626
╰─▶ my-project cannot be used because there are conflicting versions for
`django`: `django==5.0b1` does not intersect with `django==5.0a1`
╰─▶ Because my-project depends on django==5.0b1 and my-project depends on
django==5.0a1, we can conclude that the requirements are unsatisfiable.
Copy link
Member

Choose a reason for hiding this comment

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

Nice. It'll be better once we combine clauses #1009, maybe someday we should even track the source of dependencies so we can say what file each of these came from.

Comment on lines 3753 to 3782
/// Resolve a package from a `requirements.in` file, with a `constraints.txt` file pinning it to
/// a specific URL.
Copy link
Member

Choose a reason for hiding this comment

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

This reads a little confusing

Comment on lines +4000 to +4030
× No solution found when resolving dependencies:
╰─▶ Because you require filelock==1.0.0 and you require filelock==3.8.0, we
can conclude that the requirements are unsatisfiable.
Copy link
Member

Choose a reason for hiding this comment

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

This one definitely makes me want to open an issue to display the locations of direct requirements in error messages.

Cargo.toml Outdated
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "9b6d89cb8a0c7902815c8b2ae99106ba322ffb14" }
pubgrub = { git = "https://github.com/zanieb/pubgrub", rev = "5d0270cc2932ab233bb7f66a09fb0764fed7154e" }
Copy link
Member

Choose a reason for hiding this comment

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

Let's make sure to merge upstream and use the main commit before merging this one.

Copy link
Member

@zanieb zanieb left a comment

Choose a reason for hiding this comment

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

Looks nice. Is there anything you wanted me to give a closer look?

@charliermarsh charliermarsh force-pushed the charlie/transitive branch 5 times, most recently from 6bfed7a to 4df39a9 Compare February 22, 2024 02:01
@charliermarsh charliermarsh merged commit 7eaed07 into main Feb 22, 2024
7 checks passed
@charliermarsh charliermarsh deleted the charlie/transitive branch February 22, 2024 02:27
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
2 participants