Add ruff configuration and docs
Some checks failed
Run tests and linters / test (pull_request) Successful in 2m58s
Run tests and linters / lint (pull_request) Failing after 2s

Co-authored-by: Kamil Paral <kparal@redhat.com>
Related: #306
This commit is contained in:
Jaroslav Groman 2026-06-01 16:13:23 +02:00 committed by Kamil Páral
commit 3d54a63596
7 changed files with 71 additions and 22 deletions

View file

@ -28,7 +28,7 @@
- Base: `fedora:32` (Dockerfile is outdated)
### Dev Tools
- **Testing:** pytest with pytest-cov | **Linting:** flake8 (max-line-length=100) | **Types:** mypy
- **Testing:** pytest with pytest-cov | **Linting:** ruff | **Types:** mypy
- **CI:** Zuul (`.zuul.yaml`) running pytest on `fedora-latest-container`
- **Versioning:** versioneer 0.28 (PEP 440, git tags)
@ -75,7 +75,7 @@ testing/
- **Bug uniqueness is per-milestone**: A `Bug` with a given `bugid` can exist multiple times in the DB, once per `Milestone`. This is intentional — don't suggest adding a unique constraint on `bugid`.
- **Tracker types**: Three tracker types flow through the codebase: `'Blocker'`, `'FreezeException'`, and `'PrioritizedBug'`. Blocker/FE bugs are tracked via Bugzilla tracker tickets; prioritized bugs via a Bugzilla flag query.
- **Vote parsing**: The Pagure bot (`pagure_bot.py`) parses structured vote commands from Pagure issue comments. Votes, AGREED, and REVOTE commands follow strict parsing rules ("Kamil's Strict Vote Parsing Regime").
- **`# type: ignore` and `# noqa` comments**: Used deliberately throughout models for known SQLAlchemy/mypy/flake8 limitations. Don't suggest removing them.
- **`# type: ignore` and `# noqa` comments**: Used deliberately throughout models for known SQLAlchemy/mypy/ruff limitations. Don't suggest removing them.
### Critical Files
- **`blockerbugs/__init__.py`** — All app setup happens here at import time. Blueprint registration, middleware, and template filters. Changes here affect everything.

View file

@ -49,7 +49,7 @@ jobs:
continue-on-error: true
run: |
source bb-env/bin/activate
EXIT=0; python3.11 -m flake8 --statistics blockerbugs/ testing/ || EXIT=$?; MYPYPATH=./ python3.11 -m mypy || EXIT=$?; exit $EXIT
EXIT=0; ruff check || EXIT=$?; ruff format --check || EXIT=$?; MYPYPATH=./ python3.11 -m mypy || EXIT=$?; exit $EXIT
- name: Run tests
run: |
source bb-env/bin/activate

View file

@ -194,6 +194,36 @@ the command line manually (inside the virtualenv)::
./run lint
Ruff
----
This project uses `Ruff <https://docs.astral.sh/ruff/>`_ for linting and
formatting. It is configured in ``pyproject.toml``. Check this file for Ruff
configuration details.
There are Ruff editor extensions available for various editors. Check your
editor documentation for instructions on how to integrate Ruff into your
workflow.
Running Ruff from the command line
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
The following commands check lint issues and check formatting, and are
automatically run through the ``./run lint`` invocation::
ruff check
ruff format --check
Some lint issues can be fixed automatically through::
ruff check --fix
To reformat code (equivalent to Black; make sure to commit your changes first,
if you want to inspect the diff)::
ruff format
Building documentation
======================

View file

@ -1,5 +1,18 @@
[tool.black]
[tool.ruff]
# Target environment Python version, keep in sync with builder defined at:
# https://forge.fedoraproject.org/infra/ansible/src/branch/main/roles/openshift-apps/blockerbugs/templates/buildconfig.yml.j2
target-version = "py311"
line-length = 100
extend-exclude = [
"alembic/",
"blockerbugs/_version.py",
"conf/",
"docs/source/conf.py",
"versioneer.py",
]
[tool.ruff.lint.isort]
known-first-party = ["blockerbugs"]
[tool.pytest.ini_options]
minversion = "2.0"

View file

@ -1,10 +1,13 @@
# include production dependencies
-r requirements.txt
# tests use postgresql and forgejo containers
testcontainers ~= 4.14.0
## linters
# this automatically also pulls rope and flake8 (which pulls pyflakes, pycodestyle and mccabe)
python-language-server[rope,flake8]
python-language-server[rope]
mypy
ruff
## additional type hints for mypy
types-Flask

31
run
View file

@ -26,7 +26,7 @@ Available commands:
test: Execute the test suite.
coverage: Execute the test suite and measure test coverage. Create a report in
build/coverage/.
lint: Run supported linters - flake8 and mypy.
lint: Run supported linters.
docs: Build the documentation, placed into build/docs/.
setup: Perform an initial DB setup and configure current release, milestones
and bug trackers. Can be re-executed when there is a new release.
@ -98,24 +98,31 @@ function run_coverage {
}
function run_lint {
local cmd='flake8 --statistics'
local flake8_rc=0
echo "Executing command: $cmd"
echo "********************** flake8 **********************"
$cmd && flake8_rc=$? || flake8_rc=$?
echo
cmd='mypy'
local cmd='mypy'
local mypy_rc=0
echo "Executing command: $cmd"
echo "********************** mypy **********************"
$cmd && mypy_rc=$? || mypy_rc=$?
echo
cmd='ruff check'
local ruff_check_rc=0
echo "Executing command: $cmd"
echo "********************** ruff check **********************"
$cmd && ruff_check_rc=$? || ruff_check_rc=$?
echo
cmd='ruff format --check'
local ruff_format_rc=0
echo "Executing command: $cmd"
echo "********************** ruff format **********************"
$cmd && ruff_format_rc=$? || ruff_format_rc=$?
# If one of them returned non-zero, return a global non-zero
if [ "$flake8_rc" -eq 0 ]; then
exit "$mypy_rc"
if [ "$mypy_rc" -eq 0 ] && [ "$ruff_check_rc" -eq 0 ] && [ "$ruff_format_rc" -eq 0 ]; then
exit 0
else
exit "$flake8_rc"
exit 1
fi
}

View file

@ -1,7 +1,3 @@
[flake8]
extend-exclude = alembic/, build/, conf/, docs/, env*/
max-line-length = 100
[mypy]
files = blockerbugs/, testing/, scripts/, setup.py, wsgi.py
# not our code ↓