-
Notifications
You must be signed in to change notification settings - Fork 3
/
build_pkg.py
98 lines (75 loc) · 2.41 KB
/
build_pkg.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
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import shutil
import subprocess
import sys
from pathlib import Path
def run_command(command, cwd=None):
result = subprocess.run(command, shell=True, cwd=cwd, check=True)
return result
def npm_install():
print("Running npm install")
run_command("npm install", cwd="bespoke-dataset-viewer")
def copy_with_excludes(source, target, excludes=None):
"""Copy files/directories while excluding specified paths"""
if excludes is None:
excludes = []
if source.is_file():
shutil.copy2(source, target)
print(f"Copied file {source} to {target}")
elif source.is_dir():
if target.exists():
shutil.rmtree(target)
def ignore_patterns(path, names):
return [n for n in names if str(Path(path) / n) in excludes]
shutil.copytree(source, target, ignore=ignore_patterns)
print(f"Copied directory {source} to {target}")
def nextjs_build():
print("Running Next.js build")
run_command("npm run build", cwd="bespoke-dataset-viewer")
print("Copying build artifacts to static folder")
# Source and target directories
source_base = Path("bespoke-dataset-viewer")
target_base = Path("src/bespokelabs/curator/viewer/static")
# Ensure target directory exists
if target_base.exists():
shutil.rmtree(target_base)
target_base.mkdir(parents=True, exist_ok=True)
# Files and directories to copy
files_to_copy = [
".next",
"app",
"components",
"lib",
"public",
"types",
"package.json",
"package-lock.json",
"next.config.ts",
"next-env.d.ts",
"tsconfig.json",
"postcss.config.mjs",
"tailwind.config.ts",
"components.json",
]
# Paths to exclude
exclude_paths = [str(source_base / ".next" / "cache")]
for item in files_to_copy:
source = source_base / item
target = target_base / item
if source.exists():
copy_with_excludes(source, target, exclude_paths)
else:
print(f"Warning: {source} not found")
def run_pytest():
print("Running pytest")
try:
run_command("pytest")
except subprocess.CalledProcessError:
print("Pytest failed. Aborting build.")
sys.exit(1)
def main():
npm_install()
nextjs_build()
run_pytest()
print("Build completed successfully.")
if __name__ == "__main__":
main()