2022-06-09 18:12:24 +02:00
set shell : = [ "bash ", "-uc " ]
_default :
@- just --unsorted --choose
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Justfile
# NOTE: Do not change the contents of this file!
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# VARIABLES
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PYTHON := if os_family( ) = = "windows" { "py -3" } else { "python3" }
2022-06-10 11:50:59 +02:00
GEN_MODELS := "datamodel-codegen"
2022-06-11 16:07:09 +02:00
GEN_MODELS_DOCUMENTATION := "openapi-generator"
2022-06-09 18:12:24 +02:00
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Macros
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_create-file-if-not-exists fname :
@touch "{{fname}}" ;
_create-folder-if-not-exists path :
@if ! [ -d "{{path}}" ] ; then mkdir "{{path}}" ; fi
_delete-if-file-exists fname :
@if [ -f "{{fname}}" ] ; then rm "{{fname}}" ; fi
_delete-if-folder-exists path :
@if [ -d "{{path}}" ] ; then rm -rf "{{path}}" ; fi
_clean-all-files pattern :
@find . -type f -name "{{pattern}}" -exec basename { } \; 2> /dev/null
@- find . -type f -name "{{pattern}}" -exec rm { } \; 2> /dev/null
_clean-all-folders pattern :
@find . -type d -name "{{pattern}}" -exec basename { } \; 2> /dev/null
@- find . -type d -name "{{pattern}}" -exec rm -rf { } \; 2> /dev/null
_docker-build-and-log service :
@docker compose up --build -d { { service} } && docker compose logs -f --tail= 0 { { service} }
_docker-build-and-interact service container :
@docker compose up --build -d { { service} } && docker attach { { container} }
2022-06-10 11:50:59 +02:00
_generate-models path name :
@{ { GEN_MODELS} } \
--input-file-type openapi \
--encoding "UTF-8" \
--disable-timestamp \
--use-schema-description \
--allow-population-by-field-name \
--snake-case-field \
--strict-nullable \
--target-python-version 3.9 \
--input { { path} } /{ { name} } -schema.yaml \
--output { { path} } /generated/{ { name} } .py
2022-06-12 10:27:57 +02:00
_generate-models-documentation path_schema path_docs name :
2022-06-11 16:07:09 +02:00
@- { { GEN_MODELS_DOCUMENTATION} } generate \
2022-06-12 10:27:57 +02:00
--input-spec { { path_schema} } /{ { name} } -schema.yaml \
2022-06-11 16:07:09 +02:00
--generator-name markdown \
2022-06-12 10:27:57 +02:00
--output "{{path_docs}}/{{name}}"
2022-06-11 16:07:09 +02:00
2022-06-09 18:12:24 +02:00
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: build
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2022-06-12 10:27:57 +02:00
build :
@just build-requirements
@just _check-system-requirements
@just build-models
build-requirements :
2022-06-09 18:12:24 +02:00
@{ { PYTHON} } -m pip install --disable-pip-version-check -r requirements.txt
2022-06-11 16:07:09 +02:00
build-models :
2022-06-10 11:50:59 +02:00
@echo "Generate data models from schemata."
2022-06-11 16:07:09 +02:00
@just _delete-if-folder-exists "models/generated"
2022-06-10 11:50:59 +02:00
@just _create-folder-if-not-exists "models/generated"
@- just _generate-models "models" "config"
@- just _generate-models "models" "commands"
2022-06-12 10:27:57 +02:00
build-documentation :
2022-06-11 16:07:09 +02:00
@echo "Generate documentations data models from schemata."
@just _delete-if-folder-exists "docs"
@just _create-folder-if-not-exists "docs"
2022-06-12 10:27:57 +02:00
@- just _generate-models-documentation "models" "docs" "config"
@- just _generate-models-documentation "models" "docs" "commands"
@- just _clean-all-files ".openapi-generator*"
@- just _clean-all-folders ".openapi-generator*"
dist :
@just build
@just build-documentation
2022-06-09 18:12:24 +02:00
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: run
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
run :
@{ { PYTHON} } main.py
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: tests
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
tests : tests -unit
tests-logs :
@just _create-logs
@- just tests
@just _display-logs
tests-unit-logs :
@just _create-logs
@- just tests-unit
@just _display-logs
tests-unit :
@{ { PYTHON} } -m pytest tests \
--ignore= tests/integration \
--cov-reset \
--cov= . \
2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: qa
# NOTE: use for development only.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qa :
@{ { PYTHON} } -m coverage report -m
coverage source_path tests_path :
@just _create-logs
@-just _coverage-no-logs "{{source_path}}" "{{tests_path}}"
@just _display-logs
_coverage-no-logs source_path tests_path :
@{ { PYTHON} } -m pytest { { tests_path} } \
--ignore= tests/integration \
--cov-reset \
--cov= { { source_path} } \
--capture= tee-sys \
2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: clean
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
clean :
@-just clean-basic
@-just clean-sessions
clean-sessions :
@echo "All sessions will be force removed."
@- just _delete-if-folder-exists ".secrets" 2> /dev/null
clean-basic :
@echo "All system artefacts will be force removed."
@- just _clean-all-files ".DS_Store" 2> /dev/null
@echo "All test artefacts will be force removed."
@- just _clean-all-folders ".pytest_cache" 2> /dev/null
@- just _delete-if-file-exists ".coverage" 2> /dev/null
@- just _delete-if-folder-exists "logs"
@echo "All build artefacts will be force removed."
@- just _clean-all-folders "__pycache__" 2> /dev/null
@- just _delete-if-folder-exists "models/generated" 2> /dev/null
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: logging, session
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
_create-logs :
@# For logging purposes ( since stdout is rechanneled) :
@just _delete-if-file-exists "logs/debug.log"
@just _create-folder-if-not-exists "logs"
@just _create-file-if-not-exists "logs/debug.log"
_display-logs :
@echo ""
@echo "Content of logs/debug.log:"
@echo "----------------"
@echo ""
@- cat logs/debug.log
@echo ""
@echo "----------------"
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# TARGETS: requirements
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
check-system :
@echo "Operating System detected: {{os_family()}}."
@echo "Python command used: {{PYTHON}}."
2022-06-10 11:50:59 +02:00
_check-system-requirements :
@if ! ( { { GEN_MODELS} } --help >> /dev/null 2> /dev/null ) ; then \
echo "Command '{{GEN_MODELS}}' did not work. Ensure that the installation of 'datamodel-code-generator' worked and that system paths are set." \
exit 1; \
fi
2022-06-11 16:07:09 +02:00
@if ! ( { { GEN_MODELS_DOCUMENTATION} } --help >> /dev/null 2> /dev/null ) ; then \
echo "Command '{{GEN_MODELS_DOCUMENTATION}}' did not work. Ensure that the installation of 'datamodel-code-generator' worked and that system paths are set." \
exit 1; \
fi