Last active
September 3, 2020 19:39
-
-
Save thoroc/c9ebff205cf1b74c1c9f059518d7838b to your computer and use it in GitHub Desktop.
Create a list of targets for Makefile without having to write and maintain a list inside a `define HELP ... endef` block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.DEFAULT_GOAL := help | |
.PHONY: help | |
help: ## Displays this list and descriptions of available targets | |
@echo "" | |
@echo "targets:" | |
@echo "" | |
@awk -F ':|##' '/^[^\t].+:.*##/ {printf "\033[36mmake % -30s\033[0m -%s\n", $$1, $$NF }' $(MAKEFILE_LIST) | sort | |
@echo "" | |
clean: ## Remove generated files | |
@echo "cleaning local files" | |
@rm -rf .cache | |
@find . -name '*.pyc' -delete | |
lint: ## Run the linter (flake8) | |
flake8 | |
release: ## Bump versions for release e.g. make release type=(major|minor|patch) | |
# type = (major | minor | patch) | |
bump2version $(type) project_name/__init__.py | |
requirements: ## Install base requirements | |
poetry install | |
test-unit: requirements ## Execute unit tests | |
pytest --cov=./project-name --cov-fail-under 70 --cov-report term-missing --cov-report xml tests/unit/ -v | |
upload: ## Upload dist to pypi | |
poetry build | |
poetry publish |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define HELP | |
Usage: | |
make clean - Remove generated files | |
make lint - run the linter (flake8) | |
make release - Bump versions for release e.g. make release type=(major|minor|patch) | |
make requirements - Install base requirements | |
make test-requirements - Install project test requirements | |
make test-unit - Execute unit tests | |
make upload - Upload dist to pypi | |
endef | |
export HELP | |
all help: | |
@echo "$$HELP" | |
clean: | |
rm -rf .cache | |
find . -name '*.pyc' -delete | |
flake8: | |
flake8 | |
release: | |
# type = (major | minor | patch) | |
bump2version $(type) project_name/__init__.py | |
requirements: | |
pip3 install -r requirements/base.txt | |
test-requirements: | |
pip3 install -r requirements/test.txt | |
test-unit: test-requirements | |
pytest --cov=./project-name --cov-fail-under 70 --cov-report term-missing --cov-report xml tests/unit/ -v | |
upload: | |
python3 setup.py sdist bdist_wheel | |
twine upload dist/* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment