-
Notifications
You must be signed in to change notification settings - Fork 16
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
pip_api: initial support for hashed requirements #126
Conversation
pip_api/_parse_requirements.py
Outdated
class Requirement(requirements.Requirement): | ||
def __init__(self, *args, **kwargs): | ||
self.hashes = kwargs.pop("hashes", None) | ||
|
||
super().__init__(*args, **kwargs) |
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.
N.B.: requirements.Requirement
doesn't have any state/API for hashes, so I created a thin child wrapper instead. I figured this would be the least invasive approach, since it doesn't cause any API breakage, but let me know if there's a better/preferred alternative.
hashes_by_kind = defaultdict(list) | ||
if known.hashes: | ||
for hsh in known.hashes: | ||
kind, hsh = hsh.split(":", 1) |
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.
Not sure if it's worth it, but we could also promote any ValueError
that happens here (due to a malformed --hash
option) into a PipError
.
cc @tetsuo-cpp |
@woodruffw I'm getting ready to release a new version with #127, should we try and include this as well? |
Makes sense to me. I can have this ready in a moment. |
pypa/pip-audit#229 should be good to go once this is in. |
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.
LGTM otherwise
Co-authored-by: Dustin Ingram <[email protected]>
WIP.Some things that need to be done:
pip
,parse_requirments
should go into a "strict" mode as soon as it sees a hashed requirement. In strict mode, any requirements that don't have a hash cause an error.