From 8981ae0a0086e1bd6d8ab6900ddd5a78bc92a304 Mon Sep 17 00:00:00 2001 From: Jakub Famulski 2 Date: Tue, 25 Aug 2026 12:37:41 +0200 Subject: [PATCH] ci: enforce Ruff lint checks --- .gitea/workflows/ci.yaml | 12 ++++++++++++ app.py | 5 ++--- engin/__init__.py | 2 +- engin/charts.py | 1 - engin/config.py | 9 +++++++-- engin/model.py | 7 ++++++- engin/validation.py | 2 +- final_pipeline.py | 2 -- ml_polish_benchmark.py | 5 ++--- ruff.toml | 5 +++++ tests/test_app_smoke.py | 1 - tests/test_explainability.py | 1 - tests/test_service.py | 2 +- tests/test_validation.py | 1 - 14 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 ruff.toml diff --git a/.gitea/workflows/ci.yaml b/.gitea/workflows/ci.yaml index 8a47e25..7b8bfce 100644 --- a/.gitea/workflows/ci.yaml +++ b/.gitea/workflows/ci.yaml @@ -27,6 +27,18 @@ jobs: - name: Build production image run: docker build --tag engin-console:ci . + - name: Run Ruff + run: | + docker run --rm \ + --entrypoint sh \ + engin-console:ci \ + -c "python -m pip install --quiet \ + --disable-pip-version-check \ + --root-user-action=ignore \ + ruff==0.16.4 && + ruff check --no-cache \ + app.py engin tests final_pipeline.py ml_polish_benchmark.py" + - name: Check installed dependencies run: | docker run --rm \ diff --git a/app.py b/app.py index a53b436..6cea172 100644 --- a/app.py +++ b/app.py @@ -13,12 +13,12 @@ import streamlit as st from engin.charts import cylinder_spectrum, deviation_chart, engine_heatmap from engin.config import ( - AppConfig, LABEL_COLORS, LABEL_DISPLAY, LABEL_ICONS, NOT_APPLICABLE, SEVERITY_DISPLAY, + AppConfig, ) from engin.errors import UserFacingError from engin.explainability import ( @@ -32,7 +32,6 @@ from engin.model import PrecomputedPredictionModel, SklearnPredictionModel from engin.service import DiagnosisResult, DiagnosticService from engin.validation import SpectrumFrameValidator - LOGGER = logging.getLogger("engin.app") BASE_DIR = Path(__file__).resolve().parent @@ -62,7 +61,7 @@ def build_dependencies() -> AppDependencies: service=DiagnosticService(reader=reader, validator=validator, model=model), demo_payload=demo_payload, ) - except Exception as exc: + except Exception: LOGGER.exception("Live model initialization failed; enabling demo fallback") submission = pd.read_csv(BASE_DIR / "predictions.csv") diagnostics = pd.read_csv(BASE_DIR / "prediction_diagnostics.csv") diff --git a/engin/__init__.py b/engin/__init__.py index c235a14..e12931f 100644 --- a/engin/__init__.py +++ b/engin/__init__.py @@ -1,5 +1,5 @@ """Core application package for the ENGIN diagnostic console.""" -from .service import DiagnosticService, DiagnosisResult +from .service import DiagnosisResult, DiagnosticService __all__ = ["DiagnosticService", "DiagnosisResult"] diff --git a/engin/charts.py b/engin/charts.py index fd23280..d802457 100644 --- a/engin/charts.py +++ b/engin/charts.py @@ -8,7 +8,6 @@ import plotly.graph_objects as go from .config import FREQ_COLS, LABEL_COLORS from .explainability import EngineAnalysis - PLOT_BG = "#101820" GRID = "rgba(148, 163, 184, 0.14)" TEXT = "#dce8ee" diff --git a/engin/config.py b/engin/config.py index 1b331a4..2cedbc7 100644 --- a/engin/config.py +++ b/engin/config.py @@ -4,8 +4,13 @@ from __future__ import annotations from dataclasses import dataclass -from benchmark_grouped import FAULT_LABELS, FREQ_COLS, LABELS, NOT_APPLICABLE, SEVERITIES - +from benchmark_grouped import ( + FAULT_LABELS, + FREQ_COLS, + LABELS, + NOT_APPLICABLE, + SEVERITIES, +) ALLOWED_ENGINE_SIZES = (8, 12, 16) MAX_UPLOAD_BYTES = 10 * 1024 * 1024 diff --git a/engin/model.py b/engin/model.py index 479cdd1..81a8b64 100644 --- a/engin/model.py +++ b/engin/model.py @@ -7,7 +7,12 @@ from typing import Protocol import pandas as pd -from final_pipeline import DiagnosticModels, predict_test, train_models, validate_submission +from final_pipeline import ( + DiagnosticModels, + predict_test, + train_models, + validate_submission, +) from .errors import InferenceError diff --git a/engin/validation.py b/engin/validation.py index 935f8ab..402071c 100644 --- a/engin/validation.py +++ b/engin/validation.py @@ -8,7 +8,7 @@ from typing import Protocol import numpy as np import pandas as pd -from .config import AppConfig, FREQ_COLS +from .config import FREQ_COLS, AppConfig from .errors import InputDataError diff --git a/final_pipeline.py b/final_pipeline.py index 41721ec..ce28fcd 100644 --- a/final_pipeline.py +++ b/final_pipeline.py @@ -28,7 +28,6 @@ from benchmark_grouped import ( LABELS, NOT_APPLICABLE, SEVERITIES, - make_pipeline, validate_data, ) from severity_benchmark import ( @@ -39,7 +38,6 @@ from severity_benchmark import ( prepare_labeled_frame, ) - LABEL_MODEL_NAME = "deviation_logistic_c10" LABEL_FEATURE_SET = "deviation" SEVERITY_CANDIDATE_ID = "deviation_extra_trees_mf03" diff --git a/ml_polish_benchmark.py b/ml_polish_benchmark.py index cf5cc49..0577c2e 100644 --- a/ml_polish_benchmark.py +++ b/ml_polish_benchmark.py @@ -19,8 +19,8 @@ from benchmark_grouped import ( FAULT_LABELS, LABELS, NOT_APPLICABLE, - make_splits, macro_f1, + make_splits, ml_points, raw_score, validate_data, @@ -38,7 +38,6 @@ from severity_benchmark import ( prepare_labeled_frame, ) - DEFAULT_SEEDS = [7, 21, 42, 77, 123] @@ -166,7 +165,7 @@ def main() -> None: "ood_overrides": ood_count[scenario], } row.update( - {f"f1_{label}": float(value) for label, value in zip(LABELS, per_class)} + {f"f1_{label}": float(value) for label, value in zip(LABELS, per_class, strict=True)} ) run_rows.append(row) diff --git a/ruff.toml b/ruff.toml new file mode 100644 index 0000000..6da756e --- /dev/null +++ b/ruff.toml @@ -0,0 +1,5 @@ +target-version = "py312" +extend-exclude = ["archive/legacy_experiments"] + +[lint] +select = ["E4", "E7", "E9", "F", "I", "B"] diff --git a/tests/test_app_smoke.py b/tests/test_app_smoke.py index 8a21444..d45d526 100644 --- a/tests/test_app_smoke.py +++ b/tests/test_app_smoke.py @@ -5,7 +5,6 @@ from pathlib import Path from streamlit.testing.v1 import AppTest - ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_explainability.py b/tests/test_explainability.py index 1e35b5d..875fa33 100644 --- a/tests/test_explainability.py +++ b/tests/test_explainability.py @@ -14,7 +14,6 @@ from engin.explainability import ( ) from engin.service import DiagnosisResult - ROOT = Path(__file__).resolve().parents[1] diff --git a/tests/test_service.py b/tests/test_service.py index 9cd95dd..50552f5 100644 --- a/tests/test_service.py +++ b/tests/test_service.py @@ -4,7 +4,7 @@ import unittest import pandas as pd -from engin.model import PredictionBundle, PrecomputedPredictionModel +from engin.model import PrecomputedPredictionModel, PredictionBundle from engin.service import DiagnosticService from engin.validation import ValidationResult diff --git a/tests/test_validation.py b/tests/test_validation.py index 2cb3f32..33fac30 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -10,7 +10,6 @@ from engin.config import FREQ_COLS from engin.errors import InputDataError from engin.validation import SpectrumFrameValidator - ROOT = Path(__file__).resolve().parents[1]