Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import os
import re

from setuptools import setup
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel

ROOT = os.path.dirname(os.path.abspath(__file__))


def generate_sbom():
with open(os.path.join(ROOT, "VERSION")) as f:
version = f.read().strip()
with open(os.path.join(ROOT, "src", "tzdata", "__init__.py")) as f:
init_text = f.read()
iana_version = re.search(r'IANA_VERSION\s*=\s*"([^"]+)"', init_text).group(1)
with open(os.path.join(ROOT, "templates", "sbom.cdx.json.in")) as f:
template = f.read()
return template.replace("%%PACKAGE_VERSION%%", version).replace(
"%%IANA_VERSION%%", iana_version
)


class bdist_wheel(_bdist_wheel):
def write_wheelfile(self, wheelfile_base, *args, **kwargs):
_bdist_wheel.write_wheelfile(self, wheelfile_base, *args, **kwargs)
sboms_dir = os.path.join(wheelfile_base, "sboms")
if not os.path.isdir(sboms_dir):
os.makedirs(sboms_dir)
with open(os.path.join(sboms_dir, "sbom.cdx.json"), "w") as f:
f.write(generate_sbom())


cmdclass = {"bdist_wheel": bdist_wheel}
setup(cmdclass=cmdclass)
38 changes: 38 additions & 0 deletions templates/sbom.cdx.json.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"$schema": "http://cyclonedx.org/schema/bom-1.7.schema.json",
"version": 1,
"bomFormat": "CycloneDX",
"specVersion": "1.7",
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Funnily enough, many scanners don't recognize later SBOM versions. If you're not using new features it's better to use a lower version (like 1.4).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, that's not ideal, IIRC since it has been a few days I think there was something only in the newer ones.

"metadata": {
"component": {
"bom-ref": "pkg:pypi/tzdata@%%PACKAGE_VERSION%%",
"name": "tzdata",
"version": "%%PACKAGE_VERSION%%",
"purl": "pkg:pypi/tzdata@%%PACKAGE_VERSION%%",
"type": "library",
"components": [
{
"bom-ref": "https://www.iana.org/time-zones",
"name": "tz",
"version": "%%IANA_VERSION%%",
"type": "data",
"data": [
{
"type": "dataset",
"name": "IANA Time Zone Database",
"description": "zic-compiled TZif timezone files"
}
],
"licenses": [
{
"license": {
"name": "tz database license",
"url": "https://data.iana.org/time-zones/tz-link.html"
}
}
]
}
]
}
}
}
Loading