Skip to content

Commit bae6808

Browse files
committed
NO-JIRA: chore(ci): add pre-commit checks for Python code
1 parent c7e44ae commit bae6808

File tree

4 files changed

+254
-0
lines changed

4 files changed

+254
-0
lines changed

.github/workflows/code-quality.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ jobs:
5050
- name: Install deps
5151
run: uv sync --locked
5252

53+
# https://github.com/pre-commit/action
54+
- name: Run pre-commit on all files
55+
run: |
56+
uv run pre-commit run --all-files
57+
5358
- run: uv run pytest
5459

5560
code-static-analysis:

.pre-commit-config.yaml

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
# https://github.com/pre-commit/pre-commit-hooks?tab=readme-ov-file#hooks-available
3+
repos:
4+
# https://docs.astral.sh/uv/guides/integration/pre-commit/
5+
- repo: https://github.com/astral-sh/uv-pre-commit
6+
rev: 0.6.13
7+
hooks:
8+
- id: uv-lock
9+
# # https://github.com/astral-sh/ruff-pre-commit
10+
# - repo: https://github.com/astral-sh/ruff-pre-commit
11+
# rev: v0.11.4
12+
# hooks:
13+
# - id: ruff
14+
# types_or: [ python, pyi ]
15+
# args: [ --fix ]
16+
# files: 'ci/.*|tests/.*'
17+
# - id: ruff-format
18+
# types_or: [ python, pyi ]
19+
# files: 'ci/.*|tests/.*'
20+
# # https://pre-commit.com/#new-hooks
21+
# - repo: local
22+
# hooks:
23+
# # https://github.com/microsoft/pyright/issues/3612
24+
# # https://github.com/RobertCraigie/pyright-python#pre-commit
25+
# - id: pyright
26+
# name: Run Pyright on all files
27+
# # entry: /bin/bash -c 'find. -name "*.py" | xargs pyright --pythonversion 3.12'
28+
# entry: uv run pyright --pythonversion 3.12
29+
# pass_filenames: true
30+
# types_or: [ python, pyi ]
31+
# language: system
32+
# files: 'ci/.*|tests/.*'

pyproject.toml

+114
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ dependencies = []
1212

1313
[dependency-groups]
1414
dev = [
15+
"pre-commit",
16+
"pyright",
17+
"ruff",
18+
1519
"pytest",
1620
"allure-pytest",
1721
"pytest-subtests",
@@ -39,3 +43,113 @@ environments = [
3943
[build-system]
4044
requires = ["uv-build"]
4145
build-backend = "uv_build"
46+
47+
# inspired from https://github.com/red-hat-data-services/ods-ci/blob/master/pyproject.toml
48+
49+
# https://microsoft.github.io/pyright/#/configuration
50+
[tool.pyright]
51+
typeCheckingMode = "off"
52+
reportMissingImports = "error"
53+
reportUnboundVariable = "error"
54+
reportGeneralTypeIssues = "error"
55+
reportUnnecessaryTypeIgnoreComment = "error"
56+
reportPossiblyUnboundVariable = "warning"
57+
reportOptionalMemberAccess = "none"
58+
reportOptionalSubscript = "none"
59+
include = ["ci/", "tests/"]
60+
ignore = [ ]
61+
pythonVersion = "3.12"
62+
pythonPlatform = "Linux"
63+
64+
# https://docs.astral.sh/ruff/configuration
65+
[tool.ruff]
66+
include = ["pyproject.toml", "ci/**/*.py", "tests/**/*.py"]
67+
exclude = [ ]
68+
target-version = "py312"
69+
line-length = 120
70+
71+
# https://docs.astral.sh/ruff/rules
72+
[tool.ruff.lint]
73+
preview = true
74+
select = [
75+
"B", # flake8-bugbear
76+
"C4", # flake8-comprehensions
77+
"COM", # flake8-commas
78+
"E", "W", # pycodestyle errors/warnings
79+
"F", # Pyflakes
80+
"FA", # flake8-future-annotations
81+
"FLY", # flynt
82+
"G", # flake8-logging-format
83+
"I", # isort
84+
"INP", # flake8-no-pep420
85+
"INT", # flake8-gettext
86+
"ISC", # flake8-implicit-str-concat
87+
"N", # pep8-naming
88+
"NPY002", # numpy-legacy-random
89+
"PERF", # Perflint
90+
"PGH", # pygrep-hooks
91+
"PIE", # misc lints
92+
"PL", # pylint
93+
"PYI", # flake8-pyi
94+
"Q", # flake8-quotes
95+
"RET", # flake8-return
96+
"RUF", # Ruff-specific
97+
"S102", # flake8-bandit: exec-builtin
98+
"T10", # flake8-debugger
99+
"TCH", # type-checking imports
100+
"TID", # flake8-tidy-imports
101+
"UP", # pyupgrade
102+
"YTT", # flake8-2020
103+
]
104+
ignore = [
105+
# intentionally disabled
106+
"E203", # space before : (needed for how black formats slicing)
107+
"ISC001", # single-line-implicit-string-concatenation (ruff format wants this disabled)
108+
# various limits and unimportant warnings
109+
"E501", # Line too long
110+
"E741", # Ambiguous variable name: `l`
111+
"PLR0904", # Too many public methods (56 > 20)
112+
"PLR0912", # Too many branches
113+
"PLR0913", # Too many arguments in function definition (6 > 5)
114+
"PLR0915", # Too many statements
115+
"PLR0917", # Too many positional arguments (10/5)
116+
"PLR0917", # Too many positional arguments (7/5)
117+
"PLR2004", # Magic value used in comparison
118+
# "W503", # not yet implemented; line break before binary operator
119+
# "W504", # not yet implemented; line break after binary operator
120+
# TODO
121+
"B006", # Do not use mutable data structures for argument defaults
122+
"COM812", # Trailing comma missing
123+
"INP001", # File `ods_ci/tests/Resources/Page/ODH/JupyterHub/jupyter-helper.py` is part of an implicit namespace package. Add an `__init__.py`.
124+
"N806", # Variable `outputText` in function should be lowercase
125+
"N813", # Camelcase `ElementTree` imported as lowercase `et`
126+
"N816", # Variable `rotatingHandler` in global scope should not be mixedCase
127+
"N999", # Invalid module name: 'createPolarionTestRun'
128+
"PERF401", # Use a list comprehension to create a transformed list
129+
"PLC1901", # `filter_value != ""` can be simplified to `filter_value` as an empty string is falsey
130+
"PLR6201", # Use a `set` literal when testing for membership
131+
"PLR6301", # Method `_render_template` could be a function, class method, or static method
132+
"PLW1514", # `codecs.open` in text mode without explicit `encoding` argument
133+
"PLW2901", # `for` loop variable `tag_it` overwritten by assignment target
134+
"RET501", # Do not explicitly `return None` in function if it is the only possible return value
135+
"RET504", # Unnecessary assignment to `names` before `return` statement
136+
"RET505", # Unnecessary `else` after `return` statement
137+
"UP015", # Unnecessary open mode parameters
138+
"UP031", # format specifiers instead of percent format
139+
"UP032", # Use f-string instead of `format` call
140+
"RET507", # Unnecessary `else` after `continue` statement
141+
"RET508", # Unnecessary `elif` after `break` statement
142+
]
143+
144+
# Allow unused variables when underscore-prefixed.
145+
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
146+
147+
# https://docs.astral.sh/ruff/formatter
148+
[tool.ruff.format]
149+
line-ending = "lf"
150+
quote-style = "double"
151+
indent-style = "space"
152+
skip-magic-trailing-comma = false
153+
154+
docstring-code-format = true
155+
docstring-code-line-length = "dynamic"

uv.lock

+103
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)