Skip to content

Guardrails / python

Python version is declared ​

python/version-declared@v1

The project declares the Python version it is built and run against, and that version is no older than the configured floor.

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

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

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 inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "python/version-declared@v1",
              "severity": "warning",
              "with": {
                  "projectDir": ".",
                  "minVersion": "3.9"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
projectDirDirectory holding the project, relative to the directory the CLI runs in..GUARDRAIL_INPUT_PROJECTDIR
minVersionOldest Python version accepted. A declared version below this is a violation.3.9GUARDRAIL_INPUT_MINVERSION

How to fix ​

Declare the interpreter where the project already describes itself: requires-python = ">=3.12" under [project] in pyproject.toml, or a .python-version file naming the exact release. Without one, the interpreter is whatever the runner happens to have, so a syntax or standard library difference shows up in CI instead of on the laptop where it was introduced.

More in python ​

All 4 python guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412