diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2a41c56..721c2e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -20,3 +20,18 @@ jobs: run: python -m pip install -e ".[mcp]" - name: Run tests run: python -m unittest discover -s tests -t . + quality: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version: "3.13" + - name: Install (with the optional MCP dependency and the checkers) + run: python -m pip install -e ".[mcp]" ruff coverage + - name: Lint + run: ruff check . + - name: Tests with coverage floor (see pyproject.toml) + run: | + python -m coverage run -m unittest discover -s tests -t . + python -m coverage report diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 72edf45..07d4eef 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -11,6 +11,8 @@ Thanks for helping. PersonaKit is pre-release; the design is in - **Respect the module boundaries.** Only `store` touches SQLite, only `llm` talks to a model, only `ingest` reads session files. If you need to break a boundary, open an issue first. - **No duplicated logic.** Reuse an existing helper or move it to the right module. +- **Checks must pass locally first.** `ruff check .` and `python -m coverage run -m unittest discover -s tests -t . && python -m coverage report` + (CI fails below the coverage floor in `pyproject.toml`). - **Small pull requests.** One change, with tests and a doc update if behavior or a privacy claim changes. ## Workflow diff --git a/personakit/extract.py b/personakit/extract.py index eb1ab8b..3666f32 100644 --- a/personakit/extract.py +++ b/personakit/extract.py @@ -60,7 +60,7 @@ class ExtractionResult: memories: list[Memory] = field(default_factory=list) rejected: Counter = field(default_factory=Counter) - def merge(self, other: "ExtractionResult") -> None: + def merge(self, other: ExtractionResult) -> None: self.memories.extend(other.memories) self.rejected.update(other.rejected) diff --git a/personakit/llm.py b/personakit/llm.py index f242a11..6d401b9 100644 --- a/personakit/llm.py +++ b/personakit/llm.py @@ -14,9 +14,10 @@ import json import subprocess import tempfile +from collections.abc import Callable from dataclasses import dataclass from pathlib import Path -from typing import Callable, Protocol +from typing import Protocol from personakit.ingest.common import SANDBOX_PREFIX diff --git a/personakit/retrieve.py b/personakit/retrieve.py index d1869f9..192ad2a 100644 --- a/personakit/retrieve.py +++ b/personakit/retrieve.py @@ -10,8 +10,8 @@ from __future__ import annotations import re +from collections.abc import Iterable from dataclasses import dataclass -from typing import Iterable from personakit.model import Memory, State diff --git a/personakit/review.py b/personakit/review.py index 93e2b6b..3ab0bb3 100644 --- a/personakit/review.py +++ b/personakit/review.py @@ -4,8 +4,8 @@ from __future__ import annotations -from dataclasses import dataclass, field -from typing import Callable +from collections.abc import Callable +from dataclasses import dataclass from personakit.model import Decider, Memory, State from personakit.store import Store diff --git a/personakit/store.py b/personakit/store.py index 6cf43c6..3c7eddf 100644 --- a/personakit/store.py +++ b/personakit/store.py @@ -7,9 +7,9 @@ from __future__ import annotations import sqlite3 +from collections.abc import Callable, Iterable from datetime import datetime, timezone from pathlib import Path -from typing import Callable, Iterable from personakit.model import Decider, Evidence, Memory, State @@ -67,7 +67,7 @@ def __init__(self, path: str | Path, now: Callable[[], str] = _utc_now): def close(self) -> None: self._conn.close() - def __enter__(self) -> "Store": + def __enter__(self) -> Store: return self def __exit__(self, *exc: object) -> None: @@ -176,7 +176,7 @@ def list( clauses, params = [], [] if states is not None: values = [s.value for s in states] - clauses.append("state IN (%s)" % ",".join("?" * len(values))) + clauses.append(f"state IN ({','.join('?' * len(values))})") params.extend(values) if scope is not None: clauses.append("scope = ?") diff --git a/pyproject.toml b/pyproject.toml index b5811f8..a9ab829 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,3 +19,21 @@ personakit = "personakit.cli:main" [tool.setuptools.packages.find] include = ["personakit*"] + +[tool.ruff] +line-length = 130 +target-version = "py310" + +[tool.ruff.lint] +select = ["E", "F", "I", "UP", "B"] + +[tool.coverage.run] +branch = true +source = ["personakit"] + +[tool.coverage.report] +fail_under = 90 +show_missing = true + +[tool.ruff.lint.per-file-ignores] +"tests/*" = ["E501"] diff --git a/tests/test_cli.py b/tests/test_cli.py index ac08b69..aded799 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -7,8 +7,6 @@ from unittest import mock from personakit import cli, llm -from personakit.model import Evidence, Memory -from personakit.store import Store from tests.helpers import reply FIXTURES = Path(__file__).parent / "fixtures" / "claude_code" diff --git a/tests/test_retrieve.py b/tests/test_retrieve.py index 9d25849..e6e0f98 100644 --- a/tests/test_retrieve.py +++ b/tests/test_retrieve.py @@ -1,7 +1,7 @@ import unittest -from personakit.model import Evidence, Memory, State from personakit import retrieve +from personakit.model import Evidence, Memory, State from personakit.retrieve import SERVED, STANDING_CONTEXT, search