python-django.mk 1.7 KB

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