Skip to content

Commit 78eb0f7

Browse files
authored
style(ruff): switch from flake8, isort, bandit & black to ruff (#18)
* style(lint): switched to ruff * docs(makefile): update commands * build(deps): add poetry.lock * ci(github): update existing workflows * ci(style): update style job * style(pyproject): update ruff exceptions * style(ruff): fix lint * ci(labeler): add job for triage * ci(dependabot): configure dependabot * docs(readme): update badges * ci(labeler): add docker label * ci(pr): add PR title checker
1 parent 4946fa6 commit 78eb0f7

15 files changed

Lines changed: 602 additions & 149 deletions

.flake8

Lines changed: 0 additions & 5 deletions
This file was deleted.

.github/collect_env.py

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (C) 2022, François-Guillaume Fernandez.
1+
# Copyright (C) 2022-2024, François-Guillaume Fernandez.
22

33
# This program is licensed under the Apache License version 2.
44
# See LICENSE or go to <https://www.apache.org/licenses/LICENSE-2.0.txt> for full license details.
@@ -13,26 +13,22 @@
1313

1414
import locale
1515
import re
16-
import subprocess
16+
import subprocess # noqa S404
1717
import sys
18-
from collections import namedtuple
18+
from typing import NamedTuple
1919

2020
PY3 = sys.version_info >= (3, 0)
2121

2222

2323
# System Environment Information
24-
SystemEnv = namedtuple(
25-
"SystemEnv",
26-
[
27-
"os",
28-
"python_version",
29-
],
30-
)
24+
class SystemEnv(NamedTuple):
25+
os: str
26+
python_version: str
3127

3228

3329
def run(command):
3430
"""Returns (return-code, stdout, stderr)"""
35-
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
31+
p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) # noqa S602
3632
output, err = p.communicate()
3733
rc = p.returncode
3834
if PY3:
@@ -64,14 +60,13 @@ def run_and_parse_first_match(run_lambda, command, regex):
6460
def get_platform():
6561
if sys.platform.startswith("linux"):
6662
return "linux"
67-
elif sys.platform.startswith("win32"):
63+
if sys.platform.startswith("win32"):
6864
return "win32"
69-
elif sys.platform.startswith("cygwin"):
65+
if sys.platform.startswith("cygwin"):
7066
return "cygwin"
71-
elif sys.platform.startswith("darwin"):
67+
if sys.platform.startswith("darwin"):
7268
return "darwin"
73-
else:
74-
return sys.platform
69+
return sys.platform
7570

7671

7772
def get_mac_version(run_lambda):
@@ -137,14 +132,14 @@ def get_env_info():
137132

138133
def pretty_str(envinfo):
139134
def replace_nones(dct, replacement="Could not collect"):
140-
for key in dct.keys():
135+
for key in dct:
141136
if dct[key] is not None:
142137
continue
143138
dct[key] = replacement
144139
return dct
145140

146141
def replace_bools(dct, true="Yes", false="No"):
147-
for key in dct.keys():
142+
for key in dct:
148143
if dct[key] is True:
149144
dct[key] = true
150145
elif dct[key] is False:

.github/dependabot.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# To get started with Dependabot version updates, you'll need to specify which
2+
# package ecosystems to update and where the package manifests are located.
3+
# Please see the documentation for all configuration options:
4+
# https://docs.github.com/en/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
5+
6+
version: 2
7+
updates:
8+
- package-ecosystem: "pip"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"
12+
time: "06:00"
13+
timezone: "Europe/Paris"
14+
reviewers:
15+
- "frgfm"
16+
assignees:
17+
- "frgfm"
18+
allow:
19+
- dependency-name: "ruff"
20+
- dependency-name: "mypy"
21+
- dependency-name: "pre-commit"

.github/labeler.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'module: src':
2+
- changed-files:
3+
- any-glob-to-any-file: src/*
4+
5+
'module: action':
6+
- changed-files:
7+
- any-glob-to-any-file: action.yml
8+
9+
'topic: ci':
10+
- changed-files:
11+
- any-glob-to-any-file: .github/*
12+
13+
'topic: docs':
14+
- changed-files:
15+
- any-glob-to-any-file:
16+
- README.md
17+
- CONTRIBUTING.md
18+
- CODFE_OF_CONDUCT.md
19+
- LICENSE
20+
21+
'topic: docker':
22+
- changed-files:
23+
- any-glob-to-any-file:
24+
- Dockerfile
25+
- entrypoint.sh
26+
27+
'topic: build':
28+
- changed-files:
29+
- any-glob-to-any-file:
30+
- pyproject.toml
31+
- poetry.lock
32+
33+
'topic: style':
34+
- changed-files:
35+
- any-glob-to-any-file: .pre-commit-config.yaml

.github/workflows/builds.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest]
1616
steps:
17-
- uses: actions/checkout@v2
18-
- name: Cache python modules
19-
uses: satackey/action-docker-layer-caching@v0.0.11
17+
- uses: actions/checkout@v4
18+
- uses: satackey/action-docker-layer-caching@v0.0.11
2019
# Ignore the failure of a step and avoid terminating the job.
2120
continue-on-error: true
2221
- name: Build docker
23-
run: docker build . -t header-validator:py3.8.13-alpine
22+
run: docker build . -t header-validator:latest

.github/workflows/pr-title.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: pr-title
2+
3+
on:
4+
pull_request_target:
5+
types: [opened, reopened, edited, synchronize]
6+
pull_request:
7+
types: [opened, reopened, edited, synchronize]
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: amannn/action-semantic-pull-request@v5
14+
with:
15+
subjectPattern: ^(?![A-Z]).+$
16+
subjectPatternError: |
17+
The subject "{subject}" found in the pull request title "{title}"
18+
didn't match the configured pattern. Please ensure that the subject
19+
doesn't start with an uppercase character.
20+
env:
21+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: pull_requests
2+
3+
on:
4+
pull_request:
5+
branches: main
6+
7+
jobs:
8+
triage:
9+
permissions:
10+
contents: read
11+
pull-requests: write
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/labeler@v4
15+
with:
16+
repo-token: "${{ secrets.GITHUB_TOKEN }}"

.github/workflows/style.yml

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,98 +7,108 @@ on:
77
branches: main
88

99
jobs:
10-
flake8:
10+
ruff:
1111
runs-on: ${{ matrix.os }}
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest]
15-
python: [3.8]
15+
python: [3.9]
1616
steps:
17-
- uses: actions/checkout@v2
18-
- name: Set up Python
19-
uses: actions/setup-python@v1
17+
- uses: actions/checkout@v4
18+
- uses: actions/setup-python@v5
2019
with:
2120
python-version: ${{ matrix.python }}
2221
architecture: x64
23-
- name: Run flake8
24-
run: |
25-
pip install flake8
26-
flake8 --version
27-
flake8
28-
29-
isort:
30-
runs-on: ${{ matrix.os }}
31-
strategy:
32-
matrix:
33-
os: [ubuntu-latest]
34-
python: [3.8]
35-
steps:
36-
- uses: actions/checkout@v2
37-
- name: Set up Python
38-
uses: actions/setup-python@v1
22+
- uses: abatilo/actions-poetry@v3
3923
with:
40-
python-version: ${{ matrix.python }}
41-
architecture: x64
42-
- name: Run isort
24+
poetry-version: "1.8.2"
25+
- name: Resolve dependencies
26+
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade uv
30+
uv pip install --system -r requirements.txt
31+
- name: Run ruff
4332
run: |
44-
pip install isort
45-
isort --version
46-
isort .
47-
if [ -n "$(git status --porcelain --untracked-files=no)" ]; then exit 1; else echo "All clear"; fi
33+
ruff --version
34+
ruff check --diff .
4835
4936
mypy:
5037
runs-on: ${{ matrix.os }}
5138
strategy:
5239
matrix:
5340
os: [ubuntu-latest]
54-
python: [3.8]
41+
python: [3.9]
5542
steps:
56-
- uses: actions/checkout@v2
57-
- name: Set up Python
58-
uses: actions/setup-python@v1
43+
- uses: actions/checkout@v4
44+
- uses: actions/setup-python@v5
5945
with:
6046
python-version: ${{ matrix.python }}
6147
architecture: x64
48+
- uses: abatilo/actions-poetry@v3
49+
with:
50+
poetry-version: "1.8.2"
51+
- name: Resolve dependencies
52+
run: poetry export -f requirements.txt --without-hashes --with quality --output requirements.txt
53+
- name: Install dependencies
54+
run: |
55+
python -m pip install --upgrade uv
56+
uv pip install --system -r requirements.txt
6257
- name: Run mypy
6358
run: |
64-
pip install mypy
6559
mypy --version
6660
mypy
6761
68-
black:
62+
ruff-format:
6963
runs-on: ${{ matrix.os }}
7064
strategy:
7165
matrix:
7266
os: [ubuntu-latest]
73-
python: [3.8]
67+
python: [3.9]
7468
steps:
75-
- uses: actions/checkout@v2
76-
- name: Set up Python
77-
uses: actions/setup-python@v2
69+
- uses: actions/checkout@v4
70+
- uses: actions/setup-python@v5
7871
with:
7972
python-version: ${{ matrix.python }}
8073
architecture: x64
81-
- name: Run black
74+
- uses: abatilo/actions-poetry@v3
75+
with:
76+
poetry-version: "1.8.2"
77+
- name: Resolve dependencies
78+
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
79+
- name: Install dependencies
80+
run: |
81+
python -m pip install --upgrade uv
82+
uv pip install --system -r requirements.txt
83+
- name: Run ruff
8284
run: |
83-
pip install black
84-
black --version
85-
black --check --diff .
85+
ruff --version
86+
ruff format --check --diff .
8687
87-
bandit:
88+
precommit-hooks:
8889
runs-on: ${{ matrix.os }}
8990
strategy:
9091
matrix:
9192
os: [ubuntu-latest]
92-
python: [3.8]
93+
python: [3.9]
9394
steps:
94-
- uses: actions/checkout@v2
95-
- name: Set up Python
96-
uses: actions/setup-python@v2
95+
- uses: actions/checkout@v4
96+
- uses: actions/setup-python@v5
9797
with:
9898
python-version: ${{ matrix.python }}
9999
architecture: x64
100-
- name: Run bandit
100+
- uses: abatilo/actions-poetry@v3
101+
with:
102+
poetry-version: "1.8.2"
103+
- name: Resolve dependencies
104+
run: poetry export -f requirements.txt --without-hashes --only quality --output requirements.txt
105+
- name: Install dependencies
106+
run: |
107+
python -m pip install --upgrade uv
108+
uv pip install --system -r requirements.txt
109+
- name: Run pre-commit hooks
101110
run: |
102-
pip install bandit[toml]
103-
bandit --version
104-
bandit -r . -c pyproject.toml
111+
git checkout -b temp
112+
pre-commit install
113+
pre-commit --version
114+
pre-commit run --all-files

.github/workflows/tests.yml

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,12 @@ jobs:
1414
matrix:
1515
os: [ubuntu-latest]
1616
steps:
17-
- uses: actions/checkout@v2
18-
- name: Cache python modules
19-
uses: satackey/action-docker-layer-caching@v0.0.11
17+
- uses: actions/checkout@v4
18+
- uses: satackey/action-docker-layer-caching@v0.0.11
2019
# Ignore the failure of a step and avoid terminating the job.
2120
continue-on-error: true
22-
- name: Build docker
23-
run: docker build . -t header-validator:py3.8.13-alpine
21+
- run: docker build . -t header-validator:latest
2422
- name: Run action
2523
run: |
26-
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:py3.8.13-alpine 'François-Guillaume Fernandez' 2022 Apache-2.0 src/ __init__.py .github/ ''
27-
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:py3.8.13-alpine 'François-Guillaume Fernandez' 2022 '' src/ __init__.py .github/ .github/license-notice.txt
24+
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:latest 'François-Guillaume Fernandez' 2022 Apache-2.0 src/ __init__.py .github/ ''
25+
docker run --workdir /github/workspace -v "/home/runner/work/validate-python-headers/validate-python-headers":"/github/workspace" header-validator:latest 'François-Guillaume Fernandez' 2022 '' src/ __init__.py .github/ .github/license-notice.txt

0 commit comments

Comments
 (0)