From a230ca83f202f6c957147fb24775a48e5c297c02 Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Fri, 3 Dec 2021 10:15:58 -0800 Subject: [PATCH] python/update-python-libraries: Allow usage of hash --- .../update-python-libraries/update-python-libraries.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py index b27204c16245..3a6a14133ea3 100755 --- a/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py +++ b/pkgs/development/interpreters/python/update-python-libraries/update-python-libraries.py @@ -342,7 +342,15 @@ def _update_package(path, target): raise ValueError("no file available for {}.".format(pname)) text = _replace_value('version', new_version, text) - text = _replace_value('sha256', new_sha256, text) + + # fetchers can specify a sha256, or a sri hash + try: + text = _replace_value('sha256', new_sha256, text) + except ValueError: + # hashes from pypi are 16-bit encoded sha256's, need translate to an sri hash if used with "hash" + sri_hash = subprocess.check_output(["nix", "hash", "to-sri", "--type", "sha256", new_sha256]).decode('utf-8').strip() + text = _replace_value('hash', sri_hash, text) + if fetcher == 'fetchFromGitHub': text = _replace_value('rev', f"{prefix}${{version}}", text) # incase there's no prefix, just rewrite without interpolation