From 96cadaa4d9e02b28fa831314b253037370288d2d Mon Sep 17 00:00:00 2001 From: Denys Fedoryshchenko Date: Thu, 9 Apr 2026 00:13:11 +0300 Subject: [PATCH] ci: Set linting according to discussion Ref: https://github.com/kernelci/kernelci-project/issues/566 Signed-off-by: Denys Fedoryshchenko --- .github/workflows/main.yml | 28 ++++++---------------------- .pre-commit-config.yaml | 8 ++++++++ api/main.py | 10 ++++++++++ docker/api/requirements-dev.txt | 4 ++-- pyproject.toml | 22 ++++++++++++++++++++-- tests/e2e_tests/test_pipeline.py | 2 +- 6 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 3bb48a2d..9f959c6b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -72,33 +72,17 @@ jobs: lint: runs-on: ubuntu-latest - container: - image: ubuntu:24.04 name: Lint steps: - - name: Install base tooling - run: | - apt-get update - apt-get install -y --no-install-recommends git python3 python3-venv python3-pip - - - name: Create Python virtual environment - run: | - python3 -m venv /opt/venv - /opt/venv/bin/pip install --no-cache-dir --upgrade pip - - name: Check out source code uses: actions/checkout@v4 - with: - fetch-depth: 32 # This is necessary to get the commits - - name: Install linting dependencies - run: | - /opt/venv/bin/pip install --no-cache-dir ruff + - name: Install ruff + run: pip install ruff - - name: Run ruff format check (line-length policy) - run: /opt/venv/bin/ruff format --check --diff --line-length 110 api tests + - name: Ruff lint + run: ruff check . - - name: Run ruff lint check (E/W/F/I + complexity policy) - run: | - /opt/venv/bin/ruff check --line-length 110 --select E,W,F,I,C901 --ignore E203 api tests + - name: Ruff format + run: ruff format --check --diff . diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..d1a00bf3 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: LGPL-2.1-or-later +repos: + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.11.5 + hooks: + - id: ruff + args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format diff --git a/api/main.py b/api/main.py index e00710b8..4cace41c 100644 --- a/api/main.py +++ b/api/main.py @@ -1703,9 +1703,19 @@ async def patch_node( # State transition checks if new_state is not None: +<<<<<<< HEAD is_valid, message = specialized_node.validate_node_state_transition(new_state) if not is_valid: raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=message) +======= + is_valid, message = specialized_node.validate_node_state_transition( + new_state + ) + if not is_valid: + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, detail=message + ) +>>>>>>> 7df261e (api: Implement PATCH endpoint for node) if new_state != new_node_def.state: new_node_def.processed_by_kcidb_bridge = False new_node_def.state = new_state diff --git a/docker/api/requirements-dev.txt b/docker/api/requirements-dev.txt index d8446c8c..2b5aeb27 100644 --- a/docker/api/requirements-dev.txt +++ b/docker/api/requirements-dev.txt @@ -1,3 +1,3 @@ -r requirements-tests.txt -pycodestyle==2.8.0 -pylint==4.0.4 +ruff>=0.9.0 +pre-commit>=4.0.0 diff --git a/pyproject.toml b/pyproject.toml index c45466fd..395d75ca 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,8 +46,8 @@ tests = [ ] dev = [ "kernelci-api[tests]", - "pycodestyle == 2.8.0", - "pylint == 4.0.4", + "ruff >= 0.9.0", + "pre-commit >= 4.0.0", ] [project.urls] @@ -64,3 +64,21 @@ scripts = ["*"] "api.static.css" = ["*.css"] "api.static.js" = ["*.js"] migrations = ["*.py"] + +# Ruff — used by CI and pre-commit hooks +[tool.ruff] +target-version = "py310" +# Soft limit for formatter wrapping +line-length = 80 + +[tool.ruff.lint] +# Ruff defaults (E, F, W) plus import sorting and complexity checking +select = ["E", "F", "W", "I", "C901"] + +[tool.ruff.lint.pycodestyle] +# Hard limit — lines beyond this are errors regardless of formatter +max-line-length = 110 + +[tool.ruff.lint.per-file-ignores] +# Legacy high-complexity entrypoint, to be refactored incrementally +"api/main.py" = ["C901"] diff --git a/tests/e2e_tests/test_pipeline.py b/tests/e2e_tests/test_pipeline.py index 7b0c12e4..f87099cc 100644 --- a/tests/e2e_tests/test_pipeline.py +++ b/tests/e2e_tests/test_pipeline.py @@ -10,7 +10,7 @@ from cloudevents.http import from_json from .listen_handler import create_listen_task -from .test_node_handler import create_node, get_node_by_id, update_node +from .test_node_handler import create_node, get_node_by_id, patch_node, update_node @pytest.mark.dependency(