From 5137bdb2ff39acf28f62765c487bbae4e1f0ee9a Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Wed, 3 Sep 2025 01:47:49 +0200 Subject: [PATCH 01/12] fix: build frontend and copilot on installation from source code --- .github/workflows/publish.yaml | 6 +----- RELENG.md | 1 + backend/build.py | 7 +++++-- backend/pyproject.toml | 3 +++ backend/uv.lock | 2 +- 5 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 5eee52d131..dd37e621f0 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -35,15 +35,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 diff --git a/RELENG.md b/RELENG.md index d954219dd5..95e5d4f01e 100644 --- a/RELENG.md +++ b/RELENG.md @@ -18,6 +18,7 @@ This document outlines the steps for maintainers to create a new release of the - Update `version` in `[project]` of `backend/pyproject.toml`. - Update `version` in `backend/chainlit/version.py`. + - Run `uv lock` to include new version in `uv.lock` 3. **Update the changelog**: diff --git a/backend/build.py b/backend/build.py index 9990ba6f00..501165904b 100644 --- a/backend/build.py +++ b/backend/build.py @@ -6,6 +6,8 @@ import subprocess import sys +from hatchling.builders.hooks.plugin.interface import BuildHookInterface + class BuildError(Exception): """Custom exception for build failures""" @@ -98,5 +100,6 @@ def build(): sys.exit(1) -if __name__ == "__main__": - build() +class CustomBuildHook(BuildHookInterface): + def initialize(self, version, build_data): + build() diff --git a/backend/pyproject.toml b/backend/pyproject.toml index 08a8fb9093..25cc48c1f1 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -116,6 +116,9 @@ exclude = [ "chainlit/copilot/**/**/" ] +[tool.hatch.build.hooks.custom] +path = "build.py" + [tool.hatch.build.targets.wheel] packages = ["chainlit"] artifacts = [ diff --git a/backend/uv.lock b/backend/uv.lock index 2983388a36..0470f28608 100644 --- a/backend/uv.lock +++ b/backend/uv.lock @@ -679,7 +679,7 @@ wheels = [ [[package]] name = "chainlit" -version = "2.7.1.1" +version = "2.7.2" source = { editable = "." } dependencies = [ { name = "aiofiles" }, From 7a56f05668a5e48f9a66cbdb9f7e531a4aebe53d Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Wed, 3 Sep 2025 02:06:46 +0200 Subject: [PATCH 02/12] ci: fix linter workflow --- .github/actions/uv-python-install/action.yaml | 2 +- .github/workflows/lint-backend.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/actions/uv-python-install/action.yaml b/.github/actions/uv-python-install/action.yaml index 87f252faf0..9cecc2b182 100644 --- a/.github/actions/uv-python-install/action.yaml +++ b/.github/actions/uv-python-install/action.yaml @@ -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 }} diff --git a/.github/workflows/lint-backend.yaml b/.github/workflows/lint-backend.yaml index 9da0bb358e..8a67459b96 100644 --- a/.github/workflows/lint-backend.yaml +++ b/.github/workflows/lint-backend.yaml @@ -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 }} From 86b0e9bba39536e1bf811f6cf74b4b218a02c80b Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Wed, 3 Sep 2025 02:22:43 +0200 Subject: [PATCH 03/12] ci: fix pytest workflow --- .github/workflows/pytest.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yaml b/.github/workflows/pytest.yaml index 59ca93fceb..cbf0f08fab 100644 --- a/.github/workflows/pytest.yaml +++ b/.github/workflows/pytest.yaml @@ -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 }} From 46c606a017edc0893eada9497323868721a0f980 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Wed, 3 Sep 2025 03:17:28 +0200 Subject: [PATCH 04/12] docs: remove unnecessary ui build from CONTRIBUTING.md --- CONTRIBUTING.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 0382c68462..9d4e088bb5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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. From 6e4e10bbbfb52415163af9b43309a7b4890e2c21 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Thu, 11 Sep 2025 21:55:07 +0200 Subject: [PATCH 05/12] docs: remove no longer actual line in release notes --- RELENG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/RELENG.md b/RELENG.md index adcd2a5ee5..a259038c54 100644 --- a/RELENG.md +++ b/RELENG.md @@ -16,8 +16,7 @@ This document outlines the steps for maintainers to create a new release of the 2. **Bump the package version**: - - Update `version` in `backend/chainlit/version.py`. - - Run `uv lock` to include new version in `uv.lock` + - Update `version` in `backend/chainlit/version.py` 3. **Update the changelog**: From fcb26005844a5657e0f9a6756a639976af26f760 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Thu, 11 Sep 2025 21:56:08 +0200 Subject: [PATCH 06/12] docs: restore dot --- RELENG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RELENG.md b/RELENG.md index a259038c54..1b4358253c 100644 --- a/RELENG.md +++ b/RELENG.md @@ -16,7 +16,7 @@ This document outlines the steps for maintainers to create a new release of the 2. **Bump the package version**: - - Update `version` in `backend/chainlit/version.py` + - Update `version` in `backend/chainlit/version.py`. 3. **Update the changelog**: From f3cf9a491ab760668b112d81cf7577869a53b7f2 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Thu, 11 Sep 2025 22:05:19 +0200 Subject: [PATCH 07/12] chore: temporary bump version --- backend/chainlit/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/chainlit/version.py b/backend/chainlit/version.py index 7f90850470..17c3f314d8 100644 --- a/backend/chainlit/version.py +++ b/backend/chainlit/version.py @@ -1 +1 @@ -__version__ = "2.7.2" +__version__ = "2.7.3dev2" From b132bda303d668661ba31642809bf55f8642586b Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Sat, 13 Sep 2025 00:03:13 +0200 Subject: [PATCH 08/12] chore: fix wheel build and artifacts cleanup after branch switch --- backend/build.py | 4 +++- backend/pyproject.toml | 18 +++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/backend/build.py b/backend/build.py index 501165904b..781d39c87f 100644 --- a/backend/build.py +++ b/backend/build.py @@ -40,7 +40,9 @@ def copy_directory(src, dst, description): """Copy directory with proper error handling""" print(f"Copying {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...") diff --git a/backend/pyproject.toml b/backend/pyproject.toml index fa7bebba74..c587952022 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -116,20 +116,20 @@ exclude = [ "chainlit/copilot/**/**/" ] -[tool.hatch.build.hooks.custom] +[tool.hatch.build.targets.sdist] +artifacts = [ + "chainlit/frontend/dist/**/*", + "chainlit/copilot/dist/**/*" +] + +[tool.hatch.build.targets.sdist.hooks.custom] path = "build.py" [tool.hatch.build.targets.wheel] packages = ["chainlit"] artifacts = [ - "chainlit/frontend/dist/**/*", - "chainlit/copilot/dist/**/*" -] - -[tool.hatch.build.targets.sdist] -artifacts = [ - "chainlit/frontend/dist/**/*", - "chainlit/copilot/dist/**/*" + "chainlit/frontend/dist/**/*", + "chainlit/copilot/dist/**/*" ] [tool.hatch.version] From 5021c4031377645a9595544a53fc2697d156ba54 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Sat, 13 Sep 2025 00:27:27 +0200 Subject: [PATCH 09/12] chore: fix building wheel --- backend/pyproject.toml | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/pyproject.toml b/backend/pyproject.toml index c587952022..d2f972da34 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -116,15 +116,15 @@ exclude = [ "chainlit/copilot/**/**/" ] +[tool.hatch.build.hooks.custom] +path = "build.py" + [tool.hatch.build.targets.sdist] artifacts = [ "chainlit/frontend/dist/**/*", "chainlit/copilot/dist/**/*" ] -[tool.hatch.build.targets.sdist.hooks.custom] -path = "build.py" - [tool.hatch.build.targets.wheel] packages = ["chainlit"] artifacts = [ @@ -132,6 +132,10 @@ artifacts = [ "chainlit/copilot/dist/**/*" ] +[tool.hatch.build.targets.wheel.hooks.custom] +path = "build.py" +enable-by-default = false + [tool.hatch.version] path = "chainlit/version.py" From 1d65c88efc193bfe45fd1d2060f87d15e4804f40 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Sat, 13 Sep 2025 02:18:18 +0200 Subject: [PATCH 10/12] chore: distinguish between building wheel from sdist and from source code --- backend/build.py | 23 +++++++++++++---------- backend/pyproject.toml | 4 ---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/backend/build.py b/backend/build.py index 781d39c87f..a5c294cdc7 100644 --- a/backend/build.py +++ b/backend/build.py @@ -1,6 +1,5 @@ """Build script gets called on uv/pip build.""" -import os import pathlib import shutil import subprocess @@ -15,7 +14,7 @@ class BuildError(Exception): 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. @@ -28,17 +27,17 @@ 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: if dst.exists(): shutil.rmtree(dst) @@ -54,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" @@ -74,7 +73,7 @@ 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: @@ -82,6 +81,10 @@ def build(): 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!") @@ -103,5 +106,5 @@ def build(): class CustomBuildHook(BuildHookInterface): - def initialize(self, version, build_data): + def initialize(self, _, __): build() diff --git a/backend/pyproject.toml b/backend/pyproject.toml index d2f972da34..037c254bfc 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -132,10 +132,6 @@ artifacts = [ "chainlit/copilot/dist/**/*" ] -[tool.hatch.build.targets.wheel.hooks.custom] -path = "build.py" -enable-by-default = false - [tool.hatch.version] path = "chainlit/version.py" From 2ed74b37deab13d7bd1a0660162f0be0d49892af Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Sat, 13 Sep 2025 02:25:15 +0200 Subject: [PATCH 11/12] chore: temporary update version --- backend/chainlit/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/chainlit/version.py b/backend/chainlit/version.py index 17c3f314d8..62489642e5 100644 --- a/backend/chainlit/version.py +++ b/backend/chainlit/version.py @@ -1 +1 @@ -__version__ = "2.7.3dev2" +__version__ = "2.7.3dev3" From 092dc5a438711e7b65813908d6b2647fcf310086 Mon Sep 17 00:00:00 2001 From: Aleksandr Vishniakov Date: Sat, 13 Sep 2025 02:29:16 +0200 Subject: [PATCH 12/12] chore: revert version commits --- backend/chainlit/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/chainlit/version.py b/backend/chainlit/version.py index 62489642e5..7f90850470 100644 --- a/backend/chainlit/version.py +++ b/backend/chainlit/version.py @@ -1 +1 @@ -__version__ = "2.7.3dev3" +__version__ = "2.7.2"