|
| 1 | +import os |
1 | 2 | import re |
2 | | -from pathlib import Path |
3 | 3 |
|
4 | 4 | from setuptools import setup |
5 | 5 | from wheel.bdist_wheel import bdist_wheel as _bdist_wheel |
6 | 6 |
|
7 | | -ROOT = Path(__file__).parent |
| 7 | +ROOT = os.path.dirname(os.path.abspath(__file__)) |
8 | 8 |
|
9 | 9 |
|
10 | 10 | def generate_sbom(): |
11 | | - version = (ROOT / "VERSION").read_text().strip() |
12 | | - init_text = (ROOT / "src" / "tzdata" / "__init__.py").read_text() |
| 11 | + with open(os.path.join(ROOT, "VERSION")) as f: |
| 12 | + version = f.read().strip() |
| 13 | + with open(os.path.join(ROOT, "src", "tzdata", "__init__.py")) as f: |
| 14 | + init_text = f.read() |
13 | 15 | iana_version = re.search(r'IANA_VERSION\s*=\s*"([^"]+)"', init_text).group(1) |
14 | | - template = (ROOT / "templates" / "sbom.cdx.json.in").read_text() |
| 16 | + with open(os.path.join(ROOT, "templates", "sbom.cdx.json.in")) as f: |
| 17 | + template = f.read() |
15 | 18 | return template.replace("%%PACKAGE_VERSION%%", version).replace( |
16 | 19 | "%%IANA_VERSION%%", iana_version |
17 | 20 | ) |
18 | 21 |
|
19 | 22 |
|
20 | 23 | class bdist_wheel(_bdist_wheel): |
21 | 24 | def write_wheelfile(self, wheelfile_base, *args, **kwargs): |
22 | | - super().write_wheelfile(wheelfile_base, *args, **kwargs) |
23 | | - (Path(wheelfile_base) / "sboms").mkdir(exist_ok=True) |
24 | | - (Path(wheelfile_base) / "sboms" / "sbom.cdx.json").write_text(generate_sbom()) |
| 25 | + super(bdist_wheel, self).write_wheelfile(wheelfile_base, *args, **kwargs) |
| 26 | + sboms_dir = os.path.join(wheelfile_base, "sboms") |
| 27 | + if not os.path.isdir(sboms_dir): |
| 28 | + os.makedirs(sboms_dir) |
| 29 | + with open(os.path.join(sboms_dir, "sbom.cdx.json"), "w") as f: |
| 30 | + f.write(generate_sbom()) |
25 | 31 |
|
26 | 32 |
|
27 | 33 | cmdclass = {"bdist_wheel": bdist_wheel} |
|
0 commit comments