-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Makefile for python code generation from jsonschema
- Loading branch information
1 parent
13cd1ce
commit effdd2b
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <target>\n\nWhere <target> 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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ test = [ | |
"tox" | ||
] | ||
|
||
generation = [ | ||
"datamodel-code-generator" | ||
] | ||
|
||
[project.scripts] | ||
|
||
[tool.black] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters