python.mk 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # The following python-related tools and processes are supported:
  2. # * coverage (requires ".coveragerc")
  3. # * flake8
  4. # * pypi upload (requires "~/.pypirc")
  5. # * tox / unittests (requires "tox.ini")
  6. #
  7. PYTHON_BIN ?= python3
  8. DIR_PYTHON_BUILD = $(DIR_BUILD)/python-lib
  9. PYTHON_BDIST_ARGS = --dist-dir $(DIR_BUILD)/python-packages
  10. PYTHON_BUILD_ARGS = --build-base "$(DIR_PYTHON_BUILD)"
  11. PYPI_UPLOAD_TARGET = https://pypi.python.org/pypi
  12. DIR_PYTHON_COVERAGE_HTML = $(DIR_BUILD)/coverage-html
  13. PYTHON_COVERAGE_BIN ?= python3-coverage
  14. # detect if flake8 is available as an executable (e.g. Arch) or as a python module (e.g. Debian)
  15. FLAKE8_BIN ?= $(shell hash flake8 2>/dev/null && echo "flake8" || echo "$(PYTHON_BIN) -m flake8")
  16. .PHONY: help
  17. help: help-python
  18. .PHONY: help-python
  19. help-python:
  20. @echo "Python-specific packaging targets:"
  21. @echo " clean-python"
  22. @echo " dist-python"
  23. @echo " report-python"
  24. @echo " test-python"
  25. @echo " upload-python"
  26. @echo
  27. .PHONY: dist
  28. dist: dist-python
  29. .PHONY: install
  30. install: install-python
  31. .PHONY: test
  32. test: test-python
  33. .PHONY: install-python
  34. install-python:
  35. cd "$(DIR_PYTHON_SETUP)"; \
  36. $(PYTHON_BIN) setup.py install --root "$(shell realpath "$(DESTDIR)")"
  37. .PHONY: dist-python
  38. dist-python: clean-python
  39. cd "$(DIR_PYTHON_SETUP)"; \
  40. $(PYTHON_BIN) setup.py build $(PYTHON_BUILD_ARGS) bdist $(PYTHON_BDIST_ARGS)
  41. .PHONY: check-pypi-config
  42. check-pypi-config:
  43. @# verify that the section for our internal target is not missing
  44. @if grep -q "^\[$(PYPI_UPLOAD_TARGET)\]$$" ~/.pypirc; then true; else \
  45. echo "ERROR: missing '$(PYPI_UPLOAD_TARGET)' section in ~/.pypirc: "\
  46. "take a look at pypirc.sample" >&2; \
  47. exit 1; \
  48. fi
  49. .PHONY: upload
  50. upload: upload-python
  51. .PHONY: upload-python
  52. upload-python: check-pypi-config
  53. cd "$(DIR_PYTHON_SETUP)"; $(PYTHON_BIN) setup.py sdist upload -r "$(PYPI_UPLOAD_TARGET)"
  54. .PHONY: test-python
  55. test-python:
  56. $(FLAKE8_BIN) "$(DIR_PYTHON_SETUP)"
  57. if [ -e tox.ini ]; then tox; fi
  58. .PHONY: report
  59. report: report-python
  60. .PHONY: report-python
  61. report-python:
  62. if [ -e .coveragerc ]; then $(MAKE) report-python-coverage; fi
  63. .PHONY: report-python-coverage
  64. report-python-coverage:
  65. @# run unittests for coverage analysis
  66. "$(PYTHON_COVERAGE_BIN)" run -m unittest discover
  67. @# provide textual report
  68. "$(PYTHON_COVERAGE_BIN)" report
  69. @# run a visual browser if the DISPLAY variable is set
  70. @if [ -n "$$DISPLAY" ]; then \
  71. "$(PYTHON_COVERAGE_BIN)" report --directory "$(DIR_PYTHON_COVERAGE_HTML)" ;\
  72. x-www-browser "$(DIR_PYTHON_COVERAGE_HTML)"; fi
  73. .PHONY: clean-python
  74. clean-python:
  75. cd "$(DIR_PYTHON_SETUP)"; python3 setup.py clean
  76. @# datafile for python3-coverage
  77. rm -f .coverage