From 8870ab5e28fd6329e4a5d302c6e5bb3068dae7d1 Mon Sep 17 00:00:00 2001 From: Hugo van Kemenade Date: Sun, 26 Nov 2023 22:08:12 +0200 Subject: [PATCH] Lint on GitHub Actions (#196) - Lint with pre-commit on GitHub Actions, - Add some handy pre-hooks, - Configure Ruff lint rules (https://github.com/astral-sh/ruff). --------- Co-authored-by: Marc Wrobel --- .github/workflows/lint.yml | 20 ++++++++++++++++++++ .pre-commit-config.yaml | 26 ++++++++++++++++++++++++++ .ruff.toml | 13 +++++++++++++ report.py | 2 +- requirements.txt | 1 + src/common/endoflife.py | 4 ++-- src/github-releases.py | 2 +- src/sles.py | 1 - 8 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 .pre-commit-config.yaml create mode 100644 .ruff.toml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..85097631 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,20 @@ +name: Lint + +on: [push, pull_request, workflow_dispatch] + +env: + FORCE_COLOR: 1 + +permissions: + contents: read + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v4 + with: + python-version: "3.x" + - uses: pre-commit/action@v3.0.0 diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..1fce773d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,26 @@ +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.6 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-case-conflict + - id: check-merge-conflict + - id: check-json + - id: check-yaml + - id: debug-statements + - id: end-of-file-fixer + exclude: releases/.* + - id: trailing-whitespace + + - repo: meta + hooks: + - id: check-hooks-apply + - id: check-useless-excludes + +ci: + autoupdate_schedule: quarterly diff --git a/.ruff.toml b/.ruff.toml new file mode 100644 index 00000000..5245594a --- /dev/null +++ b/.ruff.toml @@ -0,0 +1,13 @@ +select = [ + "E", # pycodestyle errors + "F", # pyflakes errors + "ISC", # flake8-implicit-str-concat + "PGH", # pygrep-hooks + "RUF100", # unused noqa (yesqa) + "UP", # pyupgrade + "W", # pycodestyle warnings + "YTT", # flake8-2020 +] +extend-ignore = [ + "E501", # Line too long +] diff --git a/report.py b/report.py index 91f8be24..2696a9f1 100755 --- a/report.py +++ b/report.py @@ -8,7 +8,7 @@ count = 0 count_auto = 0 products_dir = sys.argv[1] if len(sys.argv) > 1 else 'website/products/' for product_file in sorted(list(glob(f'{products_dir}/*.md'))): - with open(product_file, "r") as f: + with open(product_file) as f: data = frontmatter.load(f) count += 1 title = data['title'] diff --git a/requirements.txt b/requirements.txt index fede8539..a1eea65d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,4 @@ requests==2.31.0 requests-html==0.10.0 requests-futures==1.0.1 regex==2023.10.3 +pre-commit==3.5.0 diff --git a/src/common/endoflife.py b/src/common/endoflife.py index ff410a98..536a9822 100644 --- a/src/common/endoflife.py +++ b/src/common/endoflife.py @@ -16,7 +16,7 @@ USER_AGENT = 'Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/1 def load_product(product_name, pathname="website/products") -> frontmatter.Post: """Load the product's file frontmatter. """ - with open(f"{pathname}/{product_name}.md", "r") as f: + with open(f"{pathname}/{product_name}.md") as f: return frontmatter.load(f) @@ -30,7 +30,7 @@ def list_products(method, products_filter=None, pathname="website/products") -> if products_filter and product_name != products_filter: continue - with open(product_file, "r") as f: + with open(product_file) as f: data = frontmatter.load(f) if "auto" in data: configs = list(filter( diff --git a/src/github-releases.py b/src/github-releases.py index 0ba1fb7e..0ac44f4d 100644 --- a/src/github-releases.py +++ b/src/github-releases.py @@ -36,7 +36,7 @@ query($endCursor: String) { } } }' --jq '.data.repository.releases.edges.[].node | select(.isPrerelease == false) | [.name, .publishedAt] | join(",")' -""" % (repo, owner) +""" % (repo, owner) # noqa: UP031 child = subprocess.Popen(query, shell=True, stdout=subprocess.PIPE) return child.communicate()[0].decode('utf-8') diff --git a/src/sles.py b/src/sles.py index 420ff137..0086b032 100644 --- a/src/sles.py +++ b/src/sles.py @@ -1,4 +1,3 @@ -import re from bs4 import BeautifulSoup from common import dates from common import endoflife