python-django.mk 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. DIR_DJANGO_LOCALES ?= locale
  2. DJANGO_MAKEMESSAGES_ARGS ?= --ignore "$(DIR_BUILD)/*" --no-location
  3. DJANGO_COMPILEMESSAGES_ARGS ?= --ignore "$(DIR_BUILD)/*"
  4. # try to detect a PO editor for translations
  5. PO_EDITOR ?= $(shell which virtaal poedit | head -1)
  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 $(DJANGO_MAKEMESSAGES_ARGS) $(shell if [ -n "$(DJANGO_WANTED_LOCALES)" ]; then printf -- '--locale %s\n' $(DJANGO_WANTED_LOCALES); else printf -- '--all'; 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. $(RUN_PYTHON) manage.py compilemessages $(DJANGO_COMPILEMESSAGES_ARGS)