Python Package Build (pybuild)

The pybuild macro builds, validates, and publishes Python distributions using the standard PyPA build frontend and Twine. It is intended for packages using a pyproject.toml and a PEP 517 build backend, not for arbitrary Python scripts.

Dependencies

The Python build package is required to create distributions; twine is required for check() and publish(). The build backend and its build requirements must also be available. By default, the build frontend creates an isolated build environment and installs the backend’s declared requirements.

Features

  • building one wheel and one source distribution (sdist)

  • optional PEP 517 build isolation (enabled by default)

  • deriving package name and version from the generated wheel metadata

  • strict Twine validation and separate publishing

  • version badge, build metrics, command logs, and an RST build report

  • run-bound distribution artifacts, including across commands when transferred

Typical usage

from cikit.macros import pybuild

distributions = pybuild.build(env)
pybuild.check(env)
pybuild.badge(env)
pybuild.write_rst(env)

build() registers the wheel and sdist as BUILD artifacts and stores package_name, package_version, build_time, build_isolation, wheel_files, and sdist_files in the current run data. The build and Twine-check logs are registered separately. A failed strict Twine check raises CiRecoverableError, allowing a CI workflow to preserve the failed status and still create a badge and report.

Publishing is deliberately separate from building:

pybuild.publish(env, build_run="pybuild")

publish() uploads distributions registered by the given build run. It does not rebuild or revalidate them. Twine uses its usual repository and credentials configuration, including TWINE_USERNAME and TWINE_PASSWORD. For separate CI jobs, the distributions and the cikit artifact registry must be transferred from the build job. The built-in commands are cikit pybuild and cikit pypublish.

API options

build() returns a list of registered distribution artifacts. Its optional arguments are project_dir, isolation, and timeout. The check() and publish() functions also accept timeout. To select a configured Twine repository explicitly:

pybuild.publish(env, build_run="pybuild", repository="testpypi")

badge() accepts name and label; write_rst() accepts name and report_title.