Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 19 additions & 16 deletions .devcontainer/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,27 @@ done
# ---------------------------------------------------------------------------
# 2. Python virtualenv and dependencies
# ---------------------------------------------------------------------------
# Dependencies are declared in pyproject.toml. This used to install from a
# requirements-dev.txt that does not exist in this repository -- it came from
# the demo repository this container was copied from -- so the step failed on
# every container build.
# Dependencies are declared in pyproject.toml and resolved in the committed
# uv.lock; `uv sync` builds .venv from the lock, so the Codespace gets the
# versions everyone else has. This used to install from a requirements-dev.txt
# that does not exist in this repository -- it came from the demo repository
# this container was copied from -- so the step failed on every container
# build.
#
# `[dev]` is pytest and ruff, which is what a Codespace needs to run the fast
# suite. The OCR backends are separate extras: add ,easyocr ,paddle or
# use [all] if you need them, and expect a long install and model downloads on
# first use.
echo "Creating Python virtualenv..."
python3 -m venv "$REPO_DIR/.venv"
# `dev` is pytest and ruff, which is what a Codespace needs to run the fast
# suite. The OCR backends are separate extras: add --extra easyocr, --extra
# paddle or --extra all if you need them, and expect a long install and model
# downloads on first use.
#
# uv comes from pipx, which the universal image ships, rather than from a
# curl-to-shell installer.
if ! command -v uv >/dev/null 2>&1; then
echo "Installing uv..."
pipx install uv || python3 -m pip install --user uv
fi

echo "Installing Python dependencies..."
"$REPO_DIR/.venv/bin/pip" install --upgrade pip
# Braced deliberately. Unbraced, `$REPO_DIR[dev]` is array-subscript
# syntax in zsh and expands to nothing; the script is bash, but the line
# gets copied into terminals that are not.
"$REPO_DIR/.venv/bin/pip" install -e "${REPO_DIR}[dev]"
echo "Creating .venv from uv.lock..."
uv sync --project "$REPO_DIR" --extra dev

echo ""
echo "Setup complete. Open .devcontainer/workspace.code-workspace, or your own *.local.code-workspace."
28 changes: 22 additions & 6 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Dependabot keeps the workflow actions current.
# Dependabot keeps the workflow actions and the Python lockfile current.
#
# Added August 2026, after an audit found actions/checkout pinned anywhere
# between v2 and v7 across the sibling repositories. The only two repos on the
Expand All @@ -17,11 +17,15 @@
# `ci` rather than `build`: these are workflow dependencies, not package ones,
# and it matches the two satellite repositories.
#
# Scoped to actions only, deliberately. pip (pyproject.toml) and npm
# (site/package.json) are not enrolled -- that would be a decision about PR
# volume on a 540-package lockfile, not about the drift this fixes. Security
# advisories are separate and unaffected: those come from Dependabot alerts,
# which do not need this file.
# Python is enrolled through `uv`, which bumps the resolved versions in
# uv.lock and leaves the floors in pyproject.toml alone -- those stay a human
# decision. The lock covers every extra, torch and PaddlePaddle included, so
# the updates are grouped into one pull request a week; ungrouped, a lockfile
# that size would arrive as a dozen PRs that each rewrite the file the others
# were built against. npm (site/package.json) is still not enrolled: that
# would be a decision about PR volume on a 540-package lockfile, not about the
# drift this fixes. Security advisories are separate and unaffected: those
# come from Dependabot alerts, which do not need this file.
# The group exists so a batch of action bumps arrives as one pull request. The
# sibling sites learned this the hard way with npm: five separate lockfile PRs
# conflict with each other by construction, because merging any one of them
Expand All @@ -30,6 +34,18 @@
# whole set moves together the way the sweep that added this file did.
version: 2
updates:
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"
commit-message:
prefix: "build"
include: "scope"
groups:
python:
patterns:
- "*"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
20 changes: 17 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,19 @@ jobs:
- name: Bands match the committed sweep
run: python -m evaluation.ocr.calibration.fit --check

# The committed uv.lock is what gives the Trivy job below real versions to
# scan, and what Dependabot's `uv` updates bump. It has to match
# pyproject.toml, or the scan reports an environment nobody installs.
# Regenerate with `uv lock` after any pyproject.toml change; the pre-commit
# hook runs the same check. Same arrangement as the sibling repositories.
lockfile:
name: Lockfile is current
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: astral-sh/setup-uv@v7
- run: uv lock --check

# Ported from scattercode.dev, which has run this arrangement for months.
# tetrak had no vulnerability scanning of any kind before this.
trivy:
Expand All @@ -87,9 +100,10 @@ jobs:

# A source-tree SBOM, which is not the same thing as the per-package
# SBOMs published with a release. This one covers what is committed --
# the site's package-lock.json and the workflow actions -- and is close
# to useless for Python, because pyproject.toml declares ranges rather
# than resolved versions. The documents consumers need are built from
# the site's package-lock.json, the workflow actions and, through
# uv.lock, every resolved Python version including the heavy extras.
# pyproject.toml alone would be close to useless here, because it
# declares ranges. The documents consumers need are still built from
# installed environments in release.yml.
- name: Generate source-tree SBOM
uses: aquasecurity/trivy-action@v0.36.0
Expand Down
23 changes: 16 additions & 7 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,18 @@ never type a number into either renderer.
## Setup

```bash
brew install tesseract poppler # macOS system dependencies
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]' # add extras as needed: [dev,all,armenian] is everything
brew install tesseract poppler uv # macOS system dependencies, and uv
uv sync --extra dev # .venv from uv.lock; add extras as needed: --extra all --extra armenian is everything
source .venv/bin/activate # or prefix each command below with `uv run`
```

`uv.lock` is committed and resolves every extra, so two checkouts get the
same versions. After changing a dependency in `pyproject.toml`, run `uv lock`
and commit the lockfile in the same change; the pre-commit hook and CI both
refuse a stale one. A plain `python3 -m venv` with `pip install -e '.[dev]'`
still works, and is what CI installs the tests with, so the declared ranges
are exercised as well as the lock.

The Claude backend needs `ANTHROPIC_API_KEY` in `.env` at the repo root.

EasyOCR, PaddleOCR and Marker download model weights on first use (~100 MB,
Expand Down Expand Up @@ -346,7 +353,9 @@ here, and the brief's status in `tetrak-product`.

- `ci.yml` — ruff plus `pytest -m "not slow"` on every push and PR, installing
core plus `[dev]` only. The heavy backends are not installed: they take
minutes and every test touching them mocks the dependency.
minutes and every test touching them mocks the dependency. A separate job
runs `uv lock --check`; Trivy scans the lockfile, which is what gives the
Python scan resolved versions rather than ranges.
- `corpus.yml` — `pytest -m slow` (real OCR over the corpus). On merge to
`main` only when `src/`, `tests/`, `evaluation/` or `pyproject.toml`
changed, plus weekly, so engine or dependency drift is still caught.
Expand Down Expand Up @@ -393,9 +402,9 @@ research: the corpus, the engines as measured, routing, results and method,
and the articles. The site's `/ocr/reference/cli/` page is a stub that links to
the guide; the generated API page it used to carry (`tools/generate_api_docs.py`)
was retired in favour of Sphinx's, so the two could not drift. Build the
Sphinx site locally with `pip install -e '.[apidocs]'` and
`sphinx-build -W -b html docs docs/_build/html`; `-W` is what CI runs, so a
warning is a failure.
Sphinx site locally with `uv sync --extra apidocs` and
`uv run sphinx-build -W -b html docs docs/_build/html`; `-W` is what CI runs,
so a warning is a failure.

The Cloudflare Pages project:

Expand Down
11 changes: 8 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,28 @@ which are plain Markdown any tool or person can open.
## Getting set up

```bash
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]' # add extras for the backends you need
brew install tesseract poppler # or apt-get install tesseract-ocr poppler-utils
brew install tesseract poppler uv # or apt-get install tesseract-ocr poppler-utils, and uv from astral.sh
uv sync --extra dev # .venv from the lockfile; add --extra <name> for the backends you need
source .venv/bin/activate # or prefix each command with `uv run`
cd site && npm ci # the documentation site
```

`npm ci` also installs the git hooks (Lefthook): Ruff and the site's linters
before each commit, and the Conventional Commits check on every commit
message. If they are not active, run `lefthook install`.

`uv.lock` is committed. If you change a dependency in `pyproject.toml`, run
`uv lock` and commit the lockfile in the same change; the pre-commit hook and
CI both refuse a stale one.

## The checks

Everything CI runs, runnable by hand:

```bash
ruff check src tests evaluation tools docs
ruff format --check src tests evaluation tools docs
uv lock --check # the lockfile matches pyproject.toml
pytest -m "not slow" # fast; the heavy backends are mocked
pytest -m slow # real OCR over the corpus; minutes
cd site && npm run lint && npm run build && npx playwright test
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,8 +376,8 @@ tests/ unit tests, plus corpus-backed threshold tests marked `slow`
```bash
git clone https://github.com/scattercode/tetrak.git
cd tetrak
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
uv sync --extra dev # .venv from the committed lockfile
source .venv/bin/activate
lefthook install

pytest -m "not slow" # the fast loop
Expand Down
9 changes: 6 additions & 3 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ If you are not using `claude`, nothing else in the package needs this.
```bash
git clone https://github.com/scattercode/tetrak.git
cd tetrak
python3 -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]' # add extras as needed: [dev,all,armenian] is everything
pytest -m "not slow"
uv sync --extra dev # add extras as needed: --extra all --extra armenian is everything
uv run pytest -m "not slow"
```

[uv](https://docs.astral.sh/uv/) creates `.venv` from the committed
`uv.lock`, so every checkout gets the same versions. A plain `python3 -m venv`
followed by `pip install -e '.[dev]'` works too.

`-m "not slow"` skips the tests that read the evaluation corpus and invoke a
real OCR engine; it runs in well under a second. The evaluation corpus and
harness live in `evaluation/` and are not part of the installed package, so
Expand Down
11 changes: 9 additions & 2 deletions lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
# pre-commit runs Ruff on staged Python files and the site's linters when
# site sources are staged; commit-msg enforces Conventional Commits via the
# shared script in .githooks/.
# Ruff must be on PATH (e.g. `brew install ruff` or `pip install ruff`).
# The site lint needs `npm ci` to have been run in site/.
# Ruff must be on PATH (e.g. `brew install ruff` or `pip install ruff`), and
# so must uv (`brew install uv`) for the lockfile check, which runs only when
# pyproject.toml or uv.lock is staged. The site lint needs `npm ci` to have
# been run in site/.

pre-commit:
parallel: true
Expand All @@ -16,6 +18,11 @@ pre-commit:
ruff-format:
glob: "*.py"
run: ruff format --check {staged_files}
# CI runs the same check. A dependency change without `uv lock` leaves a
# lockfile that describes an environment nobody installs.
uv-lock:
glob: "{pyproject.toml,uv.lock}"
run: uv lock --check
# Whole-project rather than per-file: the linters are configured in
# site/package.json with their own file globs, and running them on a
# staged subset would silently skip the config that CI applies.
Expand Down
Loading
Loading