mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-01 18:35:00 -05:00
Prisma's generated `types.py` file is 57,000+ lines with complex recursive TypedDict definitions that exhaust Pyright's type inference budget. This causes random type errors and makes the type checker unreliable. ### Changes 🏗️ - Add `gen_prisma_types_stub.py` script that generates a lightweight `.pyi` stub file - The stub preserves safe types (Literal, TypeVar) while collapsing complex TypedDicts to `dict[str, Any]` - Integrate stub generation into all workflows that run `prisma generate`: - `platform-backend-ci.yml` - `claude.yml` - `claude-dependabot.yml` - `copilot-setup-steps.yml` - `docker-compose.platform.yml` - `Dockerfile` - `Makefile` (migrate & reset-db targets) - `linter.py` (lint & format commands) - Add `gen-prisma-stub` poetry script entry - Fix two pre-existing type errors that were previously masked: - `store/db.py`: Replace private type `_StoreListingVersion_version_OrderByInput` with dict literal - `airtable/_webhook.py`: Add cast for `Serializable` type ### Checklist 📋 #### For code changes: - [x] I have clearly listed my changes in the PR description - [x] I have made a test plan - [x] I have tested my changes according to the test plan: - [x] Run `poetry run format` - passes with 0 errors (down from 57+) - [x] Run `poetry run lint` - passes with 0 errors - [x] Run `poetry run gen-prisma-stub` - generates stub successfully - [x] Verify stub file is created at correct location with proper content #### For configuration changes: - [x] `.env.default` is updated or already compatible with my changes - [x] `docker-compose.yml` is updated or already compatible with my changes - [x] I have included a list of my configuration changes in the PR description (under **Changes**) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Chores** * Added a lightweight Prisma type-stub generator and integrated it into build, lint, CI/CD, and container workflows. * Build, migration, formatting, and lint steps now generate these stubs to improve type-checking performance and reduce overhead during builds and deployments. * Exposed a project command to run stub generation manually. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
58 lines
1.6 KiB
Python
58 lines
1.6 KiB
Python
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
directory = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
BACKEND_DIR = "."
|
|
LIBS_DIR = "../autogpt_libs"
|
|
TARGET_DIRS = [BACKEND_DIR, LIBS_DIR]
|
|
|
|
|
|
def run(*command: str) -> None:
|
|
print(f">>>>> Running poetry run {' '.join(command)}")
|
|
try:
|
|
subprocess.run(
|
|
["poetry", "run"] + list(command),
|
|
cwd=directory,
|
|
check=True,
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.STDOUT,
|
|
)
|
|
except subprocess.CalledProcessError as e:
|
|
print(e.output.decode("utf-8"), file=sys.stderr)
|
|
raise
|
|
|
|
|
|
def lint():
|
|
# Generate Prisma types stub before running pyright to prevent type budget exhaustion
|
|
run("gen-prisma-stub")
|
|
|
|
lint_step_args: list[list[str]] = [
|
|
["ruff", "check", *TARGET_DIRS, "--exit-zero"],
|
|
["ruff", "format", "--diff", "--check", LIBS_DIR],
|
|
["isort", "--diff", "--check", "--profile", "black", BACKEND_DIR],
|
|
["black", "--diff", "--check", BACKEND_DIR],
|
|
["pyright", *TARGET_DIRS],
|
|
]
|
|
lint_error = None
|
|
for args in lint_step_args:
|
|
try:
|
|
run(*args)
|
|
except subprocess.CalledProcessError as e:
|
|
lint_error = e
|
|
|
|
if lint_error:
|
|
print("Lint failed, try running `poetry run format` to fix the issues")
|
|
sys.exit(1)
|
|
|
|
|
|
def format():
|
|
run("ruff", "check", "--fix", *TARGET_DIRS)
|
|
run("ruff", "format", LIBS_DIR)
|
|
run("isort", "--profile", "black", BACKEND_DIR)
|
|
run("black", BACKEND_DIR)
|
|
# Generate Prisma types stub before running pyright to prevent type budget exhaustion
|
|
run("gen-prisma-stub")
|
|
run("pyright", *TARGET_DIRS)
|