Code Style
Code conventions for the barangay package: ruff formatting, type hints, testing, and an AGENTS.md summary.
barangay keeps its style rules minimal and machine-enforced — ruff handles formatting and linting, ty handles types, and pre-commit runs both before every commit. This page is a quick reference to the conventions summarized in AGENTS.md.
Formatting and linting
ruffdefault formatting — there is no custom config; whateveruv run ruff formatproduces is canonical.- Lint with
uv run ruff check --fix --exit-non-zero-on-fix --ignore E741—E741(ambiguous variable name likel) is the only standing ignore, to keep the0/1placeholders used by therphicmsgbconvention readable. - Follow existing import ordering in neighboring files; do not introduce a new ordering style.
Type hints
- Type hints are required on all public code in
barangay/. tyis the type checker (uv run ty check) — not mypy. There is no mypy config in this project.parsers/andtests/are excluded fromty(pyproject.toml[tool.ty.src]), so exploratory parsing scripts and tests don’t need to be fully typed.- Python 3.13+ syntax is allowed and preferred — use
X | Yunions (str | None, notOptional[str]), and modern typing throughout.
Tests
- Location:
tests/, namedtest_*.py. - Local dev:
uv run pytest(sequential). - Pre-commit / CI:
uv run pytest -n auto(parallel via pytest-xdist). - Coverage:
uv run pytest --cov.
Conventions worth knowing
rphicmsgbindicator — a 9-character documentation convention for which PSGC levels a record touches (region ·province ·hUC ·iCC ·component city ·municipality ·sub-municipality ·gSGA ·barangay). See Hierarchy indicator.- Deprecated APIs stay importable but are not used in new code. The dict-based
search(), theBARANGAY/BARANGAY_EXTENDED/BARANGAY_FLATaliases, andBarangayModelare present for compatibility — new work usessearch_fuzzyand theDatabaseviews. - Data version comes from
barangay/data/CURRENT_VERSION, never hardcoded. Module-level attributesbarangay.current,barangay.as_of, andbarangay.available_datesexpose it at runtime.
Full reference
The canonical, always-current source for these conventions is AGENTS.md at the repo root — repository structure, tech stack, commands, branching strategy, and gotchas. When this page and AGENTS.md disagree, AGENTS.md wins.
Comments