A Python ship
Ruff keeps lookout and mends the canvas (linting and formatting), with mypy standing behind the types profile, a watch of its own.
Before ye sail: ruff and mypy on PATH, along with yer project's rules and type-checking configuration. Activate yer virtual environment, or have mise, the quartermaster, provide the tools.
Download python-project.pkl and save it as hk.pkl, the charts yer ship sails by.
The charts
/// Ruff linting and formatting, with optional mypy checks.
amends "package://github.com/jdx/hk/releases/download/v2.4.0/hk@2.4.0#/Config.pkl"
import "package://github.com/jdx/hk/releases/download/v2.4.0/hk@2.4.0#/Builtins.pkl"
steps {
["ruff"] = Builtins.ruff
["ruff-format"] = (Builtins.ruff_format) {
depends = "ruff"
}
["mypy"] = (Builtins.mypy) {
profiles = List("types")
}
}Take her out
hk validate
hk check --all --plan
hk check --all
hk check --all --profile types
hk fixRuff's formatter waits for Ruff's lint fixes before it takes up the canvas. mypy runs only when types is enabled; until then its watch stays off duty. Mark this well: the profile must be enabled for the hk invocation itself; setting HK_PROFILE in a hook's child-command environment does not select it.
Refit her for yer own ship
If ye'd rather have Black mend the canvas, replace the ruff-format entry with Builtins.black. Choose one primary formatter, one master sailmaker, to avoid formatting passes that fight each other.
For a push hook that always brings mypy along, add a pre-push hook that copies the top-level steps and clears mypy's profile requirement there:
hooks {
["pre-push"] {
steps = (module.steps) {
["mypy"] = (Builtins.mypy) {
profiles = List()
}
}
}
}Add this block after the top-level steps block. module.steps refers to those shared steps, the same crew. Locally and in CI, hk check --all --profile types includes type checking without a separate hook.
