From f63695c78a3c73bdc47da34cff10bc61a28752c7 Mon Sep 17 00:00:00 2001 From: Eric Power Date: Fri, 1 Mar 2024 14:40:33 -0800 Subject: [PATCH] Adding pre-commit with formatting, linting, and tests. --- .pre-commit-config.yaml | 34 ++++++++++++++++++++++++++++++++++ Makefile | 7 +++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..7a28c12 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,34 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: trailing-whitespace + - id: check-executables-have-shebangs + - id: check-yaml + - id: check-json + - id: pretty-format-json + - id: check-toml + - id: name-tests-test + args: [--unittest] + - id: no-commit-to-branch + args: [--branch, main] + - id: requirements-txt-fixer + - id: end-of-file-fixer + - id: check-added-large-files + - repo: local + hooks: + - id: make-format + name: Format Code + entry: make format + language: system + types: [python] + - id: make-lint + name: Lint Code + entry: make lint + language: system + types: [python] + - id: make-test + name: Test Code w/ Coverage + entry: make test + language: system + types: [python] diff --git a/Makefile b/Makefile index a42df87..e95b954 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ VENV := venv APP_DIR := app # default target, when make executed without arguments -all: lint test format +all: format lint test $(VENV)/bin/activate: python3 -m venv $(VENV) @@ -11,6 +11,9 @@ $(VENV)/bin/activate: venv: $(VENV)/bin/activate +format: venv + ./$(VENV)/bin/black app tests + lint: venv ./$(VENV)/bin/mypy app --strict ./$(VENV)/bin/flake8 app tests @@ -24,7 +27,7 @@ test: venv ./$(VENV)/bin/coverage report --show-missing --fail-under=100 run: venv - touch .gitignore # used to force make to run command every time + touch .gitignore # used to force make to run command every time $(shell yq -o='shell' '.env_variables' config/local.toml \ | tr '\n' ' ' \ | sed 's|$$|./$(VENV)/bin/python3 serve.py|')