mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 02:54:26 +00:00
The ruff toolchain was unpinned, so host venvs, the lint container and CI installed different releases over time. That drift is why lint-python only failed on CI: locally ruff 0.15.x preview-gated ISC004/FURB192 and (falsely) fired S310 on urllib.request.Request, while CI's 0.16.0 has ISC004/FURB192 stable and drops the S310-on-Request false positive. Pin ruff==0.16.0 in pyproject.toml's dev extras (Dependabot keeps it current) and have utils.install.lint.ruff read that pin and reinstall whenever the found version drifts, so every environment resolves the same ruff. Then fix what 0.16.0 flags: parenthesise the implicit string concatenations (ISC004), use min() over sorted()[0] (FURB192), drop the now-unused S310 noqa on the Request() builders (RUF100), and delete the narration comments that the comment lint surfaces in the touched files. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
60 lines
1.9 KiB
Python
60 lines
1.9 KiB
Python
"""Install the ruff version pinned in pyproject.toml so every environment matches.
|
|
|
|
The pin lives in ``[project.optional-dependencies].dev`` (one SPOT, Dependabot
|
|
keeps it current). Host venvs, the lint container and CI all read that same pin,
|
|
so a rule that is preview-gated in one release and stable in the next (e.g.
|
|
ISC004, or S310 firing on ``urllib.request.Request``) cannot disagree across
|
|
environments.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import subprocess
|
|
import tomllib
|
|
|
|
from utils.cache import PROJECT_ROOT
|
|
from utils.install.pip import install_pip_pkg
|
|
from utils.install.primitives import log, which
|
|
|
|
_PYPROJECT = PROJECT_ROOT / "pyproject.toml"
|
|
|
|
|
|
def _pinned_spec() -> str:
|
|
"""Return the ruff requirement string declared in pyproject's dev extras."""
|
|
with _PYPROJECT.open("rb") as f:
|
|
dev = tomllib.load(f)["project"]["optional-dependencies"]["dev"]
|
|
for dep in dev:
|
|
if dep == "ruff" or dep.startswith("ruff=="):
|
|
return dep
|
|
raise RuntimeError(
|
|
"ruff is not declared in pyproject.toml [project.optional-dependencies].dev"
|
|
)
|
|
|
|
|
|
def _installed_version() -> str | None:
|
|
try:
|
|
proc = subprocess.run(
|
|
["ruff", "--version"], capture_output=True, text=True, check=True
|
|
)
|
|
except (OSError, subprocess.CalledProcessError):
|
|
return None
|
|
parts = proc.stdout.split()
|
|
return parts[1] if len(parts) >= 2 else None
|
|
|
|
|
|
def ensure() -> None:
|
|
"""Install the pinned ruff, reinstalling whenever the found version drifts."""
|
|
spec = os.environ.get("RUFF_PIP_SPEC") or _pinned_spec()
|
|
want = spec.split("==", 1)[1] if "==" in spec else None
|
|
if want is not None and _installed_version() == want:
|
|
return
|
|
|
|
log(f"Installing {spec} (found {_installed_version() or 'no ruff'}).")
|
|
install_pip_pkg(spec)
|
|
|
|
if not which("ruff"):
|
|
raise RuntimeError(
|
|
f"Command 'ruff' is still unavailable after installing {spec}."
|
|
)
|