Contributing#
Thanks for helping. Bug reports, fixes, docs and features are all welcome; for anything larger than a small fix, please open an issue first so we can agree on the approach.
Setup and checks#
just sync # install dependencies
just lint # ruff, ruff format, mypy (strict)
just test # pytest in parallel, with the coverage gate
CI runs the same checks on every pull request (the aggregate ci-required job passes only when
all of them do, and is the single check meant for branch protection): lint and types, the
documentation build, the tests on Linux, macOS and Windows with Python 3.11 and 3.14, the tests
against the lowest dependency versions that pyproject.toml allows, and a build check
(twine check, clean-environment import).
Testing#
Tests mirror the source: the tests of
src/graftkit/_core/skills/resolve.pyare intests/_core/skills/test_resolve.py. Checks of the whole repository (docstrings, the API reference, the agent snapshots, the tests the requirements name) are at the top oftests/. A command module (commands/) only declares and renders, so its tests run it throughgraftkit.testing.runin its workflow’s test module:commands/org.pyis tested intests/_core/workflows/test_org.py.GitHub and git are faked.
graftkit.testing.FakeGitHubholds releases in memory andFakeGitholds clones; pass them asrun(..., github=..., git=...). Every test is offline unless it passes one:OfflineFetcherandOfflineGit(intests/builders.py, with the shared builders) fail it. The realghandgitcalls are tested intests/_core/test_github.pyandtests/_core/test_git.py, against local repositories, withgh’s answers faked in the test.Run commands the way the CLI does:
graftkit.testing.run(or the launcher’srun_here), never a hand-built app, so a test exercises the same path a user does.Scenarios run the installed package.
tests/scenarios/builds the wheel, installs it in a new environment, and runs the realgraftkitin each place it is used (outside a root, a root, a subfolder, an extension root, an older pin, the clones folder).gh,uvanduvxare the offline stand-ins intests/scenarios/fake_tools/, installed as real programs. Add a row to its table when a command’s behaviour depends on where it runs.Every test runs isolated: the
graftkit_rootfixture keeps the developer’s root, user config, settings variables and cache out.
The agent documents#
tests/snapshots/ pins the two documents agents read: describe --json and the generated
graftkit skill. When a change to either is intended, regenerate them with
UPDATE_SNAPSHOTS=1 uv run pytest tests/test_agent_documents.py, review the diff, and raise
DESCRIBE_FORMAT_VERSION if a field of describe --json changed meaning or was removed.
Where things are#
docs/requirements.md: what the project must do and the conditions it works under, each requirement with the test that verifies it. A change that alters a requirement updates it in the same pull request.
docs/design.md: how it works, the module map, decisions, and where to extend.
src/: the package;tests/: the tests, including the docstring and API-reference checks;docs/: the Sphinx documentation, withdocs/api.rstlisting the public API.
Design rules#
Every change, a feature as much as a refactor, meets these five requirements:
Root cause. Ask what makes the problem exist, then restructure it. Never wrap, shim or layer an abstraction around a symptom.
Lean. Delete, don’t deprecate. No backwards-compatibility branches, dead code, or options kept “just in case”; an option that only ever takes one value becomes a constant.
Single source of truth. No logic or constant lives in two places; consumers derive. If two artifacts must agree, derive one from the other, or add a test that checks they match.
Reuse without speculation. Factor out logic used more than once. Don’t extract single-use code, and don’t add extension points nothing uses yet.
Docs move with the code. Docstrings, the README,
docs/andCHANGELOG.md(under[Unreleased]) are correct in the same pull request; a deliberate trade-off is recorded where it is made.
Code style
Native first: use the standard library or a dependency already in use before writing it.
Simple, but production-like: no async or threads without a measured need. Validate what external systems return, fail loudly, and never let a partial result pass as complete.
Pydantic for data, never dataclasses: value objects subclass
FrozenModel(frozen, unknown fields rejected) and change through its validatedreplaced(). Plain classes hold behaviour only.Precise types:
mypy --stricton everything.Anyonly for genuinely dynamic values,objectfor values passed through,Literalaliases declared once, andcastas a last resort: narrow the type at its source instead.One name per concept across modules, files and commands; no
utils.py.
graftkit’s own rules
Never print or log credentials.
Follow the core’s own layout and standard. Declarations in
commands/, logic inworkflows/; every core command passes the same conformance checks as an extension (tests/_core/test_conformance.py).Pass dependencies in. Commands get everything through
Context(root, settings, GitHub, publisher); tests pass fakes rather than patching module globals.The public API is a promise. It is what
docs/api.rstlists; changing it is a changelog entry, and breaking it bumps the minor version.
Testing: a behaviour change comes with a test that pins it, in the same commit. Test your
code, not its dependencies. Run what you touched locally (just lint, the tests for that area);
just test runs the whole suite in parallel with the coverage gate, as CI does.
Docstrings and comments#
NumPy style, with no types: the signature’s annotations are the single source of truth. ruff’s
D rules (numpy convention) check the section format, and tests/test_docstrings.py (an AST
check, no extra dependency) checks the rest, including the scaffold templates, so
extension new can never generate code that breaks the rules.
Public and private. A name is private when it starts with _, lives in a _-prefixed
module (everything under graftkit._core), is nested in a function, or belongs to a private
class. Names re-exported in graftkit.__all__ or graftkit.testing.__all__ are public wherever
they are defined. Dunder methods have no docstring; a constructor’s parameters go in the class’s
Parameters section.
Private functions and classes get one line: imperative mood for a function, a noun phrase for a class, ending with a period, at most 100 characters, with no sections. Something obscure that does not fit gets a one-line comment above the definition; everything else is left out.
# Identifiers come from a job parameter, so each part is quoted, never interpolated.
def _quote(identifier: str) -> str:
"""Quote an identifier for use in a query."""
Public functions get a summary, an optional description of at most 3 lines, then, in this order and only when they apply:
Parameters: each parameter in signature order (
self/clsexcluded): the bare name, then an indented description of at most 2 lines. State the default when it is not obvious.Returns (or Yields for a generator): prose of at most 2 lines, with no type line.
Raises: each exception class, then when it is raised.
Public classes get a summary, an optional short description, then Parameters (only for a
class with its own __init__), Attributes, Methods (each public method with a one-line
description), and Raises last. On a pydantic model, Attributes holds only ClassVars and
properties: every field, public or private, is described in Field(description=...), never
in the docstring. A property’s docstring is a one-line noun phrase.
Modules each have a docstring: a one-line summary, then at most 2 lines.
Comments are one line, only for something obscure: a non-obvious constraint, a platform or
data quirk, verified external behaviour, or why unusual code is necessary. A comment that
restates the code is deleted, and a longer explanation is cut to its essential line, not moved.
Tool directives (# noqa, # type: ...) do not count.
Tests have a module docstring and follow the length limits, but not the section rules.
Documentation#
The API reference is generated with Sphinx from the docstrings
and type annotations: numpydoc renders the NumPy-style sections in the pydata-sphinx-theme.
The README, the guides, docs/requirements.md, docs/design.md, the changelog and this guide
are included as pages (the toctree in docs/index.md). The site is published to GitHub Pages
on every push to main.
Preview with
just docs(live reload).just docs-buildbuilds it the way CI does: warnings are errors.Adding a public name: list it in
docs/api.rstunder the right heading.tests/test_api_reference.pyfails if a name in__all__is missing.Types are never written in docstrings;
docs/conf.pyadds them to the rendered parameter lists from the annotations.The Sphinx packages live in the separate
docsdependency group, so they never affect the runtime dependencies.
Pull requests#
Fork the repository (or branch, if you are a maintainer) and branch off
mainusingfeature/…,fix/…,docs/…orchore/….Open a pull request against
main. Branches are merged by squash, so the pull request title becomes the commit message: make it a short imperative summary.A code owner must approve before merging (
.github/CODEOWNERS); other reviews are welcome but do not satisfy the merge rule. An author cannot approve their own pull request, so a code owner should not open the pull request they are meant to approve.
Releasing#
Releases are tags on main, published to PyPI. Tags matching v* are protected: they
cannot be moved or deleted except by organisation admins, so check before you tag, and never
reuse a version.
In a pull request, bump
versioninpyproject.toml, runuv lock(CI uses--locked), and inCHANGELOG.mdmove the[Unreleased]entries under the new version with its date. Merge it.Dry-run the release: Actions > Release > Run workflow, on
main. It performs the same checks and build as a real release but publishes nothing (ticktestpypito also upload the build to TestPyPI, once per version). Fix anything it reports; tags cannot be undone, so do not skip this.A maintainer tags the merge commit and pushes the tag:
git switch main && git pull git tag -a vX.Y.Z -m "vX.Y.Z" git push origin vX.Y.Z
The
Releaseworkflow checks that the tag is onmainand equals thepyproject.tomlversion, builds the package, and publishes a GitHub Release (that version’sCHANGELOG.mdsection as the notes, wheel and sdist attached; it fails if the changelog has no section for the version). The PyPI upload then waits for a reviewer to approve thepypienvironment (Actions run > Review deployments).Consumers bump their pin to the new version.
How PyPI publishing is configured#
The Release workflow publishes with PyPI trusted publishing (GitHub’s OIDC identity), so no
token or secret is stored anywhere. It relies on two settings outside this repository’s code:
A trusted publisher on the PyPI project: owner
Northbridge-Capital, repositorygraftkit, workflowrelease.yml, environmentpypi.A GitHub environment named
pypion this repository (managed in the infrastructure repo’s Terraform) with a required reviewer, limited tomainandv*tags.
The testpypi dry run uploads to test.pypi.org, which is a separate site with separate accounts;
it needs its own trusted publisher with the same values (not set up yet).
PyPI files are immutable: a version can be uploaded exactly once. If the publish step fails before uploading (for example a misconfigured publisher), fix the setting and re-run only the failed job; no new version is needed. If a bad release does get uploaded, yank it and cut a new version.