-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathhatch_build.py
50 lines (38 loc) · 1.25 KB
/
hatch_build.py
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
"""Custom build hook for Hatch."""
import pathlib
import subprocess
import sys
from typing import Any
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
class CustomBuilder(BuildHookInterface):
"""Custom build hook for Hatch."""
PLUGIN_NAME = "custom"
def marker(self) -> pathlib.Path:
"""Get the marker file path.
Returns:
The marker file path.
"""
return (
pathlib.Path(self.directory)
/ f".reflex-{self.metadata.version}.pyi_generated"
)
def finalize(
self, version: str, build_data: dict[str, Any], artifact_path: str
) -> None:
"""Finalize the build process.
Args:
version: The version of the package.
build_data: The build data.
artifact_path: The path to the artifact.
"""
if self.marker().exists():
return
if not (pathlib.Path(self.root) / "scripts").exists():
return
for file in (pathlib.Path(self.root) / "reflex").rglob("**/*.pyi"):
file.unlink(missing_ok=True)
subprocess.run(
[sys.executable, "-m", "reflex.utils.pyi_generator"],
check=True,
)
self.marker().touch()