Skip to content
Snippets Groups Projects
Commit 0c255105 authored by Martin Burchell's avatar Martin Burchell
Browse files

Add pre-commit hook for isort / pylava

parent 5b8e2cb5
No related branches found
No related tags found
1 merge request!124Staging
Pipeline #5526 passed
Makefile 0 → 100644
PROJECT_NAME := internewshid
MANAGEPY := python manage.py
PIPENVRUN := pipenv run
PROJECT_ROOT := .
SOURCE_DIR := $(PROJECT_ROOT)/$(PROJECT_NAME)/
lint:
@$(PIPENVRUN) pylava -o setup.cfg $(SOURCE_DIR)
.PHONY: lint
sort:
$(PIPENVRUN) isort -c -rc --diff -sp setup.cfg $(SOURCE_DIR)
.PHONY: sort
test:
@$(PIPENVRUN) pytest --cov=$(PROJECT_NAME)
.PHONY: test
#!/bin/bash
# pre-commit hook script that runs lint & sort
#
# Usage: ln -s ./bin/pre-commit-hook.sh .git/hooks/pre-commit
#
# This does not run tests, as it would be slow to do at every commit.
# Linting and sorting however ensures we don't get cosmetic commits later
# that break git blame history for no reason.
#
# This script doesn't stash changes to avoid un-expected side effects.
# So if you have non-commited changes that break this you'll need to
# stash your changes before commiting.
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m' # No Color
make lint && make sort
RESULT=$?
if [ $RESULT -ne 0 ]; then
echo -e "${RED}lint/sort failed; commit aborted. See errors above.${NC}\n"
exit 1
fi
echo -e "${GREEN}lint/sort success.${NC}\n"
exit 0
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment