-
Notifications
You must be signed in to change notification settings - Fork 468
Expand file tree
/
Copy pathhatch_build.py
More file actions
33 lines (27 loc) · 1009 Bytes
/
hatch_build.py
File metadata and controls
33 lines (27 loc) · 1009 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
import tarfile
import zipfile
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
DAT_MESSAGE = """
======
Package should contain multiple .dat files.
* Make sure you've imported the CLDR data; `make import-cldr`.
------
To skip this check, set the environment variable BABEL_NO_CHECK_BUILD=1
======
""".strip()
def check_babel_artifact(artifact_path: str):
if artifact_path.endswith(".whl"):
with zipfile.ZipFile(artifact_path) as whl:
filelist = whl.namelist()
elif artifact_path.endswith(".tar.gz"):
with tarfile.open(artifact_path) as tar:
filelist = tar.getnames()
if len([f.endswith(".dat") for f in filelist]) < 10:
raise ValueError(DAT_MESSAGE)
class CustomBuildHook(BuildHookInterface):
def finalize(self, version, build_data, artifact_path):
if version == "editable":
return
if not os.environ.get("BABEL_NO_CHECK_BUILD"):
check_babel_artifact(artifact_path)