0
0
mirror of https://github.com/PostHog/posthog.git synced 2024-11-21 21:49:51 +01:00
posthog/bin/build-schema-python.sh

31 lines
1.3 KiB
Bash
Raw Normal View History

#!/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 \
--use-one-literal-as-default --use-default --use-default-kwarg --use-subclass-enum \
--input frontend/src/queries/schema.json --input-file-type jsonschema \
--output posthog/schema.py --output-model-type pydantic_v2.BaseModel \
--custom-file-header "# mypy: disable-error-code=\"assignment\"" \
--set-default-enum-member --capitalise-enum-members \
--wrap-string-literal
2024-06-27 23:16:27 +02:00
# Format schema.py
ruff format posthog/schema.py
2024-06-27 23:16:27 +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
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
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