python-django.mk 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. DIR_DJANGO_LOCALES ?= locale
  2. # try to detect a PO editor for translations
  3. PO_EDITOR ?= $(shell which virtaal poedit | head -1)
  4. .PHONY: help-python-django
  5. help-python-django:
  6. @echo "Targets related to Django (Python):"
  7. @echo " django-migrate"
  8. @echo " django-translate"
  9. @echo
  10. help-python: help-python-django
  11. virtualenv-check:
  12. @# this should fail if dependencies are missing or no virtualenv is active
  13. @if $(RUN_PYTHON) manage.py check >/dev/null; then true; else \
  14. echo >&2 'Some python-related dependencies are missing'; \
  15. echo >&2 ' You have two options:'; \
  16. echo >&2 ' 1. Install dependencies system-wide. See the $(VIRTUALENV_REQUIREMENTS_FILE) file.'; \
  17. echo >&2 ' 2. Run "make virtualenv-update && . $(ACTIVATE_VIRTUALENV)".'; \
  18. false; fi
  19. .PHONY: django-migrate
  20. django-migrate:
  21. $(RUN_PYTHON) manage.py makemigrations
  22. $(RUN_PYTHON) manage.py migrate
  23. .PHONY: django-translate
  24. django-translate:
  25. @mkdir -p "$(DIR_DJANGO_LOCALES)"
  26. $(RUN_PYTHON) manage.py makemessages --ignore "$(DIR_BUILD)/*" $(shell if [ -n "$(DJANGO_WANTED_LOCALES)" ]; then printf -- '--locale %s\n' $(DJANGO_WANTED_LOCALES); else printf -- '--all'; fi)
  27. @if [ -z "$$(find "$(DIR_DJANGO_LOCALES)" -type f -name "*.po")" ]; then \
  28. echo >&2 "There are no PO files below '$(DIR_DJANGO_LOCALES)': maybe you want to run the following?"; \
  29. echo >&2 " make django-translate DJANGO_WANTED_LOCALES='FOO BAR'"; false; fi
  30. if [ -n "$(PO_EDITOR)" ]; then find "$(DIR_DJANGO_LOCALES)" -type f -name "*.po" | xargs -r -n 1 "$(PO_EDITOR)"; fi
  31. @# TODO: add '--ignore' (see above) after switching to Django v2.2 or later
  32. $(RUN_PYTHON) manage.py compilemessages