Supply sha256 checksum to mocked PyPI

This commit is contained in:
Frost Ming
2020-10-28 10:44:02 +08:00
parent 2f92245172
commit 98fbe2fc5a
3 changed files with 8 additions and 4 deletions
+6 -2
View File
@@ -16,7 +16,7 @@ from six.moves import xmlrpc_client
from flask import Flask, redirect, abort, render_template, send_file, jsonify
ReleaseTuple = collections.namedtuple("ReleaseTuple", ["path", "requires_python"])
ReleaseTuple = collections.namedtuple("ReleaseTuple", ["path", "requires_python", "hash"])
app = Flask(__name__)
session = requests.Session()
@@ -86,13 +86,17 @@ class Package(object):
path_to_binary = os.path.abspath(path_to_binary)
path, release = os.path.split(path_to_binary)
requires_python = ""
hash_value = ""
if path_to_binary.endswith(".whl"):
pkg = distlib.wheel.Wheel(path_to_binary)
md_dict = pkg.metadata.todict()
requires_python = md_dict.get("requires_python", "")
if requires_python.count(".") > 1:
requires_python, _, _ = requires_python.rpartition(".")
self.releases[release] = ReleaseTuple(path_to_binary, requires_python)
if os.path.isfile(path_to_binary + ".sha256"):
with open(path_to_binary + ".sha256") as f:
hash_value = f.read().strip()
self.releases[release] = ReleaseTuple(path_to_binary, requires_python, hash_value)
self._package_dirs.add(ReleaseTuple(path, requires_python))
@@ -7,7 +7,7 @@
<body>
<h1>Links for {{ package.name }}</h1>
{% for release, value in package.releases.items() %}
<a href="/{{ package.name }}/{{ release }}"{%- if value.requires_python %} data-requires-python="{{ value.requires_python }}"{% endif %}>{{ release }}</a>
<a href="/{{ package.name }}/{{ release }}{%- if value.hash %}#sha256={{ value.hash }}{% endif %}"{%- if value.requires_python %} data-requires-python="{{ value.requires_python }}"{% endif %}>{{ release }}</a>
<br>
{% endfor %}
</body>