Skip to content

Commit

Permalink
Formatting changes to hash-built-wheels script
Browse files Browse the repository at this point in the history
Mostly nitpicks, geared toward making the script more Pythonic and
intuitive. Another pass is warranted to flesh out comments and
docstrings, we can squash during final review.
  • Loading branch information
Conor Schaefer committed May 15, 2019
1 parent b60f713 commit 33b5a27
Showing 1 changed file with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,19 @@
import glob
import hashlib
import os
import re
import sys

REQUIREMENTS_FILE = os.environ['SD_REQUIREMENTS']
WHEELHOUSE = os.environ['SD_WHEELHOUSE']
LOCK_FILE = os.environ['SD_PIP_LOCK']


def main():
f = open(LOCK_FILE, "r")
lockfile = f.readlines()
f.close()

with open(LOCK_FILE, "r") as f:
lockfile = f.readlines()

# remove newlines
lockfile = list(map(lambda x: x.strip(), lockfile))
lockfile = [x.strip() for x in lockfile]
new_reqs = ""

for line in lockfile:
Expand All @@ -25,9 +24,8 @@ def main():
package_string = "{}-{}".format(package.replace("-", "_"), version)
new_reqs += "{}=={}".format(package, version)
new_reqs += " --hash=sha256:{}\n".format(get_hash_for_package(package_string))
reqs_file = open(REQUIREMENTS_FILE, "w")
reqs_file.write(new_reqs)
reqs_file.close()
with open(REQUIREMENTS_FILE, "w") as reqs_file:
reqs_file.write(new_reqs)


def get_hash_for_package(package):
Expand All @@ -38,11 +36,10 @@ def get_hash_for_package(package):

def get_wheel(name):
result = glob.glob(name + "*.whl")
if(len(result) == 1):
return result[0]
else:
print("There are several wheels matching package name", file=sys.stderr) # noqa
sys.exit(1)
if len(result) != 1:
msg = "There are several wheels matching package {}".format(name)
raise Exception(msg)
return result[0]


def sha256_file(path):
Expand Down

0 comments on commit 33b5a27

Please sign in to comment.