Skip to content

Allow unpinned requirements to use hashes from constraints - #13887

Merged
pradyunsg merged 1 commit into
pypa:mainfrom
pradyunsg:resolver-constraints-pins-hashes
Apr 17, 2026
Merged

Allow unpinned requirements to use hashes from constraints#13887
pradyunsg merged 1 commit into
pypa:mainfrom
pradyunsg:resolver-constraints-pins-hashes

Conversation

@pradyunsg

Copy link
Copy Markdown
Member

Closes #9243, I think?

This is now a tomorrow thing for me. Gotta go to PyCon US stuff now.

@pradyunsg
pradyunsg force-pushed the resolver-constraints-pins-hashes branch from 5ce88cb to dac19f2 Compare April 6, 2026 10:47
Comment on lines +60 to +63
hash_options = {
alg: [v for v in other.hash_options[alg] if v in self.hash_options[alg]]
for alg in self.hash_options.keys() & other.hash_options.keys()
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Should multiple entries for the same requirement get unioned or intersected?

Right now, this mirrors Hashes.__and__: uses as-is when one side is empty, intersection of them when both are present.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Though choice. Maybe unioned in case users combine constraints files for different platforms?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Let's get this in people's hands and see what they say? 👀

It's easier to start restrictive and relax this, so I'm leaning towards the intersection for the first iteration that we release.

Constraints with `==version --hash=...` correctly narrow the candidate
set, but the per-candidate `InstallRequirement` still reflected the
original unpinned and hashless requirement.

In such a configuration, plumb through the hashes from the constraints
to the per-candidate `InstallRequirement`, and pin it to the version
from the link (which is informed by the constraint). This makes
hashes get correctly used for candidate selection and verification, at
the cost of a few copies at the start of the resolve in such cases.
@pradyunsg
pradyunsg force-pushed the resolver-constraints-pins-hashes branch from dac19f2 to 3cd1be1 Compare April 6, 2026 20:26
@pradyunsg
pradyunsg marked this pull request as ready for review April 6, 2026 20:26
@sbidoul sbidoul added this to the 26.1 milestone Apr 11, 2026

@sbidoul sbidoul left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I admit I never deeply understood what a requirement template was, but the implementation looks good to me and I tested this resolves #9243.

Comment on lines +60 to +63
hash_options = {
alg: [v for v in other.hash_options[alg] if v in self.hash_options[alg]]
for alg in self.hash_options.keys() & other.hash_options.keys()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Though choice. Maybe unioned in case users combine constraints files for different platforms?

template = copy.copy(template)
template.hash_options = {
k: list(v) for k, v in constraint_hash_options.items()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Is this to do a deepcopy ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yea, I could do a deepcopy directly too; if that'd be clearer. 😅

@sbidoul sbidoul modified the milestones: 26.1, Drop the legacy resolver Apr 12, 2026
@sbidoul sbidoul added the C: constraint Dealing with "constraints" (the -c option) label Apr 12, 2026
@pradyunsg
pradyunsg merged commit 9aef949 into pypa:main Apr 17, 2026
36 checks passed
@pradyunsg
pradyunsg deleted the resolver-constraints-pins-hashes branch April 17, 2026 20:41
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators May 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bot:chronographer:provided C: constraint Dealing with "constraints" (the -c option)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[regression] resolvelib-based dependency processing of constraints with hashes fails to "see" the exact pins

2 participants