2024-04-24 13:39:43 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
# Generate schema.py from schema.json
|
|
|
|
datamodel-codegen \
|
2024-06-27 23:16:27 +02:00
|
|
|
--class-name='SchemaRoot' --collapse-root-models --target-python-version 3.11 --disable-timestamp \
|
2024-04-24 13:39:43 +02:00
|
|
|
--use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \
|
|
|
|
--input frontend/src/queries/schema.json --input-file-type jsonschema \
|
2024-06-03 17:34:05 +02:00
|
|
|
--output posthog/schema.py --output-model-type pydantic_v2.BaseModel \
|
|
|
|
--custom-file-header "# mypy: disable-error-code=\"assignment\"" \
|
2024-06-10 15:19:20 +02:00
|
|
|
--set-default-enum-member --capitalise-enum-members \
|
|
|
|
--wrap-string-literal
|
2024-06-27 23:16:27 +02:00
|
|
|
|
2024-04-24 13:39:43 +02:00
|
|
|
# Format schema.py
|
|
|
|
ruff format posthog/schema.py
|
2024-06-27 23:16:27 +02:00
|
|
|
|
2024-04-24 13:39:43 +02:00
|
|
|
# Check schema.py and autofix
|
|
|
|
ruff check --fix posthog/schema.py
|
2024-06-27 23:16:27 +02:00
|
|
|
|
|
|
|
# Replace class Foo(str, Enum) with class Foo(StrEnum) for proper handling in format strings in python 3.11
|
|
|
|
# Remove this when https://github.com/koxudaxi/datamodel-code-generator/issues/1313 is resolved
|
2024-04-24 13:39:43 +02:00
|
|
|
if [[ "$OSTYPE" == "darwin"* ]]; then
|
|
|
|
# sed needs `-i` to be followed by `''` on macOS
|
2024-06-27 23:16:27 +02:00
|
|
|
sed -i '' -e 's/str, Enum/StrEnum/g' posthog/schema.py
|
|
|
|
sed -i '' 's/from enum import Enum/from enum import Enum, StrEnum/g' posthog/schema.py
|
2024-04-24 13:39:43 +02:00
|
|
|
else
|
2024-06-27 23:16:27 +02:00
|
|
|
sed -i -e 's/str, Enum/StrEnum/g' posthog/schema.py
|
|
|
|
sed -i 's/from enum import Enum/from enum import Enum, StrEnum/g' posthog/schema.py
|
|
|
|
fi
|