Skip to content

✨ feat: add PEP 770 SBOM build hook - #1

Merged
gaborbernat merged 4 commits into
mainfrom
add-sbom-hook
Nov 7, 2026
Merged

gaborbernat merged 4 commits into
mainfrom
add-sbom-hook

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

This adds hatch-pep770, a hatchling build hook that writes a CycloneDX 1.6 SBOM into each wheel at .dist-info/sboms/<name>.cdx.json, as PEP 770 describes. It is the generator from pypa/virtualenv's hatch_build.py, made reusable so the other hatchling projects can enable it with one table in pyproject.toml.

The SBOM records the project from its core metadata, the declared runtime dependencies, any wheels the project bundles as data files (with hashes, files and vendored packages), and the build toolchain. Nothing about the build machine goes in, and the timestamp comes from SOURCE_DATE_EPOCH, so rebuilding a tag reproduces the wheel byte for byte.

The virtualenv-specific parts became options (supplier, repository, default-branch, bundled-wheels) plus a bundled_wheel_properties method a custom build hook can override. Built through this package, virtualenv's wheel SBOM matches its current one except for the build-script hash, the serial number, and hatch-pep770 showing up among the build tools. The SPDX rendering and the validator ship as hatch-pep770 spdx and hatch-pep770 validate; the latter needs the validate extra.

The floor is Python 3.9 because virtualenv still builds there. On 3.9 hatchling stops at 1.27, which cannot embed an SBOM, so the hook prints a warning and skips it.

Port the CycloneDX SBOM generator from pypa/virtualenv's hatch_build.py
into a reusable hatchling plugin, with the project-specific parts
(supplier, repository, bundled wheels) moved into hook options and a
subclass method for per-wheel properties. The SPDX rendering and the
validator ship as the hatch-pep770 spdx and validate commands.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

@gaborbernat
gaborbernat merged commit 02b2178 into main Nov 7, 2026
25 checks passed
@gaborbernat
gaborbernat deleted the add-sbom-hook branch November 7, 2026 02:49
@gaborbernat
gaborbernat restored the add-sbom-hook branch November 7, 2026 02:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants