Skip to content

Instantly share code, notes, and snippets.

@thoroc
Last active September 3, 2020 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thoroc/c9ebff205cf1b74c1c9f059518d7838b to your computer and use it in GitHub Desktop.
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
.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
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