Skip to content

Commit

Permalink
Fixups and cleanup for build script.
Browse files Browse the repository at this point in the history
* No need to copy already symlinked README.
* Help Windows find pnpm.
  Ref: https://stackoverflow.com/questions/3022013/windows-cant-find-the-file-on-subprocess-call
  • Loading branch information
dokterbob committed Oct 10, 2024
1 parent 48156b9 commit 83084d5
Showing 1 changed file with 27 additions and 13 deletions.
40 changes: 27 additions & 13 deletions backend/build.py
Original file line number Diff line number Diff line change
@@ -1,47 +1,61 @@
"""Build scritp gets called on poetry build."""
"""Build script gets called on poetry/pip build."""

import pathlib
import shutil
import subprocess


def pnpm_install(project_root):
subprocess.run(["pnpm", "install"], cwd=project_root)
def pnpm_install(project_root, pnpm_path):
subprocess.run([pnpm_path, "install"], cwd=project_root, check=True)


def pnpm_buildui(project_root):
subprocess.run(["pnpm", "buildUi"], cwd=project_root)
def pnpm_buildui(project_root, pnpm_path):
subprocess.run([pnpm_path, "buildUi"], cwd=project_root, check=True)


def copy_frontend(project_root):
"""Copy the frontend dist directory to the backend for inclusion in the package."""

# Create backend frontend dist dir
backend_frontend_dir = project_root / "backend" / "chainlit" / "frontend"
backend_frontend_dir = project_root / "backend" / "chainlit" / "frontend" / "dist"
backend_frontend_dir.mkdir(parents=True, exist_ok=True)

# Recursively copy frontend_dist to backend_frontend_dir
frontend_dist = project_root / "frontend" / "dist"

shutil.copytree(frontend_dist, backend_frontend_dir / "dist", dirs_exist_ok=True)
print(f"Copying {frontend_dist} to {backend_frontend_dir}")
shutil.copytree(frontend_dist, backend_frontend_dir, dirs_exist_ok=True)


def copy_copilot(project_root):
"""Copy the copilot dist directory to the backend for inclusion in the package."""

# Create backend copilot dir
backend_copilot_dir = project_root / "backend" / "chainlit" / "copilot"
backend_copilot_dir = project_root / "backend" / "chainlit" / "copilot" / "dist"
backend_copilot_dir.mkdir(parents=True, exist_ok=True)

# Recursively copy copilot_dist to backend_copilot_dir
copilot_dist = project_root / "libs" / "copilot" / "dist"

shutil.copytree(copilot_dist, backend_copilot_dir / "dist", dirs_exist_ok=True)
print(f"Copying {copilot_dist} to {backend_copilot_dir}")
shutil.copytree(copilot_dist, backend_copilot_dir, dirs_exist_ok=True)


if __name__ == "__main__":
project_root = pathlib.Path.cwd().parent
pnpm_install(project_root)
pnpm_buildui(project_root)
def build():
# Find directory containing this file.
backend_dir = pathlib.Path(__file__).resolve().parent
project_root = backend_dir.parent

pnpm = shutil.which("pnpm")
if not pnpm:
print("pnpm not found!")
exit(-1)

pnpm_install(project_root, pnpm)
pnpm_buildui(project_root, pnpm)
copy_frontend(project_root)
copy_copilot(project_root)


if __name__ == "__main__":
build()

0 comments on commit 83084d5

Please sign in to comment.