Skip to content

Commit 9d5790e

Browse files
authored
[MNT] code quality job (#151)
Adds a code quality job, this checks code formatting based on the same rules as in `sktime`, on files that have changed.
1 parent d9fcea3 commit 9d5790e

3 files changed

Lines changed: 128 additions & 0 deletions

File tree

.github/workflows/test.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,44 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
jobs:
18+
code-quality:
19+
name: code-quality
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: repository checkout step
23+
uses: actions/checkout@v5
24+
25+
- name: python environment step
26+
uses: actions/setup-python@v5
27+
with:
28+
python-version: "3.11"
29+
30+
- name: install pre-commit
31+
run: python3 -m pip install pre-commit
32+
33+
- name: Checkout code
34+
uses: actions/checkout@v5
35+
with:
36+
fetch-depth: 0
37+
38+
- name: Get changed files
39+
id: changed-files
40+
run: |
41+
CHANGED_FILES=$(git diff --name-only ${{ github.event.pull_request.base.sha }} ${{ github.sha }} | tr '\n' ' ')
42+
echo "CHANGED_FILES=${CHANGED_FILES}" >> $GITHUB_ENV
43+
44+
- name: Print changed files
45+
run: |
46+
echo "Changed files:" && echo "$CHANGED_FILES" | tr ' ' '\n'
47+
48+
- name: Run pre-commit on changed files
49+
run: |
50+
if [ -n "$CHANGED_FILES" ]; then
51+
pre-commit run --color always --files $CHANGED_FILES --show-diff-on-failure
52+
else
53+
echo "No changed files to check."
54+
fi
55+
1856
test-no-extras:
1957
name: test-no-extras
2058
strategy:

.pre-commit-config.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: https://github.com/pre-commit/pre-commit-hooks
5+
rev: v4.6.0
6+
hooks:
7+
- id: trailing-whitespace
8+
- id: end-of-file-fixer
9+
- id: check-yaml
10+
- id: check-ast
11+
12+
- repo: https://github.com/astral-sh/ruff-pre-commit
13+
rev: v0.6.9
14+
hooks:
15+
- id: ruff
16+
args: [--fix]
17+
- id: ruff-format
18+
19+
- repo: https://github.com/nbQA-dev/nbQA
20+
rev: 1.8.7
21+
hooks:
22+
- id: nbqa-black
23+
- id: nbqa-ruff
24+
- id: nbqa-check-ast

pyproject.toml

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,69 @@ all_extras = [
6969
"Homepage" = "https://github.com/SimonBlanke/Hyperactive"
7070
"Bug Reports" = "https://github.com/SimonBlanke/Hyperactive/issues"
7171
"Source" = "https://github.com/SimonBlanke/Hyperactive/"
72+
73+
74+
[tool.ruff]
75+
line-length = 88
76+
exclude = [".git", "examples/*"]
77+
target-version = "py39"
78+
extend-include = ["*.ipynb"]
79+
80+
[tool.ruff.lint]
81+
select = [
82+
# https://pypi.org/project/pycodestyle
83+
"D",
84+
"E",
85+
"W",
86+
# https://pypi.org/project/pyflakes
87+
"F",
88+
# https://pypi.org/project/flake8-bandit
89+
"S",
90+
# https://docs.astral.sh/ruff/rules/#pyupgrade-up
91+
"UP",
92+
"I002", # Missing required imports
93+
"UP008", # Super calls with redundant arguments passed.
94+
"G010", # Deprecated log warn.
95+
"PLR1722", # Use sys.exit() instead of exit() and quit().
96+
"PT014", # pytest-duplicate-parametrize-test-cases.
97+
"PT006", # Checks for the type of parameter names passed to pytest.mark.parametrize.
98+
"PT007", # Checks for the type of parameter values passed to pytest.mark.parametrize.
99+
"PT018", # Checks for assertions that combine multiple independent condition
100+
"RUF001", # Checks for non unicode string literals
101+
"RUF002", # Checks for non unicode string literals
102+
"RUF003", # Checks for non unicode string literals
103+
]
104+
extend-select = [
105+
"I", # isort
106+
"C4", # https://pypi.org/project/flake8-comprehensions
107+
]
108+
ignore=[
109+
"E203", # Whitespace-before-punctuation.
110+
"E402", # Module-import-not-at-top-of-file.
111+
"E731", # Do not assign a lambda expression, use a def.
112+
"RET504", # Unnecessary variable assignment before `return` statement.
113+
"S101", # Use of `assert` detected.
114+
"RUF100", # https://docs.astral.sh/ruff/rules/unused-noqa/
115+
"C408", # Unnecessary dict call - rewrite as a literal.
116+
"UP031", # Use format specifier instead of %
117+
"S102", # Use of excec
118+
"C414", # Unnecessary `list` call within `sorted()`
119+
"S301", # pickle and modules that wrap it can be unsafe
120+
"C416", # Unnecessary list comprehension - rewrite as a generator
121+
"S310", # Audit URL open for permitted schemes
122+
"S202", # Uses of `tarfile.extractall()`
123+
"S307", # Use of possibly insecure function
124+
"C417", # Unnecessary `map` usage (rewrite using a generator expression)
125+
"S605", # Starting a process with a shell, possible injection detected
126+
"E741", # Ambiguous variable name
127+
"S107", # Possible hardcoded password
128+
"S105", # Possible hardcoded password
129+
"PT018", # Checks for assertions that combine multiple independent condition
130+
"S602", # sub process call with shell=True unsafe
131+
"C419", # Unnecessary list comprehension, some are flagged yet are not
132+
"C409", # Unnecessary `list` literal passed to `tuple()` (rewrite as a `tuple` literal)
133+
"S113", # Probable use of httpx call without timeout
134+
]
135+
136+
[tool.ruff.lint.pydocstyle]
137+
convention = "numpy"

0 commit comments

Comments
 (0)