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 <marc.wrobel@gmail.com>
This commit is contained in:
Hugo van Kemenade
2023-11-26 22:08:12 +02:00
committed by GitHub
parent 0d17306872
commit 8870ab5e28
8 changed files with 64 additions and 5 deletions

20
.github/workflows/lint.yml vendored Normal file
View File

@@ -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

26
.pre-commit-config.yaml Normal file
View File

@@ -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

13
.ruff.toml Normal file
View File

@@ -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
]

View File

@@ -8,7 +8,7 @@ count = 0
count_auto = 0 count_auto = 0
products_dir = sys.argv[1] if len(sys.argv) > 1 else 'website/products/' products_dir = sys.argv[1] if len(sys.argv) > 1 else 'website/products/'
for product_file in sorted(list(glob(f'{products_dir}/*.md'))): 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) data = frontmatter.load(f)
count += 1 count += 1
title = data['title'] title = data['title']

View File

@@ -17,3 +17,4 @@ requests==2.31.0
requests-html==0.10.0 requests-html==0.10.0
requests-futures==1.0.1 requests-futures==1.0.1
regex==2023.10.3 regex==2023.10.3
pre-commit==3.5.0

View File

@@ -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: def load_product(product_name, pathname="website/products") -> frontmatter.Post:
"""Load the product's file frontmatter. """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) 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: if products_filter and product_name != products_filter:
continue continue
with open(product_file, "r") as f: with open(product_file) as f:
data = frontmatter.load(f) data = frontmatter.load(f)
if "auto" in data: if "auto" in data:
configs = list(filter( configs = list(filter(

View File

@@ -36,7 +36,7 @@ query($endCursor: String) {
} }
} }
}' --jq '.data.repository.releases.edges.[].node | select(.isPrerelease == false) | [.name, .publishedAt] | join(",")' }' --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) child = subprocess.Popen(query, shell=True, stdout=subprocess.PIPE)
return child.communicate()[0].decode('utf-8') return child.communicate()[0].decode('utf-8')

View File

@@ -1,4 +1,3 @@
import re
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from common import dates from common import dates
from common import endoflife from common import endoflife