Skip to content

Commit 0575dc8

Browse files
authored
Refactor the hash helper script to use pathlib and CLI args
1 parent 8682135 commit 0575dc8

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

print-hash.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1-
import os
21
import hashlib
2+
import pathlib
3+
import sys
34

45
sha256 = hashlib.sha256()
56
md5 = hashlib.md5()
67
blake2_256 = hashlib.blake2b(digest_size=256 // 8)
78

8-
file_list = os.listdir(os.path.abspath(os.getenv("INPUT_PACKAGES_DIR")))
9+
packages_dir = pathlib.Path(sys.argv[1]).resolve().absolute()
10+
file_iterable = packages_dir.iterdir()
911

1012
print("Showing hash values of files to be uploaded:")
1113

12-
for file in file_list:
13-
print(file)
14+
for file_object in file_iterable:
15+
print(file_object)
1416
print("")
1517

16-
with open(os.path.abspath(os.path.join(os.getenv("INPUT_PACKAGES_DIR"), file)), "rb") as f:
17-
content = f.read()
18+
content = file_object.read_bytes()
1819

1920
sha256.update(content)
2021
md5.update(content)

twine-upload.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ if [[ ${INPUT_VERBOSE,,} != "false" ]] ; then
4545
fi
4646

4747
if [[ ${INPUT_PRINT_HASH,,} != "false" || ${INPUT_VERBOSE,,} != "false" ]] ; then
48-
python /app/print-hash.py
48+
python /app/print-hash.py "${INPUT_PACKAGES_DIR%%/}"
4949
fi
5050

5151
TWINE_USERNAME="$INPUT_USER" \

0 commit comments

Comments
 (0)