Skip to content

Allow unpinned requirements to use hashes from constraints#13887

Open
pradyunsg wants to merge 1 commit intopypa:mainfrom
pradyunsg:resolver-constraints-pins-hashes
Open

Allow unpinned requirements to use hashes from constraints#13887
pradyunsg wants to merge 1 commit intopypa: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?

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
Copy link
Copy Markdown
Member

@sbidoul sbidoul left a comment

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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