From 5855c931ca84088a5e7a6592d3143fc7ee05c69c Mon Sep 17 00:00:00 2001 From: chewingbever Date: Fri, 28 Aug 2020 13:15:08 +0200 Subject: [PATCH] Added pre-commit hook --- .githooks/pre-commit | 11 +++++++++++ Makefile | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100755 .githooks/pre-commit diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 0000000..a4d593c --- /dev/null +++ b/.githooks/pre-commit @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This hooks runs tests and checks if the linter doesn't hate you + +# Linting +printf "flake8....." +make lint > /dev/null 2>&1 && printf "OK!\n" || { printf "Fail." && exit 1; } + +# Running tests +printf "pytest....." +make test > /dev/null 2>&1 && printf "OK!\n" || { printf "Fail." && exit 1; } diff --git a/Makefile b/Makefile index 62bc4ff..e4b0b93 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ DOCS=docs # Interpreter to create venv with INTERPRETER=python3.8 -all: run +all: build-venv # =====VENV===== @@ -38,10 +38,13 @@ clean-cache: @ echo "Removing caches..." @ find . -type d \( -name "__pycache__" -o -name ".pytest_cache" \) -exec rm -r "{}" + +# Removed generation documentation clean-docs: @ echo "Removing documentation build..." @ [ ! -e "$(DOCS)/build" ] || rm -r "$(DOCS)/build" + @ [ ! -e "$(DOCS)/source/apidoc" ] || rm -r "$(DOCS)/source/apidoc" +# Remove build leftovers (not dist) clean-setup: @ echo 'Removing build artifacts...' @ [ ! -e "build" ] || rm -rf build @@ -49,14 +52,22 @@ clean-setup: # =====DOCS===== +# # Generate documentation docs: docs/source/conf.py docs/source/index.rst build-venv @ "$(VENV)/bin/sphinx-apidoc" -f -o "$(DOCS)/source/apidoc" "$(SRC)" @ "$(VENV)/bin/sphinx-build" "$(DOCS)/source" "$(DOCS)/build" # =====TESTS===== +# Run tests test: pytest.ini build-venv - @ "$(VENV)/bin/pytest" --color=yes + @ "$(VENV)/bin/pytest" --color=auto + + +# =====LINTING===== +# Run flake8 +lint: build-venv + @ "$(VENV)/bin/flake8" "$(SRC)"/**/*.py # =====PACKAGING=====