Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/uv-python-install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,6 @@ runs:
with:
python-version: ${{ inputs.python-version }}
- name: Install Python dependencies
run: uv sync ${{ inputs.extra-dependencies }}
run: uv sync --no-install-project --no-editable ${{ inputs.extra-dependencies }}
shell: bash
working-directory: ${{ inputs.working-directory }}
2 changes: 1 addition & 1 deletion .github/workflows/lint-backend.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ jobs:
changed-files: "true"
args: "format --check"
- name: Run Mypy
run: uv run mypy chainlit/
run: uv run --no-project mypy chainlit/
working-directory: ${{ env.BACKEND_DIR }}
6 changes: 1 addition & 5 deletions .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ jobs:
with:
working-directory: ${{ env.BACKEND_DIR }}

- name: Build frontend and prepare assets
run: uv run python build.py
working-directory: ${{ env.BACKEND_DIR }}

- name: Build Python distribution
run: uv build
working-directory: ${{ env.BACKEND_DIR }}

- name: List wheel contents
- name: Check frontend and copilot folder included
run: |
pip install wheel
python -m wheel unpack dist/chainlit-*.whl -d unpacked
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@ jobs:
run: pnpm run buildUi
timeout-minutes: 5
- name: Run Pytest
run: uv run pytest --cov=chainlit/
run: uv run --no-project pytest --cov=chainlit/
working-directory: ${{ env.BACKEND_DIR }}
8 changes: 0 additions & 8 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ cd backend
uv sync --extra tests --extra mypy --extra dev --extra custom-data
```

### Build Frontend

The following will build the frontend distributions locally. From the root of the repo:

```sh
pnpm run buildUi
```

## Start the Chainlit server from source

Start by running `backend/hello.py` as an example.
Expand Down
32 changes: 20 additions & 12 deletions backend/build.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
"""Build script gets called on uv/pip build."""

import os
import pathlib
import shutil
import subprocess
import sys

from hatchling.builders.hooks.plugin.interface import BuildHookInterface


class BuildError(Exception):
"""Custom exception for build failures"""

pass


def run_subprocess(cmd: list[str], cwd: os.PathLike) -> None:
def run_subprocess(cmd: list[str], cwd: pathlib.Path) -> None:
"""
Run a subprocess, allowing natural signal propagation.

Expand All @@ -26,19 +27,21 @@ def run_subprocess(cmd: list[str], cwd: os.PathLike) -> None:
subprocess.run(cmd, cwd=cwd, check=True)


def pnpm_install(project_root, pnpm_path):
def pnpm_install(project_root: pathlib.Path, pnpm_path: str):
run_subprocess([pnpm_path, "install", "--frozen-lockfile"], project_root)


def pnpm_buildui(project_root, pnpm_path):
def pnpm_buildui(project_root: pathlib.Path, pnpm_path: str):
run_subprocess([pnpm_path, "buildUi"], project_root)


def copy_directory(src, dst, description):
def copy_directory(src: pathlib.Path, dst: pathlib.Path, description: str):
"""Copy directory with proper error handling"""
print(f"Copying {src} to {dst}")
print(f"Copying {description} from {src} to {dst}")
try:
dst.mkdir(parents=True, exist_ok=True)
if dst.exists():
shutil.rmtree(dst)
dst.mkdir(parents=True)
shutil.copytree(src, dst, dirs_exist_ok=True)
except KeyboardInterrupt:
print("\nInterrupt received during copy operation...")
Expand All @@ -50,14 +53,14 @@ def copy_directory(src, dst, description):
raise BuildError(f"Failed to copy {src} to {dst}: {e!s}")


def copy_frontend(project_root):
def copy_frontend(project_root: pathlib.Path):
"""Copy the frontend dist directory to the backend for inclusion in the package."""
backend_frontend_dir = project_root / "backend" / "chainlit" / "frontend" / "dist"
frontend_dist = project_root / "frontend" / "dist"
copy_directory(frontend_dist, backend_frontend_dir, "frontend assets")


def copy_copilot(project_root):
def copy_copilot(project_root: pathlib.Path):
"""Copy the copilot dist directory to the backend for inclusion in the package."""
backend_copilot_dir = project_root / "backend" / "chainlit" / "copilot" / "dist"
copilot_dist = project_root / "libs" / "copilot" / "dist"
Expand All @@ -70,14 +73,18 @@ def build():
print(
"\n-- Building frontend, this might take a while!\n\n"
" If you don't need to build the frontend and just want dependencies installed, use:\n"
" `uv sync --no-build`\n"
" `uv sync --no-install-project --no-editable`\n"
)

try:
# Find directory containing this file
backend_dir = pathlib.Path(__file__).resolve().parent
project_root = backend_dir.parent

# Dirty hack to distinguish between building wheel from sdist and from source code
if not (project_root / "package.json").exists():
return

pnpm = shutil.which("pnpm")
if not pnpm:
raise BuildError("pnpm not found!")
Expand All @@ -98,5 +105,6 @@ def build():
sys.exit(1)


if __name__ == "__main__":
build()
class CustomBuildHook(BuildHookInterface):
def initialize(self, _, __):
build()
17 changes: 10 additions & 7 deletions backend/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,20 @@ exclude = [
"chainlit/copilot/**/**/"
]

[tool.hatch.build.targets.wheel]
packages = ["chainlit"]
[tool.hatch.build.hooks.custom]
path = "build.py"

[tool.hatch.build.targets.sdist]
artifacts = [
"chainlit/frontend/dist/**/*",
"chainlit/copilot/dist/**/*"
"chainlit/frontend/dist/**/*",
"chainlit/copilot/dist/**/*"
]

[tool.hatch.build.targets.sdist]
[tool.hatch.build.targets.wheel]
packages = ["chainlit"]
artifacts = [
"chainlit/frontend/dist/**/*",
"chainlit/copilot/dist/**/*"
"chainlit/frontend/dist/**/*",
"chainlit/copilot/dist/**/*"
]

[tool.hatch.version]
Expand Down
Loading