From 0e8fe135e4e45a3068f7b47eb2d86f98a154b8bf Mon Sep 17 00:00:00 2001 From: Marc Wrobel Date: Sat, 30 Dec 2023 10:03:55 +0100 Subject: [PATCH] Enable flake8-bugbear linting rules (#267) See https://docs.astral.sh/ruff/rules/#flake8-bugbear-b. --- .ruff.toml | 1 + src/cgit.py | 2 +- src/common/endoflife.py | 15 ++++++--------- src/common/git.py | 2 +- src/distrowatch.py | 2 +- src/docker_hub.py | 2 +- src/git.py | 2 +- src/github-releases.py | 2 +- src/maven.py | 2 +- src/npm.py | 2 +- src/pypi.py | 2 +- src/sles.py | 2 +- src/splunk.py | 4 ++-- 13 files changed, 19 insertions(+), 21 deletions(-) diff --git a/.ruff.toml b/.ruff.toml index 89f99f90..d0117d8c 100644 --- a/.ruff.toml +++ b/.ruff.toml @@ -1,4 +1,5 @@ select = [ + "B", # flake8-bugbear "C90", # mccabe "E", # pycodestyle errors "F", # pyflakes errors diff --git a/src/cgit.py b/src/cgit.py index 65aaefeb..cb8b39a3 100644 --- a/src/cgit.py +++ b/src/cgit.py @@ -9,7 +9,7 @@ Ideally we would want to use the git repository directly, but cgit-managed repos METHOD = "cgit" p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/common/endoflife.py b/src/common/endoflife.py index a5d2cc0f..09c178ca 100644 --- a/src/common/endoflife.py +++ b/src/common/endoflife.py @@ -137,10 +137,10 @@ class Product: return f"<{self.name}>" -def list_products(method, products_filter=None) -> dict[str, list[dict]]: +def list_products(method, products_filter=None) -> list[str]: """Return a list of products that are using the same given update method. """ - products_with_method = {} + products = [] for product_file in glob(f"{PRODUCTS_PATH}/*.md"): product_name = os.path.splitext(os.path.basename(product_file))[0] @@ -150,11 +150,8 @@ def list_products(method, products_filter=None) -> dict[str, list[dict]]: with open(product_file) as f: data = frontmatter.load(f) if "auto" in data: - configs = list(filter( - lambda config: method in config.keys(), - data["auto"] - )) - if len(configs) > 0: - products_with_method[product_name] = configs + matching_configs = list(filter(lambda config: method in config.keys(), data["auto"])) + if len(matching_configs) > 0: + products.append(product_name) - return products_with_method + return products diff --git a/src/common/git.py b/src/common/git.py index 4bf462f6..782da52e 100644 --- a/src/common/git.py +++ b/src/common/git.py @@ -20,7 +20,7 @@ class Git: child = run(f"git {cmd}", capture_output=True, timeout=300, check=True, shell=True, cwd=self.repo_dir) return child.stdout.decode("utf-8").strip().split("\n") except ChildProcessError as ex: - raise RuntimeError(f"Failed to run '{cmd}': {ex}") + raise RuntimeError(f"Failed to run '{cmd}': {ex}") from ex def setup(self, bare: bool = False): """Creates the repository path and runs: diff --git a/src/distrowatch.py b/src/distrowatch.py index 31477e61..30ff6bea 100644 --- a/src/distrowatch.py +++ b/src/distrowatch.py @@ -6,7 +6,7 @@ from common import dates, endoflife, http METHOD = 'distrowatch' p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/docker_hub.py b/src/docker_hub.py index 35d342f2..c7fdc41e 100644 --- a/src/docker_hub.py +++ b/src/docker_hub.py @@ -23,7 +23,7 @@ def fetch_releases(product, config, url): p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/git.py b/src/git.py index 6338fc37..6e1d03fb 100644 --- a/src/git.py +++ b/src/git.py @@ -8,7 +8,7 @@ from common.git import Git METHOD = 'git' p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/github-releases.py b/src/github-releases.py index 0ff54c78..948f67df 100644 --- a/src/github-releases.py +++ b/src/github-releases.py @@ -43,7 +43,7 @@ query($endCursor: String) { p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/maven.py b/src/maven.py index b101ee26..c75f826e 100644 --- a/src/maven.py +++ b/src/maven.py @@ -6,7 +6,7 @@ from common import endoflife, http METHOD = "maven" p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/npm.py b/src/npm.py index 016d3ddf..3fb40ea6 100644 --- a/src/npm.py +++ b/src/npm.py @@ -5,7 +5,7 @@ from common import dates, endoflife, http METHOD = "npm" p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/pypi.py b/src/pypi.py index c7b0d38f..e625b0ba 100644 --- a/src/pypi.py +++ b/src/pypi.py @@ -5,7 +5,7 @@ from common import dates, endoflife, http METHOD = "pypi" p_filter = sys.argv[1] if len(sys.argv) > 1 else None -for product_name, configs in endoflife.list_products(METHOD, p_filter).items(): +for product_name in endoflife.list_products(METHOD, p_filter): product = endoflife.Product(product_name) print(f"::group::{product.name}") diff --git a/src/sles.py b/src/sles.py index f6d7b570..491f8bce 100644 --- a/src/sles.py +++ b/src/sles.py @@ -21,7 +21,7 @@ for detail_id in [f"detail{row['id']}" for row in sles_header_rows]: for row in minor_versions_table.find_all("tr")[1:]: # For each minor release there is an FCS date, general support end date and LTSS end date cells = row.find_all("td") - version = cells[0].text.strip("SUSE Linux Enterprise Server ").replace(' SP', '.') + version = cells[0].text.replace("SUSE Linux Enterprise Server ", '').replace(' SP', '.') date_str = cells[1].text try: diff --git a/src/splunk.py b/src/splunk.py index eb26c998..a267e909 100644 --- a/src/splunk.py +++ b/src/splunk.py @@ -23,8 +23,8 @@ def get_latest_minor_versions(versions): # For each group, find the version with the highest patch version latest_versions = [] - for major_minor, group in version_groups.items(): - latest_patch = max(group, key=lambda version: int(version[2])) + for version_group in version_groups.values(): + latest_patch = max(version_group, key=lambda v: int(v[2])) latest_versions.append('.'.join(latest_patch)) return latest_versions