Skip to content
BETAGuardrails are in beta. The library, the configuration format and the CLI command can still change.

Guardrails / python

Build backend is declared

python/build-backend-declared@v1

A packaged project names its build backend in [build-system], so it builds the same way everywhere.

Idpython/build-backend-declared
Versionv1
Categorypython
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectspython

Collectors

This guardrail gathers nothing itself. It depends on the collectors below, which the CLI runs once per build before any check, and reads what they found out of GUARDRAIL_FACTS. A collector that collects nothing skips this guardrail rather than failing it.

CollectorGathersInputs it is given
pythonThe Python project in the project directory: its manifest and build backend, the Python version it asks for, the requirements it declares and which of them are pinned, and the lock files committed beside them.projectDir

The inputs above are this guardrail's own, passed straight through. Configuring one in buildnote.json changes what is collected, and two guardrails configured the same way share the one collection.

Configuration

json
{
  "guardrails": {
      "failOn": "error",
      "comment": true,
      "checks": [
          {
              "use": "python/build-backend-declared@v1",
              "severity": "warning",
              "with": {
                  "projectDir": "."
              },
              "exemptions": []
          }
      ]
  }
}

Inputs

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR

How to fix

Declare the backend in pyproject.toml:

toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

With no [build-system] table, PEP 517 falls back to legacy setuptools with whatever version the environment has, so the wheel a release builds depends on the machine that built it.

More in python

  • python/lockfile-committed. The project commits a lock file, so an install of the same commit resolves the same versions.
  • python/single-lockfile. The project commits at most one lock file, so two installers do not each believe they own the environment.
  • python/version-declared. The project declares the Python version it is built and run against, and that version is no older than the configured floor.

All 4 python guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412