forked from yt-dlp/ejs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhatch_build.py
More file actions
executable file
·79 lines (61 loc) · 2.19 KB
/
hatch_build.py
File metadata and controls
executable file
·79 lines (61 loc) · 2.19 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/env python
import os
import shutil
import subprocess
try:
from hatchling.builders.hooks.plugin.interface import BuildHookInterface
except ImportError:
BuildHookInterface = object
class CustomBuildHook(BuildHookInterface):
def initialize(self, version, build_data):
name, cmds, env = build_bundle_cmds()
if cmds is None:
raise RuntimeError(
"One of 'pnpm', 'deno', 'bun', or 'npm' could not be found. "
"Please install one of them to proceed with the build."
)
print(f"Building with {name}...")
for cmd in cmds:
subprocess.run(cmd, env=env, check=True)
build_data["force_include"].update(
{
"dist/yt.solver.core.min.js": "yt_dlp_ejs/yt/solver/core.min.js",
"dist/yt.solver.lib.min.js": "yt_dlp_ejs/yt/solver/lib.min.js",
}
)
def clean(self, versions):
shutil.rmtree("node_modules", ignore_errors=True)
def build_bundle_cmds():
env = os.environ.copy()
if pnpm := shutil.which("pnpm"):
name = "pnpm"
install = [pnpm, "install", "--frozen-lockfile"]
bundle = [pnpm, "run", "bundle"]
elif deno := shutil.which("deno"):
name = "deno"
env["DENO_NO_UPDATE_CHECK"] = "1"
install = [deno, "install", "--frozen"]
bundle = [deno, "task", "bundle"]
elif bun := shutil.which("bun"):
name = "bun"
install = [bun, "install", "--frozen-lockfile"]
bundle = [bun, "--bun", "run", "bundle"]
elif npm := shutil.which("npm"):
name = "npm (node)"
install = [npm, "ci"]
bundle = [npm, "run", "bundle"]
else:
return None, None, None
return name, [install, bundle], env
if __name__ == "__main__":
import sys
name, cmds, env = build_bundle_cmds()
if cmds is None:
print("ERROR: No suitable JavaScript runtime found", file=sys.stderr)
sys.exit(128)
print(f"Bundling using {name}...", file=sys.stderr)
try:
for cmd in cmds:
subprocess.check_call(cmd, env=env)
except subprocess.CalledProcessError as error:
sys.exit(error.returncode)