chore: enforce ruff config and fix lint findings

This commit is contained in:
2026-08-15 20:45:02 +01:00
parent 06ce53bc44
commit dbbea1a95f
12 changed files with 42 additions and 26 deletions
+5
View File
@@ -29,6 +29,11 @@ jobs:
pip install -r requirements.txt pip install -r requirements.txt
pip install httpx pip install httpx
- name: Lint
run: |
pip install ruff
ruff check .
- name: Byte-compile every module - name: Byte-compile every module
run: python -m compileall -q ashvale scripts run.py run: python -m compileall -q ashvale scripts run.py
-1
View File
@@ -30,7 +30,6 @@ Two jobs here, both familiar from soft-sensor work:
from __future__ import annotations from __future__ import annotations
import math
from dataclasses import dataclass, field from dataclasses import dataclass, field
from typing import Dict, Optional from typing import Dict, Optional
+8 -2
View File
@@ -32,8 +32,14 @@ from typing import Dict, List, Tuple
import numpy as np import numpy as np
from .physics import (absolute_humidity, clear_sky_irradiance, dew_point, from .physics import (
solar_position, vapour_pressure_deficit, wet_bulb) absolute_humidity,
clear_sky_irradiance,
dew_point,
solar_position,
vapour_pressure_deficit,
wet_bulb,
)
FEATURE_NAMES: List[str] = [ FEATURE_NAMES: List[str] = [
"bias", "bias",
+1 -2
View File
@@ -34,8 +34,7 @@ matters.
from __future__ import annotations from __future__ import annotations
import asyncio import asyncio
import time from typing import List, Sequence, Tuple
from typing import Dict, List, Sequence, Tuple
OFF = (0, 0, 0) OFF = (0, 0, 0)
+4 -4
View File
@@ -12,11 +12,11 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from .rls import RecursiveLeastSquares, AdaptiveConformal
from .nowcast import NowcastEnsemble
from .climatology import HarmonicClimatology
from .precip import PrecipitationModel, zambretti
from .anomaly import AnomalyMonitor from .anomaly import AnomalyMonitor
from .climatology import HarmonicClimatology
from .nowcast import NowcastEnsemble
from .precip import PrecipitationModel, zambretti
from .rls import AdaptiveConformal, RecursiveLeastSquares
__all__ = [ __all__ = [
"RecursiveLeastSquares", "AdaptiveConformal", "NowcastEnsemble", "RecursiveLeastSquares", "AdaptiveConformal", "NowcastEnsemble",
+2 -2
View File
@@ -141,9 +141,9 @@ class HarmonicClimatology:
sigma0 = self.resid_std.get(target, 1.0) sigma0 = self.resid_std.get(target, 1.0)
sigma = sigma0 * np.sqrt(1.0 + lead_h / 24.0) sigma = sigma0 * np.sqrt(1.0 + lead_h / 24.0)
return [ return [
{"ts": float(t), "lead_h": float(l), "mu": float(m), {"ts": float(t), "lead_h": float(lh), "mu": float(m),
"lo": float(m - 1.645 * s), "hi": float(m + 1.645 * s)} "lo": float(m - 1.645 * s), "hi": float(m + 1.645 * s)}
for t, l, m, s in zip(grid, lead_h, mu, sigma) for t, lh, m, s in zip(grid, lead_h, mu, sigma)
] ]
def anomaly_now(self, target: str, ts: float, observed: float) -> float: def anomaly_now(self, target: str, ts: float, observed: float) -> float:
+1 -1
View File
@@ -39,7 +39,7 @@ from __future__ import annotations
import math import math
import time import time
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional
import numpy as np import numpy as np
-1
View File
@@ -25,7 +25,6 @@ same code to the Pi unchanged.
from __future__ import annotations from __future__ import annotations
import math import math
import random
import time import time
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
+1 -2
View File
@@ -34,7 +34,6 @@ from __future__ import annotations
import asyncio import asyncio
import json import json
import math
import time import time
from pathlib import Path from pathlib import Path
from typing import Any, Dict, List, Optional from typing import Any, Dict, List, Optional
@@ -44,7 +43,7 @@ import numpy as np
from . import physics from . import physics
from .config import Config from .config import Config
from .estimation import SignalTracker from .estimation import SignalTracker
from .features import N_FEATURES, build_features from .features import build_features
from .models.anomaly import AnomalyMonitor from .models.anomaly import AnomalyMonitor
from .models.climatology import HarmonicClimatology from .models.climatology import HarmonicClimatology
from .models.nowcast import NowcastEnsemble from .models.nowcast import NowcastEnsemble
+4 -1
View File
@@ -77,5 +77,8 @@ line-length = 100
target-version = "py39" target-version = "py39"
[tool.ruff.lint] [tool.ruff.lint]
select = ["E", "F", "W", "I", "UP", "B"] # UP is deliberately absent. With target-version = "py39" it fights the
# `from __future__ import annotations` style used throughout and generates
# several hundred findings for no behavioural gain. B currently finds nothing.
select = ["E", "F", "W", "I"]
ignore = ["E501"] ignore = ["E501"]
+7 -5
View File
@@ -47,11 +47,11 @@ import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from ashvale.config import load_config # noqa: E402 from ashvale.config import load_config # noqa: E402
from ashvale.features import build_features # noqa: E402 from ashvale.features import build_features # noqa: E402
from ashvale.models.climatology import HarmonicClimatology # noqa: E402 from ashvale.models.climatology import HarmonicClimatology # noqa: E402
from ashvale.models.nowcast import NowcastEnsemble # noqa: E402 from ashvale.models.nowcast import NowcastEnsemble # noqa: E402
from ashvale.storage import Store, resample # noqa: E402 from ashvale.storage import Store, resample # noqa: E402
def horizon_label(seconds: int) -> str: def horizon_label(seconds: int) -> str:
@@ -163,7 +163,9 @@ def main() -> None:
f"{r['bias']:>+8.3f} {r['weights']}{flag}") f"{r['bias']:>+8.3f} {r['weights']}{flag}")
print() print()
print(f"units: temperature C, humidity %, pressure hPa") # Driven off the dict rather than hardcoded, so adding a target cannot leave
# the units line silently describing the wrong columns.
print("units: " + ", ".join(f"{t} {units[t]}" for t in cfg.model.targets if t in units))
print("coverage should sit near 90% if the conformal calibration is honest.") print("coverage should sit near 90% if the conformal calibration is honest.")
+9 -5
View File
@@ -50,11 +50,15 @@ import numpy as np
sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
from ashvale.config import load_config # noqa: E402 from ashvale.config import load_config # noqa: E402
from ashvale.estimation import SignalTracker # noqa: E402 from ashvale.estimation import SignalTracker # noqa: E402
from ashvale.physics import (dew_point, sea_level_pressure, # noqa: E402 from ashvale.physics import ( # noqa: E402
solar_position, clear_sky_irradiance) clear_sky_irradiance,
from ashvale.storage import Store # noqa: E402 dew_point,
sea_level_pressure,
solar_position,
)
from ashvale.storage import Store # noqa: E402
def generate(days: float, step_s: int, lat: float, lon: float, def generate(days: float, step_s: int, lat: float, lon: float,