diff --git a/pypiprivate/publish.py b/pypiprivate/publish.py index 52f8128..42b3270 100644 --- a/pypiprivate/publish.py +++ b/pypiprivate/publish.py @@ -1,6 +1,7 @@ import os import re import logging +import hashlib from pkg_resources import packaging from jinja2 import Environment @@ -21,6 +22,18 @@ def normalized_name(name): return re.sub(r"[-_.]+", "-", name).lower() +def sha256sum(filename): + h = hashlib.sha256() + b = bytearray(128 * 1024) + mv = memoryview(b) + + with open(filename, 'rb', buffering=0) as f: + for n in iter(lambda: f.readinto(mv), 0): + h.update(mv[:n]) + + return h.hexdigest() + + def _filter_pkg_dists(dists, pkg_name, pkg_ver): # Wheels have different naming conventions: https://www.python.org/dev/peps/pep-0491/#escaping-and-unicode # We want to account for both sdist and wheel naming. @@ -56,7 +69,10 @@ def build_index(title, items, index_type='root'):