123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- # The following python-related tools and processes are supported:
- # * coverage (requires ".coveragerc")
- # * flake8
- # * pypi upload (requires "~/.pypirc")
- # * tox / unittests (requires "tox.ini")
- #
- PYTHON_BIN ?= python3
- DIR_PYTHON_BUILD = $(DIR_BUILD)/python-lib
- PYTHON_BDIST_ARGS = --dist-dir $(DIR_BUILD)/python-packages
- PYTHON_BUILD_ARGS = --build-base "$(DIR_PYTHON_BUILD)"
- PYTHON_INSTALL_ARGS = --root "$(abspath $(DESTDIR))"
- PYPI_UPLOAD_TARGET = https://pypi.python.org/pypi
- DIR_PYTHON_COVERAGE_HTML = $(DIR_BUILD)/coverage-html
- PYTHON_COVERAGE_BIN ?= python3-coverage
- # detect if flake8 is available as an executable (e.g. Arch) or as a python module (e.g. Debian)
- FLAKE8_BIN ?= $(shell hash flake8 2>/dev/null && echo "flake8" || echo "$(PYTHON_BIN) -m flake8")
- .PHONY: help
- help: help-python
- .PHONY: help-python
- help-python:
- @echo "Python-specific packaging targets:"
- @echo " clean-python"
- @echo " dist-python"
- @echo " lint-python"
- @echo " report-python"
- @echo " test-python"
- @echo " upload-python"
- @echo
- .PHONY: dist
- dist: dist-python
- .PHONY: install
- install: install-python
- .PHONY: lint
- test: lint-python
- .PHONY: test
- test: test-python
- .PHONY: install-python
- install-python:
- cd "$(DIR_PYTHON_SETUP)" && $(PYTHON_BIN) setup.py install $(PYTHON_INSTALL_ARGS)
- .PHONY: dist-python
- dist-python: clean-python
- cd "$(DIR_PYTHON_SETUP)" \
- && $(PYTHON_BIN) setup.py build $(PYTHON_BUILD_ARGS) bdist $(PYTHON_BDIST_ARGS)
- .PHONY: check-pypi-config
- check-pypi-config:
- @# verify that the section for our internal target is not missing
- @if grep -q "^\[$(PYPI_UPLOAD_TARGET)\]$$" ~/.pypirc; then true; else \
- echo "ERROR: missing '$(PYPI_UPLOAD_TARGET)' section in ~/.pypirc: "\
- "take a look at pypirc.sample" >&2; \
- exit 1; \
- fi
- .PHONY: upload
- upload: upload-python
- .PHONY: upload-python
- upload-python: check-pypi-config
- cd "$(DIR_PYTHON_SETUP)" && $(PYTHON_BIN) setup.py sdist upload -r "$(PYPI_UPLOAD_TARGET)"
- .PHONY: lint-python
- lint-python:
- $(FLAKE8_BIN) "$(DIR_PYTHON_SETUP)"
- .PHONY: test-python
- test-python:
- if [ -e tox.ini ]; then tox; fi
- .PHONY: report
- report: report-python
- .PHONY: report-python
- report-python:
- if [ -e .coveragerc ]; then $(MAKE) report-python-coverage; fi
- .PHONY: report-python-coverage
- report-python-coverage:
- @# run unittests for coverage analysis
- "$(PYTHON_COVERAGE_BIN)" run -m unittest discover
- @# provide textual report
- "$(PYTHON_COVERAGE_BIN)" report
- @# run a visual browser if the DISPLAY variable is set
- @if [ -n "$$DISPLAY" ]; then \
- "$(PYTHON_COVERAGE_BIN)" report --directory "$(DIR_PYTHON_COVERAGE_HTML)" ;\
- x-www-browser "$(DIR_PYTHON_COVERAGE_HTML)"; fi
- .PHONY: clean-python
- clean-python:
- cd "$(DIR_PYTHON_SETUP)" && python3 setup.py clean || true
- @# datafile for python3-coverage
- $(RM) .coverage
|