Skip to content

Comments

Require URL dependencies to be declared upfront#319

Merged
charliermarsh merged 1 commit intomainfrom
charlie/strict-dependency
Nov 5, 2023
Merged

Require URL dependencies to be declared upfront#319
charliermarsh merged 1 commit intomainfrom
charlie/strict-dependency

Conversation

@charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Nov 4, 2023

In the resolver, our current model for solving URL dependencies requires that we visit the URL dependency before the registry-based dependency. This PR encodes a strict requirement that all URL dependencies be declared upfront, either as requirements or constraints.

I wrote more about how it works and why it's necessary in documentation here. I think we could relax this constraint over time, but it requires a more sophisticated model -- and for now, I just want something that's (1) correct, (2) easy for us to reason about, and (3) easy for users to reason about.

As additional motivation... allowing arbitrary URL dependencies anywhere in the tree creates some really confusing situations in which I'm not even sure what the right answers are. For example, assume you declare a direct dependency on Werkzeug==2.0.0. You then depend on a version of Flask that depends on a version of Werkzeug from some arbitrary URL. You build the source distribution at that arbitrary URL, and it turns out it does build to a declared version of 2.0.0. What should happen? (And if it resolves to a version that isn't 2.0.0, what should happen then?) I suspect different tools handle this differently, but it must lead to a lot of "silent" failures. In my testing of Poetry, it seems like Poetry just ignores the URL dependency, which seems wrong, but is also a behavior we could implement in the future.

Closes #303.
Closes #284.

@charliermarsh charliermarsh force-pushed the charlie/strict-dependency branch 2 times, most recently from 869a408 to 0d043dd Compare November 4, 2023 19:50
mod version;

/// Convert a set of requirements to a set of `PubGrub` packages and ranges.
pub(crate) fn iter_requirements<'a>(
Copy link
Member Author

Choose a reason for hiding this comment

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

This was all moved into the new PubGrubDependencies struct (and modified).

{
debug!("Adding root dependency: {package} {version}");
Self::visit_package(&package, &mut priorities, &mut in_flight, request_sink)?;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This isn't necessary -- we end up visiting this immediately after anyway by way of visiting the Root package.


----- stderr -----
× No solution found when resolving dependencies:
╰─▶ root depends on werkzeug 3.0.0
Copy link
Member Author

Choose a reason for hiding this comment

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

Bad error message, sigh...

/// To enforce this requirement, we in turn require that all possible URL dependencies are
/// defined upfront, as `requirements.txt` or `constraints.txt` or similar. Otherwise,
/// solving these graphs becomes far more complicated -- and the "right" behavior isn't
/// even clear. For example, imagine that you define a direct dependency on WerkZeug, and
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// even clear. For example, imagine that you define a direct dependency on WerkZeug, and
/// even clear. For example, imagine that you define a direct dependency on Werkzeug, and

also below

Copy link
Member Author

Choose a reason for hiding this comment

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

FYI WerkZeug means tool in German.

@charliermarsh charliermarsh force-pushed the charlie/strict-dependency branch from 0d043dd to 83a2f71 Compare November 5, 2023 17:07
@charliermarsh charliermarsh enabled auto-merge (squash) November 5, 2023 17:07
@charliermarsh charliermarsh merged commit 4b83d8e into main Nov 5, 2023
@charliermarsh charliermarsh deleted the charlie/strict-dependency branch November 5, 2023 17:09
charliermarsh added a commit that referenced this pull request Dec 8, 2024
## Summary

As far as I can tell, this was added in
#319, but it seems _incorrect_ to
ignore these.

Closes #9693.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Require that URL dependencies are declared upfront Throw an error if a requirement exists with conflicting URLs

2 participants