diff --git a/python/Makefile b/python/Makefile new file mode 100644 index 00000000..24ac968a --- /dev/null +++ b/python/Makefile @@ -0,0 +1,32 @@ +schemas = $(shell find ../jsonschema -name "*.json") + +.DEFAULT_GOAL = help + +MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) +HERE := $(dir $(MKFILE_PATH)) + +help: ## Show this help + @awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \n\nWhere is one of:\n"} /^[$$()% a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) + +generate: + datamodel-codegen \ + --output-model-type "pydantic_v2.BaseModel" \ + --input $(HERE)../jsonschema/Envelope.json \ + --output $(HERE)src/_messages.py \ + --use-generic-container-types \ + --allow-population-by-field-name \ + --snake-case-field \ + --input-file-type=jsonschema \ + --class-name Envelope \ + --use-double-quotes \ + --use-union-operator + +require: ## Check requirements for the code generation (python is required) + @python --version >/dev/null 2>&1 || (echo "ERROR: python is required."; exit 1) + +clean: ## Remove automatically generated files and related artifacts + rm -rf $(HERE)src/_messages.py + +install-deps: ## Install generation dependencies + python -m ensurepip --upgrade + pip install $(HERE)[generation] diff --git a/python/pyproject.toml b/python/pyproject.toml index aa7d7be0..fb4a8a7a 100644 --- a/python/pyproject.toml +++ b/python/pyproject.toml @@ -45,6 +45,10 @@ test = [ "tox" ] +generation = [ + "datamodel-code-generator" +] + [project.scripts] [tool.black] diff --git a/python/src/_messages.py b/python/src/_messages.py index 461716a1..b49b70bb 100644 --- a/python/src/_messages.py +++ b/python/src/_messages.py @@ -1,11 +1,11 @@ # generated by datamodel-codegen: # filename: Envelope.json -# timestamp: 2024-01-13T14:45:09+00:00 +# timestamp: 2024-09-04T20:46:37+00:00 from __future__ import annotations from enum import Enum -from typing import Optional, Sequence +from typing import Sequence from pydantic import BaseModel, ConfigDict, Field