-
-
Notifications
You must be signed in to change notification settings - Fork 634
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
Handle URL requirements with constraints files. #11907
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6482ed9
Handle URL requirements with constraints files.
benjyw 23455f8
Git is fussy
benjyw 632e7e3
Git, still finicky.
benjyw d88aa09
Fix test.
benjyw 5a4dc29
See what's up
benjyw 786dba7
Again
benjyw c3d5c5b
Maybe this will fix the test in CI.
benjyw 635b0bd
Maybe now...
benjyw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -244,13 +244,25 @@ async def pex_from_targets( | |
# In requirement strings, Foo_-Bar.BAZ and foo-bar-baz refer to the same project. We let | ||
# packaging canonicalize for us. | ||
# See: https://www.python.org/dev/peps/pep-0503/#normalized-names | ||
exact_req_projects = { | ||
canonicalize_project_name(Requirement.parse(req).project_name) for req in exact_reqs | ||
} | ||
|
||
url_reqs = set() # E.g., 'foobar@ git+https://github.com/foo/bar.git@branch' | ||
name_reqs = set() # E.g., foobar>=1.2.3 | ||
name_req_projects = set() | ||
|
||
for req_str in exact_reqs: | ||
req = Requirement.parse(req_str) | ||
if req.url: # type: ignore[attr-defined] | ||
url_reqs.add(req) | ||
else: | ||
name_reqs.add(req) | ||
name_req_projects.add(canonicalize_project_name(req.project_name)) | ||
|
||
constraint_file_projects = { | ||
canonicalize_project_name(req.project_name) for req in constraints_file_reqs | ||
} | ||
unconstrained_projects = exact_req_projects - constraint_file_projects | ||
# Constraints files must only contain name reqs, not URL reqs (those are already | ||
# constrained by their very nature). See https://github.com/pypa/pip/issues/8210. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noting that Pip now has support for URL reqs in constraint files via: pypa/pip#9673 pypa/pip#8210 spawned -> pypa/pip#8253 which was fixed by -> pypa/pip#9673 |
||
unconstrained_projects = name_req_projects - constraint_file_projects | ||
if unconstrained_projects: | ||
constraints_descr = ( | ||
f"constraints file {constraints_file.path}" | ||
|
@@ -272,15 +284,27 @@ async def pex_from_targets( | |
"file does not cover all requirements." | ||
) | ||
else: | ||
# To get a full set of requirements we must add the URL requirements to the | ||
# constraints file, since the latter cannot contain URL requirements. | ||
# NB: We can only add the URL requirements we know about here, i.e., those that | ||
# are transitive deps of the targets in play. There may be others in the repo. | ||
# So we may end up creating a few different repository pexes, each with identical | ||
# name requirements but different subsets of URL requirements. Fortunately since | ||
# all these repository pexes will have identical pinned versions of everything, | ||
# this is not a correctness issue, only a performance one. | ||
# TODO: Address this as part of providing proper lockfile support. However we | ||
# generate lockfiles, they must be able to include URL requirements. | ||
all_constraints = {str(req) for req in (constraints_file_reqs | url_reqs)} | ||
repository_pex = await Get( | ||
Pex, | ||
PexRequest( | ||
description=f"Resolving {python_setup.requirement_constraints}", | ||
output_filename="repository.pex", | ||
internal_only=request.internal_only, | ||
requirements=PexRequirements(str(req) for req in constraints_file_reqs), | ||
requirements=PexRequirements(all_constraints), | ||
interpreter_constraints=interpreter_constraints, | ||
platforms=request.platforms, | ||
additional_args=["-vvv"], | ||
), | ||
) | ||
elif ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR adds a lot of randomness from all appearances. Lots of sets and set math. It seems the original order of the constraints and or requirements should be kept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought, but the
PexRequirements
ctor sorts its argument. So we were already not preserving the original order, but we were (and still are) eliminating randomness.