-
Notifications
You must be signed in to change notification settings - Fork 324
/
build.py
65 lines (51 loc) · 1.73 KB
/
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import subprocess
import shutil
import toml
import sys
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="ell-studio")
def npm_build():
print("Running npm build")
run_command("npm run build", cwd="ell-studio")
print("Copying static files")
source_dir = os.path.join("ell-studio", "build")
target_dir = os.path.join("src", "ell", "studio", "static")
shutil.rmtree(target_dir, ignore_errors=True)
shutil.copytree(source_dir, target_dir)
print(f"Copied static files from {source_dir} to {target_dir}")
def get_ell_version():
pyproject_path = "pyproject.toml"
pyproject_data = toml.load(pyproject_path)
return pyproject_data["tool"]["poetry"]["version"]
def run_pytest():
print("Running pytest")
try:
run_command("pytest", cwd="tests")
except subprocess.CalledProcessError:
print("Pytest failed. Aborting build.")
sys.exit(1)
def run_all_examples():
print("Running all examples")
try:
run_command("python run_all_examples.py -w 16", cwd="tests")
except subprocess.CalledProcessError:
print("Some examples failed. Please review the output above.")
user_input = input("Do you want to continue with the build? (y/n): ").lower()
if user_input != 'y':
print("Aborting build.")
sys.exit(1)
def main():
ell_version = get_ell_version()
os.environ['REACT_APP_ELL_VERSION'] = ell_version
npm_install()
npm_build()
run_pytest()
run_all_examples()
print("Build completed successfully.")
if __name__ == "__main__":
main()