From f47436d2b991aff57176bbdb96f4b0ec468f6a72 Mon Sep 17 00:00:00 2001 From: Mathijs de Bruin Date: Thu, 31 Oct 2024 10:32:14 +0000 Subject: [PATCH] Pre-commit/CI and build improvements. * Small improvements to build script. * Use ruff for linting and formatting. * Use mypy daemon for (much) faster type-checking. * Add typing to `cache.py` to fix it's requirements. * Bump to latest mypy for increased performance. * Bump husky to latest version. * Only lint Python when Python files have changed. * Linting for GitHub Actions. Requires actionlint: https://github.com/rhysd/actionlint * Linting and formatting check in CI. --- .github/workflows/ci.yaml | 6 +- .../{mypy.yaml => lint-backend.yaml} | 15 +- .gitignore | 1 + .husky/pre-commit | 4 - backend/build.py | 108 ++++++++---- backend/chainlit/cache.py | 3 +- backend/poetry.lock | 162 +++++++----------- backend/pyproject.toml | 7 +- lint-staged.config.js | 7 +- package.json | 6 +- pnpm-lock.yaml | 12 +- 11 files changed, 173 insertions(+), 158 deletions(-) rename .github/workflows/{mypy.yaml => lint-backend.yaml} (58%) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index b2c6d7dda3..ca062dd47b 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -14,8 +14,8 @@ jobs: pytest: uses: ./.github/workflows/pytest.yaml secrets: inherit - mypy: - uses: ./.github/workflows/mypy.yaml + lint-backend: + uses: ./.github/workflows/lint-backend.yaml secrets: inherit e2e-tests: uses: ./.github/workflows/e2e-tests.yaml @@ -26,7 +26,7 @@ jobs: ci: runs-on: ubuntu-latest name: Run CI - needs: [mypy, pytest, lint-ui, e2e-tests] + needs: [lint-backend, pytest, lint-ui, e2e-tests] steps: - name: Done run: echo "Done" diff --git a/.github/workflows/mypy.yaml b/.github/workflows/lint-backend.yaml similarity index 58% rename from .github/workflows/mypy.yaml rename to .github/workflows/lint-backend.yaml index 4ff0cdf49d..ed4d81b5fb 100644 --- a/.github/workflows/mypy.yaml +++ b/.github/workflows/lint-backend.yaml @@ -1,11 +1,11 @@ -name: Mypy +name: LintBackend on: [workflow_call] permissions: read-all jobs: - mypy: + lint-backend: runs-on: ubuntu-latest env: BACKEND_DIR: ./backend @@ -16,6 +16,17 @@ jobs: with: poetry-install-args: --with tests --with mypy --with custom-data --no-root poetry-working-directory: ${{ env.BACKEND_DIR }} + - name: Lint with ruff + uses: astral-sh/ruff-action@v1 + with: + src: ${{ env.BACKEND_DIR }} + changed-files: "true" + - name: Check formatting with ruff + uses: astral-sh/ruff-action@v1 + with: + src: ${{ env.BACKEND_DIR }} + changed-files: "true" + args: "format --check" - name: Run Mypy run: poetry run mypy chainlit/ working-directory: ${{ env.BACKEND_DIR }} diff --git a/.gitignore b/.gitignore index 1b0f2b0171..5510ce46dc 100644 --- a/.gitignore +++ b/.gitignore @@ -60,3 +60,4 @@ dist-ssr .coverage backend/README.md +backend/.dmypy.json diff --git a/.husky/pre-commit b/.husky/pre-commit index 18faa0f3b2..cb2c84d5c3 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,5 +1 @@ -#!/usr/bin/env sh -. "$(dirname -- "$0")/_/husky.sh" - pnpm lint-staged -pnpm run lintPython diff --git a/backend/build.py b/backend/build.py index bdbe9cbb3d..951c496753 100644 --- a/backend/build.py +++ b/backend/build.py @@ -1,62 +1,104 @@ """Build script gets called on poetry/pip build.""" +import os import pathlib import shutil +import signal import subprocess +import sys +from contextlib import contextmanager +from typing import Optional + + +class BuildError(Exception): + """Custom exception for build failures""" + + pass + + +def run_subprocess(cmd: list[str], cwd: os.PathLike) -> None: + """ + Run a subprocess, allowing natural signal propagation. + + Args: + cmd: Command and arguments as a list of strings + cwd: Working directory for the subprocess + """ + + print(f"-- Running: {' '.join(cmd)}") + subprocess.run(cmd, cwd=cwd, check=True) def pnpm_install(project_root, pnpm_path): - subprocess.run( - [pnpm_path, "install", "--frozen-lockfile"], cwd=project_root, check=True - ) + run_subprocess([pnpm_path, "install", "--frozen-lockfile"], project_root) def pnpm_buildui(project_root, pnpm_path): - subprocess.run([pnpm_path, "buildUi"], cwd=project_root, check=True) + run_subprocess([pnpm_path, "buildUi"], project_root) + + +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) + shutil.copytree(src, dst, dirs_exist_ok=True) + except KeyboardInterrupt: + print("\nInterrupt received during copy operation...") + # Clean up partial copies + if dst.exists(): + shutil.rmtree(dst) + raise + except Exception as e: + raise BuildError(f"Failed to copy {src} to {dst}: {str(e)}") 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" / "dist" - backend_frontend_dir.mkdir(parents=True, exist_ok=True) - - # Recursively copy frontend_dist to backend_frontend_dir frontend_dist = project_root / "frontend" / "dist" - - print(f"Copying {frontend_dist} to {backend_frontend_dir}") - shutil.copytree(frontend_dist, backend_frontend_dir, dirs_exist_ok=True) + copy_directory(frontend_dist, backend_frontend_dir, "frontend assets") 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" / "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" - - print(f"Copying {copilot_dist} to {backend_copilot_dir}") - shutil.copytree(copilot_dist, backend_copilot_dir, dirs_exist_ok=True) + copy_directory(copilot_dist, backend_copilot_dir, "copilot assets") 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) + """Main build function with proper error handling""" + + 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" + " `poetry install --no-root`\n" + ) + + try: + # Find directory containing this file + backend_dir = pathlib.Path(__file__).resolve().parent + project_root = backend_dir.parent + + pnpm = shutil.which("pnpm") + if not pnpm: + raise BuildError("pnpm not found!") + + pnpm_install(project_root, pnpm) + pnpm_buildui(project_root, pnpm) + copy_frontend(project_root) + copy_copilot(project_root) + + except KeyboardInterrupt: + print("\nBuild interrupted by user") + sys.exit(1) + except BuildError as e: + print(f"\nBuild failed: {str(e)}") + sys.exit(1) + except Exception as e: + print(f"\nUnexpected error: {str(e)}") + sys.exit(1) if __name__ == "__main__": diff --git a/backend/chainlit/cache.py b/backend/chainlit/cache.py index f117b52022..c888b8ef61 100644 --- a/backend/chainlit/cache.py +++ b/backend/chainlit/cache.py @@ -1,6 +1,7 @@ import importlib.util import os import threading +from typing import Any from chainlit.config import config from chainlit.logger import logger @@ -22,7 +23,7 @@ def init_lc_cache(): ) -_cache = {} +_cache: dict[tuple, Any] = {} _cache_lock = threading.Lock() diff --git a/backend/poetry.lock b/backend/poetry.lock index 27efcf3288..53d6e2ce4f 100644 --- a/backend/poetry.lock +++ b/backend/poetry.lock @@ -421,52 +421,6 @@ files = [ {file = "bidict-0.23.1.tar.gz", hash = "sha256:03069d763bc387bbd20e7d49914e75fc4132a41937fa3405417e1a5a2d006d71"}, ] -[[package]] -name = "black" -version = "24.8.0" -description = "The uncompromising code formatter." -optional = false -python-versions = ">=3.8" -files = [ - {file = "black-24.8.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:09cdeb74d494ec023ded657f7092ba518e8cf78fa8386155e4a03fdcc44679e6"}, - {file = "black-24.8.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:81c6742da39f33b08e791da38410f32e27d632260e599df7245cccee2064afeb"}, - {file = "black-24.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:707a1ca89221bc8a1a64fb5e15ef39cd755633daa672a9db7498d1c19de66a42"}, - {file = "black-24.8.0-cp310-cp310-win_amd64.whl", hash = "sha256:d6417535d99c37cee4091a2f24eb2b6d5ec42b144d50f1f2e436d9fe1916fe1a"}, - {file = "black-24.8.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:fb6e2c0b86bbd43dee042e48059c9ad7830abd5c94b0bc518c0eeec57c3eddc1"}, - {file = "black-24.8.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:837fd281f1908d0076844bc2b801ad2d369c78c45cf800cad7b61686051041af"}, - {file = "black-24.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:62e8730977f0b77998029da7971fa896ceefa2c4c4933fcd593fa599ecbf97a4"}, - {file = "black-24.8.0-cp311-cp311-win_amd64.whl", hash = "sha256:72901b4913cbac8972ad911dc4098d5753704d1f3c56e44ae8dce99eecb0e3af"}, - {file = "black-24.8.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:7c046c1d1eeb7aea9335da62472481d3bbf3fd986e093cffd35f4385c94ae368"}, - {file = "black-24.8.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:649f6d84ccbae73ab767e206772cc2d7a393a001070a4c814a546afd0d423aed"}, - {file = "black-24.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2b59b250fdba5f9a9cd9d0ece6e6d993d91ce877d121d161e4698af3eb9c1018"}, - {file = "black-24.8.0-cp312-cp312-win_amd64.whl", hash = "sha256:6e55d30d44bed36593c3163b9bc63bf58b3b30e4611e4d88a0c3c239930ed5b2"}, - {file = "black-24.8.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:505289f17ceda596658ae81b61ebbe2d9b25aa78067035184ed0a9d855d18afd"}, - {file = "black-24.8.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:b19c9ad992c7883ad84c9b22aaa73562a16b819c1d8db7a1a1a49fb7ec13c7d2"}, - {file = "black-24.8.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:1f13f7f386f86f8121d76599114bb8c17b69d962137fc70efe56137727c7047e"}, - {file = "black-24.8.0-cp38-cp38-win_amd64.whl", hash = "sha256:f490dbd59680d809ca31efdae20e634f3fae27fba3ce0ba3208333b713bc3920"}, - {file = "black-24.8.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:eab4dd44ce80dea27dc69db40dab62d4ca96112f87996bca68cd75639aeb2e4c"}, - {file = "black-24.8.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:3c4285573d4897a7610054af5a890bde7c65cb466040c5f0c8b732812d7f0e5e"}, - {file = "black-24.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:9e84e33b37be070ba135176c123ae52a51f82306def9f7d063ee302ecab2cf47"}, - {file = "black-24.8.0-cp39-cp39-win_amd64.whl", hash = "sha256:73bbf84ed136e45d451a260c6b73ed674652f90a2b3211d6a35e78054563a9bb"}, - {file = "black-24.8.0-py3-none-any.whl", hash = "sha256:972085c618ee94f402da1af548a4f218c754ea7e5dc70acb168bfaca4c2542ed"}, - {file = "black-24.8.0.tar.gz", hash = "sha256:2500945420b6784c38b9ee885af039f5e7471ef284ab03fa35ecdde4688cd83f"}, -] - -[package.dependencies] -click = ">=8.0.0" -mypy-extensions = ">=0.4.3" -packaging = ">=22.0" -pathspec = ">=0.9.0" -platformdirs = ">=2" -tomli = {version = ">=1.1.0", markers = "python_version < \"3.11\""} -typing-extensions = {version = ">=4.0.1", markers = "python_version < \"3.11\""} - -[package.extras] -colorama = ["colorama (>=0.4.3)"] -d = ["aiohttp (>=3.7.4)", "aiohttp (>=3.7.4,!=3.9.0)"] -jupyter = ["ipython (>=7.8.0)", "tokenize-rt (>=3.2.0)"] -uvloop = ["uvloop (>=0.15.2)"] - [[package]] name = "boilerpy3" version = "1.0.7" @@ -1841,20 +1795,6 @@ files = [ [package.dependencies] six = "*" -[[package]] -name = "isort" -version = "5.13.2" -description = "A Python utility / library to sort Python imports." -optional = false -python-versions = ">=3.8.0" -files = [ - {file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"}, - {file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"}, -] - -[package.extras] -colors = ["colorama (>=0.4.6)"] - [[package]] name = "jinja2" version = "3.1.4" @@ -3026,38 +2966,43 @@ typing-extensions = {version = ">=4.1.0", markers = "python_version < \"3.11\""} [[package]] name = "mypy" -version = "1.11.2" +version = "1.13.0" description = "Optional static typing for Python" optional = false python-versions = ">=3.8" files = [ - {file = "mypy-1.11.2-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:d42a6dd818ffce7be66cce644f1dff482f1d97c53ca70908dff0b9ddc120b77a"}, - {file = "mypy-1.11.2-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:801780c56d1cdb896eacd5619a83e427ce436d86a3bdf9112527f24a66618fef"}, - {file = "mypy-1.11.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:41ea707d036a5307ac674ea172875f40c9d55c5394f888b168033177fce47383"}, - {file = "mypy-1.11.2-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:6e658bd2d20565ea86da7d91331b0eed6d2eee22dc031579e6297f3e12c758c8"}, - {file = "mypy-1.11.2-cp310-cp310-win_amd64.whl", hash = "sha256:478db5f5036817fe45adb7332d927daa62417159d49783041338921dcf646fc7"}, - {file = "mypy-1.11.2-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:75746e06d5fa1e91bfd5432448d00d34593b52e7e91a187d981d08d1f33d4385"}, - {file = "mypy-1.11.2-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:a976775ab2256aadc6add633d44f100a2517d2388906ec4f13231fafbb0eccca"}, - {file = "mypy-1.11.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:cd953f221ac1379050a8a646585a29574488974f79d8082cedef62744f0a0104"}, - {file = "mypy-1.11.2-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:57555a7715c0a34421013144a33d280e73c08df70f3a18a552938587ce9274f4"}, - {file = "mypy-1.11.2-cp311-cp311-win_amd64.whl", hash = "sha256:36383a4fcbad95f2657642a07ba22ff797de26277158f1cc7bd234821468b1b6"}, - {file = "mypy-1.11.2-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:e8960dbbbf36906c5c0b7f4fbf2f0c7ffb20f4898e6a879fcf56a41a08b0d318"}, - {file = "mypy-1.11.2-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:06d26c277962f3fb50e13044674aa10553981ae514288cb7d0a738f495550b36"}, - {file = "mypy-1.11.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:6e7184632d89d677973a14d00ae4d03214c8bc301ceefcdaf5c474866814c987"}, - {file = "mypy-1.11.2-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:3a66169b92452f72117e2da3a576087025449018afc2d8e9bfe5ffab865709ca"}, - {file = "mypy-1.11.2-cp312-cp312-win_amd64.whl", hash = "sha256:969ea3ef09617aff826885a22ece0ddef69d95852cdad2f60c8bb06bf1f71f70"}, - {file = "mypy-1.11.2-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:37c7fa6121c1cdfcaac97ce3d3b5588e847aa79b580c1e922bb5d5d2902df19b"}, - {file = "mypy-1.11.2-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:4a8a53bc3ffbd161b5b2a4fff2f0f1e23a33b0168f1c0778ec70e1a3d66deb86"}, - {file = "mypy-1.11.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:2ff93107f01968ed834f4256bc1fc4475e2fecf6c661260066a985b52741ddce"}, - {file = "mypy-1.11.2-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:edb91dded4df17eae4537668b23f0ff6baf3707683734b6a818d5b9d0c0c31a1"}, - {file = "mypy-1.11.2-cp38-cp38-win_amd64.whl", hash = "sha256:ee23de8530d99b6db0573c4ef4bd8f39a2a6f9b60655bf7a1357e585a3486f2b"}, - {file = "mypy-1.11.2-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:801ca29f43d5acce85f8e999b1e431fb479cb02d0e11deb7d2abb56bdaf24fd6"}, - {file = "mypy-1.11.2-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:af8d155170fcf87a2afb55b35dc1a0ac21df4431e7d96717621962e4b9192e70"}, - {file = "mypy-1.11.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:f7821776e5c4286b6a13138cc935e2e9b6fde05e081bdebf5cdb2bb97c9df81d"}, - {file = "mypy-1.11.2-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:539c570477a96a4e6fb718b8d5c3e0c0eba1f485df13f86d2970c91f0673148d"}, - {file = "mypy-1.11.2-cp39-cp39-win_amd64.whl", hash = "sha256:3f14cd3d386ac4d05c5a39a51b84387403dadbd936e17cb35882134d4f8f0d24"}, - {file = "mypy-1.11.2-py3-none-any.whl", hash = "sha256:b499bc07dbdcd3de92b0a8b29fdf592c111276f6a12fe29c30f6c417dd546d12"}, - {file = "mypy-1.11.2.tar.gz", hash = "sha256:7f9993ad3e0ffdc95c2a14b66dee63729f021968bff8ad911867579c65d13a79"}, + {file = "mypy-1.13.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6607e0f1dd1fb7f0aca14d936d13fd19eba5e17e1cd2a14f808fa5f8f6d8f60a"}, + {file = "mypy-1.13.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:8a21be69bd26fa81b1f80a61ee7ab05b076c674d9b18fb56239d72e21d9f4c80"}, + {file = "mypy-1.13.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7b2353a44d2179846a096e25691d54d59904559f4232519d420d64da6828a3a7"}, + {file = "mypy-1.13.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:0730d1c6a2739d4511dc4253f8274cdd140c55c32dfb0a4cf8b7a43f40abfa6f"}, + {file = "mypy-1.13.0-cp310-cp310-win_amd64.whl", hash = "sha256:c5fc54dbb712ff5e5a0fca797e6e0aa25726c7e72c6a5850cfd2adbc1eb0a372"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:581665e6f3a8a9078f28d5502f4c334c0c8d802ef55ea0e7276a6e409bc0d82d"}, + {file = "mypy-1.13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:3ddb5b9bf82e05cc9a627e84707b528e5c7caaa1c55c69e175abb15a761cec2d"}, + {file = "mypy-1.13.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:20c7ee0bc0d5a9595c46f38beb04201f2620065a93755704e141fcac9f59db2b"}, + {file = "mypy-1.13.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:3790ded76f0b34bc9c8ba4def8f919dd6a46db0f5a6610fb994fe8efdd447f73"}, + {file = "mypy-1.13.0-cp311-cp311-win_amd64.whl", hash = "sha256:51f869f4b6b538229c1d1bcc1dd7d119817206e2bc54e8e374b3dfa202defcca"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_10_13_x86_64.whl", hash = "sha256:5c7051a3461ae84dfb5dd15eff5094640c61c5f22257c8b766794e6dd85e72d5"}, + {file = "mypy-1.13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:39bb21c69a5d6342f4ce526e4584bc5c197fd20a60d14a8624d8743fffb9472e"}, + {file = "mypy-1.13.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:164f28cb9d6367439031f4c81e84d3ccaa1e19232d9d05d37cb0bd880d3f93c2"}, + {file = "mypy-1.13.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:a4c1bfcdbce96ff5d96fc9b08e3831acb30dc44ab02671eca5953eadad07d6d0"}, + {file = "mypy-1.13.0-cp312-cp312-win_amd64.whl", hash = "sha256:a0affb3a79a256b4183ba09811e3577c5163ed06685e4d4b46429a271ba174d2"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a7b44178c9760ce1a43f544e595d35ed61ac2c3de306599fa59b38a6048e1aa7"}, + {file = "mypy-1.13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:5d5092efb8516d08440e36626f0153b5006d4088c1d663d88bf79625af3d1d62"}, + {file = "mypy-1.13.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:de2904956dac40ced10931ac967ae63c5089bd498542194b436eb097a9f77bc8"}, + {file = "mypy-1.13.0-cp313-cp313-musllinux_1_1_x86_64.whl", hash = "sha256:7bfd8836970d33c2105562650656b6846149374dc8ed77d98424b40b09340ba7"}, + {file = "mypy-1.13.0-cp313-cp313-win_amd64.whl", hash = "sha256:9f73dba9ec77acb86457a8fc04b5239822df0c14a082564737833d2963677dbc"}, + {file = "mypy-1.13.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:100fac22ce82925f676a734af0db922ecfea991e1d7ec0ceb1e115ebe501301a"}, + {file = "mypy-1.13.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:7bcb0bb7f42a978bb323a7c88f1081d1b5dee77ca86f4100735a6f541299d8fb"}, + {file = "mypy-1.13.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:bde31fc887c213e223bbfc34328070996061b0833b0a4cfec53745ed61f3519b"}, + {file = "mypy-1.13.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:07de989f89786f62b937851295ed62e51774722e5444a27cecca993fc3f9cd74"}, + {file = "mypy-1.13.0-cp38-cp38-win_amd64.whl", hash = "sha256:4bde84334fbe19bad704b3f5b78c4abd35ff1026f8ba72b29de70dda0916beb6"}, + {file = "mypy-1.13.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:0246bcb1b5de7f08f2826451abd947bf656945209b140d16ed317f65a17dc7dc"}, + {file = "mypy-1.13.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:7f5b7deae912cf8b77e990b9280f170381fdfbddf61b4ef80927edd813163732"}, + {file = "mypy-1.13.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:7029881ec6ffb8bc233a4fa364736789582c738217b133f1b55967115288a2bc"}, + {file = "mypy-1.13.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:3e38b980e5681f28f033f3be86b099a247b13c491f14bb8b1e1e134d23bb599d"}, + {file = "mypy-1.13.0-cp39-cp39-win_amd64.whl", hash = "sha256:a6789be98a2017c912ae6ccb77ea553bbaf13d27605d2ca20a76dfbced631b24"}, + {file = "mypy-1.13.0-py3-none-any.whl", hash = "sha256:9c250883f9fd81d212e0952c92dbfcc96fc237f4b7c92f56ac81fd48460b3e5a"}, + {file = "mypy-1.13.0.tar.gz", hash = "sha256:0291a61b6fbf3e6673e3405cfcc0e7650bebc7939659fdca2702958038bd835e"}, ] [package.dependencies] @@ -3067,6 +3012,7 @@ typing-extensions = ">=4.6.0" [package.extras] dmypy = ["psutil (>=4.0)"] +faster-cache = ["orjson"] install-types = ["pip"] mypyc = ["setuptools (>=50)"] reports = ["lxml"] @@ -3559,17 +3505,6 @@ files = [ numpy = ">=1.23.5" types-pytz = ">=2022.1.1" -[[package]] -name = "pathspec" -version = "0.12.1" -description = "Utility library for gitignore style pattern matching of file paths." -optional = false -python-versions = ">=3.8" -files = [ - {file = "pathspec-0.12.1-py3-none-any.whl", hash = "sha256:a0d503e138a4c123b27490a4f7beda6a01c6f288df0e4a8b79c7eb0dc7b4cc08"}, - {file = "pathspec-0.12.1.tar.gz", hash = "sha256:a482d51503a1ab33b1c67a6c3813a26953dbdc71c31dacaef9a838c4e29f5712"}, -] - [[package]] name = "pillow" version = "10.4.0" @@ -4503,6 +4438,33 @@ files = [ {file = "rpds_py-0.20.0.tar.gz", hash = "sha256:d72a210824facfdaf8768cf2d7ca25a042c30320b3020de2fa04640920d4e121"}, ] +[[package]] +name = "ruff" +version = "0.7.1" +description = "An extremely fast Python linter and code formatter, written in Rust." +optional = false +python-versions = ">=3.7" +files = [ + {file = "ruff-0.7.1-py3-none-linux_armv6l.whl", hash = "sha256:cb1bc5ed9403daa7da05475d615739cc0212e861b7306f314379d958592aaa89"}, + {file = "ruff-0.7.1-py3-none-macosx_10_12_x86_64.whl", hash = "sha256:27c1c52a8d199a257ff1e5582d078eab7145129aa02721815ca8fa4f9612dc35"}, + {file = "ruff-0.7.1-py3-none-macosx_11_0_arm64.whl", hash = "sha256:588a34e1ef2ea55b4ddfec26bbe76bc866e92523d8c6cdec5e8aceefeff02d99"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:94fc32f9cdf72dc75c451e5f072758b118ab8100727168a3df58502b43a599ca"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_armv7l.manylinux2014_armv7l.whl", hash = "sha256:985818742b833bffa543a84d1cc11b5e6871de1b4e0ac3060a59a2bae3969250"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:32f1e8a192e261366c702c5fb2ece9f68d26625f198a25c408861c16dc2dea9c"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_ppc64.manylinux2014_ppc64.whl", hash = "sha256:699085bf05819588551b11751eff33e9ca58b1b86a6843e1b082a7de40da1565"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl", hash = "sha256:344cc2b0814047dc8c3a8ff2cd1f3d808bb23c6658db830d25147339d9bf9ea7"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:4316bbf69d5a859cc937890c7ac7a6551252b6a01b1d2c97e8fc96e45a7c8b4a"}, + {file = "ruff-0.7.1-py3-none-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:79d3af9dca4c56043e738a4d6dd1e9444b6d6c10598ac52d146e331eb155a8ad"}, + {file = "ruff-0.7.1-py3-none-musllinux_1_2_aarch64.whl", hash = "sha256:c5c121b46abde94a505175524e51891f829414e093cd8326d6e741ecfc0a9112"}, + {file = "ruff-0.7.1-py3-none-musllinux_1_2_armv7l.whl", hash = "sha256:8422104078324ea250886954e48f1373a8fe7de59283d747c3a7eca050b4e378"}, + {file = "ruff-0.7.1-py3-none-musllinux_1_2_i686.whl", hash = "sha256:56aad830af8a9db644e80098fe4984a948e2b6fc2e73891538f43bbe478461b8"}, + {file = "ruff-0.7.1-py3-none-musllinux_1_2_x86_64.whl", hash = "sha256:658304f02f68d3a83c998ad8bf91f9b4f53e93e5412b8f2388359d55869727fd"}, + {file = "ruff-0.7.1-py3-none-win32.whl", hash = "sha256:b517a2011333eb7ce2d402652ecaa0ac1a30c114fbbd55c6b8ee466a7f600ee9"}, + {file = "ruff-0.7.1-py3-none-win_amd64.whl", hash = "sha256:f38c41fcde1728736b4eb2b18850f6d1e3eedd9678c914dede554a70d5241307"}, + {file = "ruff-0.7.1-py3-none-win_arm64.whl", hash = "sha256:19aa200ec824c0f36d0c9114c8ec0087082021732979a359d6f3c390a6ff2a37"}, + {file = "ruff-0.7.1.tar.gz", hash = "sha256:9d8a41d4aa2dad1575adb98a82870cf5db5f76b2938cf2206c22c940034a36f4"}, +] + [[package]] name = "s3transfer" version = "0.10.2" @@ -5760,4 +5722,4 @@ type = ["pytest-mypy"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<4.0.0" -content-hash = "83dcb100388452b55021b7121738be63f4a8f00b2a5640d006e36561f9d43fc5" +content-hash = "2964359572fb5dc66ff4428b72b89b9154b71f8192a4783887c1073faee7085e" diff --git a/backend/pyproject.toml b/backend/pyproject.toml index d9f63d44e9..8b57573159 100644 --- a/backend/pyproject.toml +++ b/backend/pyproject.toml @@ -87,14 +87,13 @@ pandas = "^2.2.2" moto = "^5.0.14" [tool.poetry.group.dev.dependencies] -black = "^24.8.0" -isort = "^5.13.2" +ruff = "^0.7.1" [tool.poetry.group.mypy] optional = true [tool.poetry.group.mypy.dependencies] -mypy = "^1.7.1" +mypy = "^1.13" types-requests = "^2.31.0.2" types-aiofiles = "^23.1.0.5" mypy-boto3-dynamodb = "^1.34.113" @@ -125,6 +124,8 @@ ignore_missing_imports = true + + [tool.poetry.group.custom-data] optional = true diff --git a/lint-staged.config.js b/lint-staged.config.js index 548cc2feb6..9fb04678a6 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,6 +1,7 @@ // eslint-disable-next-line no-undef module.exports = { - "**/*.{js,jsx,ts,tsx}": ["npx prettier --write", "npx eslint --fix"], - "**/*.{ts,tsx}": [() => "tsc --skipLibCheck --noEmit"], - "**/*.py": ["black", "isort --profile=black"], + '**/*.{js,jsx,ts,tsx}': ['npx prettier --write', 'npx eslint --fix'], + '**/*.{ts,tsx}': [() => 'tsc --skipLibCheck --noEmit'], + '**/*.py': ['ruff check --fix', 'ruff format', () => 'pnpm run lintPython'], + '.github/{workflows,actions}/**': ['actionlint'] }; diff --git a/package.json b/package.json index 4d1d2b640a..053f8d16b6 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "cypress": "12.9.0", "dotenv": "^16.3.1", "eslint": "^8.48.0", - "husky": "^8.0.3", + "husky": "^9.1.6", "kill-port": "^2.0.1", "lint-staged": "^13.3.0", "prettier": "^2.8.8", @@ -20,10 +20,10 @@ "preinstall": "npx only-allow pnpm", "test": "pnpm exec ts-node ./cypress/support/e2e.ts", "test:ui": "cd frontend && pnpm test", - "prepare": "husky install", + "prepare": "husky", "lintUi": "cd frontend && pnpm run lint", "formatUi": "cd frontend && pnpm run format", - "lintPython": "cd backend && poetry run mypy chainlit/ tests/", + "lintPython": "cd backend && poetry run dmypy run --timeout 600 -- chainlit/ tests/", "formatPython": "black `git ls-files | grep '.py$'` && isort --profile=black .", "buildUi": "cd libs/react-client && pnpm run build && cd ../copilot && pnpm run build && cd ../../frontend && pnpm run build" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 67cfc9acc6..6f2cfe332a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -38,8 +38,8 @@ importers: specifier: ^8.48.0 version: 8.48.0 husky: - specifier: ^8.0.3 - version: 8.0.3 + specifier: ^9.1.6 + version: 9.1.6 kill-port: specifier: ^2.0.1 version: 2.0.1 @@ -871,9 +871,9 @@ packages: resolution: {integrity: sha512-nZXjEF2nbo7lIw3mgYjItAfgQXog3OjJogSbKa2CQIIvSGWcKgeJnQlNXip6NglNzYH45nSRiEVimMvYL8DDqQ==} engines: {node: '>=14.18.0'} - husky@8.0.3: - resolution: {integrity: sha512-+dQSyqPh4x1hlO1swXBiNb2HzTDN1I2IGLQx1GrBuiqFJfoMrnZWwVmatvSiO+Iz8fBUnf+lekwNo4c2LlXItg==} - engines: {node: '>=14'} + husky@9.1.6: + resolution: {integrity: sha512-sqbjZKK7kf44hfdE94EoX8MZNk0n7HeW37O4YrVGCF4wzgQjp+akPAkfUK5LZ6KuR/6sqeAVuXHji+RzQgOn5A==} + engines: {node: '>=18'} hasBin: true ieee754@1.2.1: @@ -2447,7 +2447,7 @@ snapshots: human-signals@4.3.1: {} - husky@8.0.3: {} + husky@9.1.6: {} ieee754@1.2.1: {}