From 4323150c5ca643fa117d7bf25b3a5330c770086b Mon Sep 17 00:00:00 2001 From: Martin Weinelt Date: Sat, 25 Feb 2023 13:02:38 +0100 Subject: [PATCH] update-python-libraries: Improve code quality - Prune unused imports - Collect imports at the top - Removed unused exception assignments - Fill bare except clause with - Expand overly long check_output lines --- .../update-python-libraries.py | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) 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 d19c597f6695..14b3ed4f3f1e 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 @@ -13,8 +13,8 @@ to update all non-pinned libraries in that folder. import argparse import json +import logging import os -import pathlib import re import requests from concurrent.futures import ThreadPoolExecutor as Pool @@ -39,7 +39,6 @@ GIT = "git" NIXPKGS_ROOT = subprocess.check_output(["git", "rev-parse", "--show-toplevel"]).decode('utf-8').strip() -import logging logging.basicConfig(level=logging.INFO) @@ -284,13 +283,21 @@ def _get_latest_version_github(package, extension, current_version, target): hash = _hash_to_sri(algorithm, document[algorithm]) else: try: - hash = subprocess.check_output(["nix-prefetch-url", "--type", "sha256", "--unpack", f"{release['tarball_url']}"], stderr=subprocess.DEVNULL)\ - .decode('utf-8').strip() - except: + hash = subprocess.check_output([ + "nix-prefetch-url", + "--type", "sha256", + "--unpack", + f"{release['tarball_url']}" + ], stderr=subprocess.DEVNULL).decode('utf-8').strip() + except (subprocess.CalledProcessError, UnicodeError): # this may fail if they have both a branch and a tag of the same name, attempt tag name tag_url = str(release['tarball_url']).replace("tarball","tarball/refs/tags") - hash = subprocess.check_output(["nix-prefetch-url", "--type", "sha256", "--unpack", tag_url], stderr=subprocess.DEVNULL)\ - .decode('utf-8').strip() + hash = subprocess.check_output([ + "nix-prefetch-url", + "--type", "sha256", + "--unpack", + tag_url + ], stderr=subprocess.DEVNULL).decode('utf-8').strip() return version, hash, prefix @@ -337,12 +344,12 @@ def _determine_extension(text, fetcher): if fetcher == 'fetchPypi': try: src_format = _get_unique_value('format', text) - except ValueError as e: + except ValueError: src_format = None # format was not given try: extension = _get_unique_value('extension', text) - except ValueError as e: + except ValueError: extension = None # extension was not given if extension is None: