Skip to content

Commit

Permalink
feat(py): generate types.py from genkit-schema.json using datamod…
Browse files Browse the repository at this point in the history
…el-codegen #1807

    ISSUE: #1807

    CHANGELOG:
    - [ ] Add a bin/generate_schema_types script that generates the Pydantic
      types.py module.
    - [ ] Update the pre-commit hooks to ensure this file gets regenerated
      routinely.
    - [ ] Remove timestamp to ensure we do not treat a file with identical
      content differently preventing the hassles of updating this file per
    commit.
  • Loading branch information
yesudeep committed Feb 4, 2025
1 parent 58d0bb8 commit 2735ceb
Show file tree
Hide file tree
Showing 5 changed files with 585 additions and 249 deletions.
26 changes: 26 additions & 0 deletions py/bin/generate_schema_types
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/usr/bin/env bash
#
# Copyright 2025 Google LLC
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

TOP_DIR=$(git rev-parse --show-toplevel)
TYPES_FILE="$TOP_DIR/py/packages/genkit/src/genkit/core/types.py"

# Generate types using configuration from pyproject.toml
uv run --directory "$TOP_DIR/py" datamodel-codegen

# Remove the Model class that uses RootModel
sed -i '' '/^class Model(RootModel\[Any\]):$/,/^ root: Any$/d' "$TYPES_FILE"

addlicense \
-c "Google LLC" \
-s=only \
"$TYPES_FILE"

uv run --directory "$TOP_DIR/py" \
ruff check --fix "$TYPES_FILE"

uv run --directory "$TOP_DIR/py" \
ruff format "$TYPES_FILE"
6 changes: 6 additions & 0 deletions py/captainhook.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
{
"run": "pnpm i --frozen-lockfile"
},
{
"run": "py/bin/generate_schema_types"
},
{
"run": "py/bin/fmt"
},
Expand Down Expand Up @@ -81,6 +84,9 @@
{
"run": "pnpm i --frozen-lockfile"
},
{
"run": "py/bin/generate_schema_types"
},
{
"run": "py/bin/fmt"
},
Expand Down
Loading

0 comments on commit 2735ceb

Please sign in to comment.