Skip to main content

codeality-py

Structural linter and config scaffolder for Python: atomic files, placement, size caps, no inline SQL. Brings the same discipline as @syntopica/eslint-config and cargo-baseline to Python projects.

Install

uv add --dev syntopica-codeality-py

Usage

codeality-py init [--check|--apply|--force]  # scaffold ruff, mypy, deptry,
                                            # pytest, coverage and CI config
codeality-py check [PATH...]                 # run the structural rules
codeality-py gate                            # run the whole quality chain
codeality-py baseline create|update|check    # track migration debt
codeality-py affected [--base REF] [-- ...]  # run only the tests a change reaches
codeality-py test-audit [--json]             # find what makes the suite costly

init never overwrites: it merges into existing configuration, or reports a conflict. check never writes. gate fails when a required tool is absent rather than skipping it.

Inner loop: affected

codeality-py affected runs pytest on the test files that import, directly or transitively, a Python file changed since --base (default HEAD: committed since, staged, unstaged and untracked). It builds a static import graph with ast, so there is no state to keep, no first full run and no new dependency. pytest-testmon was rejected for the opposite reasons: it keeps a .testmondata database, traces coverage on every run and needs a full run first. --plan prints the pytest command without running it, and everything after -- goes to pytest. When addopts collects coverage, --no-cov is added, because a subset would fail the coverage threshold.

The whole suite runs when a change can reach every test without an import: a conftest.py, pytest.ini, tox.ini, setup.cfg, pyproject.toml, a lockfile, an .env* file, or a deleted module. When no test reaches the changed files, the command says they are untested and never reports a pass. Every run ends by saying the full gate has not run. Git runs without GIT_DIR, GIT_WORK_TREE and GIT_INDEX_FILE, so it works inside a hook of a linked worktree.

Dynamic imports are followed only for a literal importlib.import_module("x") or __import__("x"). Declare the rest in codeality-py.toml:

[affected]
widen = ["fixtures/**"]          # a change here runs the whole suite

[[affected.map]]
when = "migrations/*.sql"        # a non-Python file...
to = ["src/app/db"]              # ...counts as a change to these paths

Suite audit: test-audit

Findings exit 1; observations never change the exit code. Both print their evidence, and --json emits schemaVersion, findings and observations.

Name Kind Reported when
coverage-in-addopts finding addopts has --cov*, so every run pays for tracing.
missing-testpaths finding No testpaths and a bare run walks 100 or more directories with no test.
real-sleep-in-tests finding A literal time.sleep(n) or asyncio.sleep(n) of 0.5s or more in a test.
xdist-candidate observation 40 or more test files and no -n in addopts.
hook-runs-full-gate observation A lefthook, husky or .githooks hook runs pytest or codeality-py gate.

Rules

Code Rule Enforces
BPY000 parse-error A file that fails to parse is a finding, never a silent skip.
BPY001 one-primary-unit Exactly one primary declaration per ordinary module.
BPY002 file-matches-unit File name is the snake_case of its primary declaration.
BPY003 no-grab-bag-names No utils, helpers, misc or common in any path segment.
BPY004 max-file-lines Code-line cap per file; tests get their own, looser cap.
BPY005 barrel-only-init __init__.py holds imports, __all__ and nothing else.
BPY006 no-inline-sql SQL lives in resource files, not in string literals.

Suite time budget

# codeality-py.toml
test-budget-seconds = 300

Past the budget a passing suite is a finding: the pytest stage reports over-budget, exits 1, and its detail carries the slowest tests. The procedure - profile, make the unit under test cheaper, parallelise, serialise what must stay shared - is in docs/standards/testing.md.

The budget is tuned to the machine the suite is developed on. A slower environment, such as a CI runner, sets its own for the run instead of raising the committed number for everyone:

# .github/workflows/quality.yml
env:
  CODEALITY_PY_TEST_BUDGET_SECONDS: '600'

When CODEALITY_PY_TEST_BUDGET_SECONDS is set it replaces test-budget-seconds; unset or empty, it changes nothing. A value that is not a positive integer is a configuration error (exit 2), never silently ignored. The pytest stage names the budget it was held to and where it came from - budget 600s from CODEALITY_PY_TEST_BUDGET_SECONDS - in its text line, its detail, and the budget_seconds and budget_source fields of gate --json.

Exit codes

Code Meaning
0 All blocking checks passed.
1 Policy findings.
2 Invalid usage or invalid configuration.
3 Infrastructure failure: a required tool is missing or unusable.

License

MIT

Metadata

Release files for syntopica-codeality-py 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for syntopica-codeality-py 0.3.0
File Size Uploaded Provenance Actions
syntopica_codeality_py-0.3.0.tar.gz 164.8 kB With provenance Details for syntopica_codeality_py-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for syntopica-codeality-py 0.3.0
File Interpreter ABI Platform Actions
syntopica_codeality_py-0.3.0-py3-none-any.whl Python 3 none any Details for syntopica_codeality_py-0.3.0-py3-none-any.whl

Total release size: 310.5 kB

Release files / syntopica_codeality_py-0.3.0.tar.gz

Download URL syntopica_codeality_py-0.3.0.tar.gz
Size 164.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f495f62086c464a80d2b89f0840b3197ecd61b5af68dc4b6e71a6b12378011fb
BLAKE2b-256 checksum
How to use checksums
3e69206d1463062d43ca5a199db437ef75af6ffd4a1aad8dc8e1771ee3febd0a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / syntopica_codeality_py-0.3.0-py3-none-any.whl

Download URL syntopica_codeality_py-0.3.0-py3-none-any.whl
Size 145.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9ae4a32eb4c6d7579eef10879e3da8396c3b3b85c4d3692fe9c3070919837b9f
BLAKE2b-256 checksum
How to use checksums
3e7873081e7a17fbd8eaa64aee3a7322d8bc7ff896aed5873353a343caf9aac4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for syntopica-codeality-py 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for syntopica_codeality_py-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page