Merge branch '2-devop-env'

master
Jef Roosens 2021-04-02 14:49:06 +02:00
commit 5287fd818e
Signed by: Jef Roosens
GPG Key ID: B580B976584B5F30
5 changed files with 91 additions and 0 deletions

23
.hooks/commit-msg 100755
View File

@ -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

14
.hooks/pre-commit 100755
View File

@ -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

41
Makefile 100644
View File

@ -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

View File

@ -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

2
requirements.txt 100644
View File

@ -0,0 +1,2 @@
# Web framework
Flask~=1.1.2