From 6fc0e2c15facb4be296c11a0b80a2ea2e1bef7c9 Mon Sep 17 00:00:00 2001 From: deeplow Date: Wed, 20 Jul 2022 08:59:37 +0100 Subject: [PATCH] add Makefile with linters (black & isort) - borrowed makefile self-help code from SecureDrop - considered windows dev env case: GNU make available via Cygwin --- Makefile | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..9c97fb8 --- /dev/null +++ b/Makefile @@ -0,0 +1,37 @@ +.PHONY: lint-black +lint-black: ## check python source code formatting issues, with black + black --check --diff ./ + +.PHONY: lint-black-apply +lint-black-apply: ## apply black's source code formatting suggestions + black ./ + +.PHONY: lint-isort +lint-isort: ## check imports are organized, with isort + isort --check-only ./ + +.PHONY: lint-isort-apply +lint-isort-apply: ## apply isort's imports organization suggestions + isort ./ + +.PHONY: lint +lint: lint-black lint-isort ## check the code with various linters + +.PHONY: lint-apply +lint-apply: lint-black-apply lint-isort-apply ## apply all the linter's suggestions + +# Makefile self-help borrowed from the securedrop-client project +# Explaination of the below shell command should it ever break. +# 1. Set the field separator to ": ##" and any make targets that might appear between : and ## +# 2. Use sed-like syntax to remove the make targets +# 3. Format the split fields into $$1) the target name (in blue) and $$2) the target descrption +# 4. Pass this file as an arg to awk +# 5. Sort it alphabetically +# 6. Format columns with colon as delimiter. +.PHONY: help +help: ## Print this message and exit. + @printf "Makefile for developing and testing dangerzone.\n" + @printf "Subcommands:\n\n" + @awk 'BEGIN {FS = ":.*?## "} /^[0-9a-zA-Z_-]+:.*?## / {printf "\033[36m%s\033[0m : %s\n", $$1, $$2}' $(MAKEFILE_LIST) \ + | sort \ + | column -s ':' -t