Contributing

Setup

$ git clone https://github.com/wzjoriv/stubpy
$ cd stubpy
$ pip install -e ".[dev]"

Developer commands

scripts/dev.py wraps the day-to-day tasks:

$ python scripts/dev.py --help

Command

What it does

dev.py check

Lint, tests, docs without warnings and the project’s own checks; non-zero when one fails.

dev.py test [tier]

Runs a test tier (default quick, the whole suite, quiet); memory-capped and logged. cov adds a coverage report.

dev.py docs [--open] [--clean]

Builds the HTML docs.

dev.py stubpy self-stub

Stubs the stubpy package with and without importing it; non-zero when a file fails or a stub does not parse.

dev.py stubpy corpus

Regenerates the stubs of the pure-Python test corpus in corpora/ with this checkout and lists the stubs whose text changed.

dev.py stubpy raster

Stubs the compiled test corpus in corpora/, compiled modules included; non-zero when a file fails.

dev.py corpora rasterlib build [--clean]

Builds the native modules of the compiled corpus in place, single-threaded.

Run dev.py check before opening a pull request.

Lint

The project uses ruff (line length 110, target Python 3.10).

$ ruff check stubpy scripts tests

Tests

tests/ mirrors the package: tests/analysis/, tests/emit/, tests/resolve/, tests/config/, tests/core/, tests/cli/, tests/compiled/, plus tests/integration/ and a few top-level files (test_hint.py, test_merge.py). Put a new test next to the code it covers.

$ python scripts/dev.py test
$ pytest tests/emit -q

Generated stubs

tests/integration/test_stubs_typecheck.py generates the stubs of corpora/drawlib (with and without importing it) and of corpora/rasterlib (when its extensions are built) and runs mypy on them, for the current Python and for 3.10. It skips without mypy (pip install mypy) and runs in CI in the full matrix on Python 3.12. A new error fails the test: fix the emitter, or, when the source itself has the problem (the corpora keep a few deliberate signature clashes), add its (error code, file) to KNOWN in the test with the reason.

Package boundaries

Two tests enforce the structure:

  • tests/test_package_boundaries.py: a module or sub-package whose name starts with _ belongs to its parent package only; analysis and resolve never import emit, core.pipeline or core.api; emit never imports core.pipeline or core.api.

  • tests/test_package_exports.py: the names in stubpy.__all__ match the public API.

See Architecture for the layout. Docstrings use the NumPy style for public API; one line is enough for simple internals.

Docs

The docs use Sphinx with Furo and MyST. The build treats warnings as errors:

$ pip install -e ".[docs]"
$ python scripts/dev.py docs --open
$ sphinx-build -b html -W --keep-going docs docs/_build/html

Every example in the guides is real stubpy output. When behaviour changes, rerun the example and update the page. Pushes to main publish the dev docs and releases publish stable.