Skip to content

Commit 6fa1e33

Browse files
Use os instead :-(
1 parent 191791a commit 6fa1e33

1 file changed

Lines changed: 14 additions & 8 deletions

File tree

setup.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,33 @@
1+
import os
12
import re
2-
from pathlib import Path
33

44
from setuptools import setup
55
from wheel.bdist_wheel import bdist_wheel as _bdist_wheel
66

7-
ROOT = Path(__file__).parent
7+
ROOT = os.path.dirname(os.path.abspath(__file__))
88

99

1010
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()
1315
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()
1518
return template.replace("%%PACKAGE_VERSION%%", version).replace(
1619
"%%IANA_VERSION%%", iana_version
1720
)
1821

1922

2023
class bdist_wheel(_bdist_wheel):
2124
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())
2531

2632

2733
cmdclass = {"bdist_wheel": bdist_wheel}

0 commit comments

Comments
 (0)