Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions add_to_pydotorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ def md5sum_for(filename: str) -> str:
).hexdigest()


def sha256sum_for(filename: str) -> str:
"""Returns SHA256 checksum for filename."""
return hashlib.sha256(
open(filename, "rb").read(),
).hexdigest()
Comment on lines +213 to +215
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return hashlib.sha256(
open(filename, "rb").read(),
).hexdigest()
return hashlib.sha256(open(filename, "rb").read()).hexdigest()

or

Suggested change
return hashlib.sha256(
open(filename, "rb").read(),
).hexdigest()
with open(filename, "rb") as f:
return hashlib.sha256(f.read()).hexdigest()



def filesize_for(filename: str) -> int:
return path.getsize(filename)

Expand Down Expand Up @@ -261,6 +268,7 @@ def build_file_dict(
"is_source": os_pk == 3,
"url": download_root + f"{base_version(release)}/{rfile}",
"md5_sum": md5sum_for(filename),
"sha256sum": sha256sum_for(filename),
"filesize": filesize_for(filename),
"download_button": add_download,
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_add_to_pydotorg.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_build_file_dict(tmp_path: Path) -> None:
"is_source": False,
"url": f"{release_url}/test-artifact.txt",
"md5_sum": "3e25960a79dbc69b674cd4ec67a72c62",
"sha256sum": "64ec88ca00b268e5ba1a35678a1b5316d212f4f366b2477232534a8aeca37f3c",
"filesize": 11,
"download_button": True,
"sigstore_bundle_file": f"{release_url}/test-artifact.txt.sigstore",
Expand Down