-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Add SHA256 hash of .whl as info output #5908
Changes from 1 commit
4e8b6e9
09e3184
3c68b84
2639514
8d4e17c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Wheel builds will output the final filename and SHA256 hash of .whl | ||
files as an info log entry. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,15 +68,22 @@ def normpath(src, p): | |
return os.path.relpath(src, p).replace(os.path.sep, '/') | ||
|
||
|
||
def rehash(path, blocksize=1 << 20): | ||
# type: (str, int) -> Tuple[str, str] | ||
def hash_file(path, blocksize=1 << 20): | ||
cjerdonek marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# type: (str, int) -> Tuple[Any, str] | ||
"""Return (hash, length) for path using hashlib.sha256()""" | ||
h = hashlib.sha256() | ||
length = 0 | ||
with open(path, 'rb') as f: | ||
for block in read_chunks(f, size=blocksize): | ||
length += len(block) | ||
h.update(block) | ||
return (h, str(length)) # type: ignore | ||
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. This could return the length as 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. Good observation. For that matter (but not for this PR), 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. I have made |
||
|
||
|
||
def rehash(path, blocksize=1 << 20): | ||
# type: (str, int) -> Tuple[str, str] | ||
"""Return (encoded_digest, length) for path using hashlib.sha256()""" | ||
h, length = hash_file(path, blocksize) | ||
digest = 'sha256=' + urlsafe_b64encode( | ||
h.digest() | ||
).decode('latin1').rstrip('=') | ||
|
@@ -885,7 +892,10 @@ def _build_one_inside_env(self, req, output_dir, python_tag=None): | |
wheel_name = os.path.basename(wheel_path) | ||
dest_path = os.path.join(output_dir, wheel_name) | ||
try: | ||
wheel_hash, _ = hash_file(wheel_path) | ||
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. I think it would be helpful for readers of the code to give a name to the second variable in the return value. You could add a code comment above the line saying, "We don't need to use the second value." if you would like to communicate that. 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.
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. I have put the length into the output string with a8e382b, so this value is now used |
||
shutil.move(wheel_path, dest_path) | ||
logger.info('Finished: %s sha256=%s', | ||
wheel_name, wheel_hash.hexdigest()) | ||
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. The other log messages in your post have the form "Running setup.py bdist_wheel for simple: finished ..." So maybe this could be "Finished wheel for <name>: ..." 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. Also, this 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. I agree on the format and have changed that with a8e382b I did leave the following info message ( The line will become quite long with the full path too; however if you feel strongly the backwards compatibility issues aren't a concern I can change it. 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. I guess I don't feel strongly about merging the log messages. However, I'd rather not create any expectation among users (or future maintainers for that matter) that log messages won't or shouldn't change. One reason is that I think we should be open to improving these messages when we can as a matter of UX. Thus, my preference would be for the comment not to be there. 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.
By the way, to clarify, my suggestion was for the second log message to be in the same log message as the first but still be on a separate line (i.e. a newline character would go in the message). Thus, the lengths of lines needn't increase, and in fact the same greps could even work if the text was kept the same. 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.
Removed with 45a6415
Ahh ... yes I wasn't sure about multi-line log strings. This probably comes from some ancient history of mine where I was dealing with |
||
logger.info('Stored in directory: %s', output_dir) | ||
return dest_path | ||
except Exception: | ||
|
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.
You should use the imperative tone (see https://pip.pypa.io/en/stable/development/contributing/#news-entries ). Maybe something like this?
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 have addressed this with 09e3184