Repository navigation
Expand file tree
/
Copy pathhatch_build.py
More file actions
59 lines (48 loc) · 2.01 KB
/
Copy pathhatch_build.py
File metadata and controls
59 lines (48 loc) · 2.01 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
"""Custom hooks to build wheel file for platforms.
This is hatchling build hook that add Dart Sass executables adapted specified platforms into bdist.
To enable this, you should pass environment variables: ``BUILD_FOR_PLATFORM``
that must be contains in keys of ``RELEASE_TARGET``.
"""
import os
import subprocess
from pathlib import Path
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
RELEASE_TARGET = {
"win_amd64": {"os": "windows", "arch": "x64", "is_musl": False},
"win_arm64": {"os": "windows", "arch": "arm64", "is_musl": False},
"manylinux_2_17_x86_64": {"os": "linux", "arch": "x64", "is_musl": False},
"manylinux_2_17_aarch64": {"os": "linux", "arch": "arm64", "is_musl": False},
"musllinux_1_2_x86_64": {"os": "linux", "arch": "x64", "is_musl": True},
"musllinux_1_2_aarch64": {"os": "linux", "arch": "arm64", "is_musl": True},
}
here = Path(__file__).parent
class CustomHook(BuildHookInterface):
def initialize(self, version, build_data):
if "BUILD_FOR_PLATFORM" not in os.environ:
# Skip hook when env is not passed.
return
if os.environ["BUILD_FOR_PLATFORM"] not in RELEASE_TARGET:
# Skip hook when env is not contained in targets.
# TODO: It should display warnings.
return
platform = os.environ["BUILD_FOR_PLATFORM"]
release = RELEASE_TARGET[platform]
# Mark that bdist includes bineries for platform.
build_data["pure_python"] = False
# Set build tag
py_tag = "py3"
abi_tag = "none"
build_data["tag"] = f"{py_tag}-{abi_tag}-{platform}"
# Fetch Dart Sass executables for platform.
cmd = [
"python",
"-m",
"sass_embedded.dart_sass",
"--clean",
"--os",
release["os"],
"--arch",
release["arch"],
]
cmd.append("--musl" if release["is_musl"] else "--no-musl")
subprocess.run(cmd, cwd=here / "src", check=True)