diff --git a/.hooks/commit-msg b/.hooks/commit-msg new file mode 100755 index 0000000..284ee8d --- /dev/null +++ b/.hooks/commit-msg @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +# This hook checks if the commit message ends with an issue number, and if not, +# tries to derive that number from the branch name + +branch=`git rev-parse --abbrev-ref HEAD` + +# This check doesn't need to run when commiting to develop/master +[[ "$branch" =~ ^master|develop$ ]] && exit 0 + +issue_num=`echo "$branch" | grep -Po '^[0-9]+(?=-)'` + +# Check if issue number is already present +if ! grep -q '([0-9]\+)$' "$1"; then + # Error out if we can't derive issue number + [[ -z "$issue_num" ]] && { + >&2 echo "Couldn't derive issue number from branch. Please add one manually."; + exit 1; + } + + # Append issue number, and remove all comments + echo "[#$issue_num]" "$(cat "$1")" > "$1" +fi diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 0000000..3bd0b24 --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +# This hook lints the code, and if we're on develop or master, also forces the tests to pass. + + +branch=`git rev-parse --abbrev-ref HEAD` + +# TODO should we add release branches here as well? +if [[ "$branch" =~ ^master|develop$ ]]; then + make test > /dev/null 2>&1 || { + >&2 echo "Tests failed. check 'make test' for more info."; + exit 1; + } +fi diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..da1e6ec --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# =====CONFIG===== +PYTHON := python3.9 +# This can't contain spaces (I think) +VENV := venv + + +# By default, just create the venv when needed +all: venv + + +# Create the venv +$(VENV)/bin/activate: requirements.txt requirements-dev.txt + @ '$(PYTHON)' -m venv '$(VENV)' + @ '$(VENV)'/bin/pip install -r requirements.txt -r requirements-dev.txt + +# Convenient alias for the venv +venv: $(VENV)/bin/activate +.PHONY: venv + + +# Remove the venv +clean: + @ rm -rf '$(VENV)' + + +# Run the Flask server +# TODO +run: venv + + +# Format the codebase using black +format: venv + @ '$(VENV)/bin/python' -m black src + +# Lint the codebase using flake8 +lint: venv + @ '$(VENV)/bin/python' -m flake8 src + +# Run rests using pytest +# TODO +test: venv diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..d4647f1 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,11 @@ +# Formatter +black~=20.8b1 + +# Linter +flake8~=3.9.0 + +# Testing suite +pytest~=6.2.2 + +# Language server +jedi~=0.18.0 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..dc4b804 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +# Web framework +Flask~=1.1.2