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

Track Markers via a PubGrub package variant #4123

Merged
merged 2 commits into from
Jun 7, 2024
Merged

Conversation

charliermarsh
Copy link
Member

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.

@charliermarsh charliermarsh requested a review from BurntSushi June 7, 2024 02:13
@charliermarsh charliermarsh added bug Something isn't working preview Experimental behavior labels Jun 7, 2024
@@ -727,7 +727,7 @@ fn fork_non_local_fork_marker_direct() -> Result<()> {
----- stderr -----
warning: `uv lock` is experimental and may change without warning.
× No solution found when resolving dependencies:
╰─▶ Because package-b{sys_platform == 'darwin'}==1.0.0 depends on package-c>=2.0.0 and package-a{sys_platform == 'linux'}==1.0.0 depends on package-c<2.0.0, we can conclude that package-a{sys_platform == 'linux'}==1.0.0 and package-b{sys_platform == 'darwin'}==1.0.0 are incompatible.
╰─▶ Because package-b==1.0.0 depends on package-c>=2.0.0 and package-a==1.0.0 depends on package-c<2.0.0, we can conclude that package-a==1.0.0 and package-b{sys_platform == 'darwin'}==1.0.0 are incompatible.
Copy link
Member Author

Choose a reason for hiding this comment

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

There is still some weirdness here -- we might want to throw out the markers entirely when reporting? I know how to do that.

name,
marker,
url: Some(url),
}))
Copy link
Member Author

Choose a reason for hiding this comment

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

There is admittedly some weirdness here. If we have both a marker and an extra, I'm using the Extra variant. The Marker variant is being used only for bare packages with markers. In get_dependencies, if Extra has a marker field, we flatten it out to include the base package with and without markers.

Copy link
Member

Choose a reason for hiding this comment

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

Hmmm yes that is odd. I think that was one of the reasons I ended up not going this route initially, because it seemed like we'd want an ExtraMarker variant too. But I guess the flattening in get_dependencies works around that?

I think I would find some comments about this, on the PubGrabInner variants, helpful.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, the flattening works around it.

),
])),

// Add a dependency on both the extra and base package, with and without the marker.
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 is a bit strange. I think it's necessary?

Copy link
Member

Choose a reason for hiding this comment

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

Would adding a dependency on the virtual marker package and having the virtual package then depend on the real package work to?

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.

Nice fix. Very subtle and clever.

. o O { I find myself wondering if we can somehow abstract the case analysis on PubGrubPackageInner. I find it somewhat difficult to keep it straight how to deal with and consider each case. }

name,
marker,
url: Some(url),
}))
Copy link
Member

Choose a reason for hiding this comment

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

Hmmm yes that is odd. I think that was one of the reasons I ended up not going this route initially, because it seemed like we'd want an ExtraMarker variant too. But I guess the flattening in get_dependencies works around that?

I think I would find some comments about this, on the PubGrabInner variants, helpful.

@charliermarsh
Copy link
Member Author

@BurntSushi -- I agree. We have the same patterns reused in a few places too, around matching on package name and URL.

@charliermarsh charliermarsh enabled auto-merge (squash) June 7, 2024 19:47
@charliermarsh charliermarsh merged commit bcfe88d into main Jun 7, 2024
46 checks passed
@charliermarsh charliermarsh deleted the charlie/marker-pkg branch June 7, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working preview Experimental behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enforce constraints eagerly when forking on markers
3 participants