From c32c9035d81b47447ada4aa92edccc556a024b70 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 2 Apr 2021 13:49:40 +0200 Subject: [PATCH 1/5] Added Makefile & first requirements (#2) --- Makefile | 41 +++++++++++++++++++++++++++++++++++++++++ requirements-dev.txt | 11 +++++++++++ requirements.txt | 2 ++ 3 files changed, 54 insertions(+) create mode 100644 Makefile create mode 100644 requirements-dev.txt create mode 100644 requirements.txt 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 From 6acbb4ad62ae8ad34c4794a4119e9212083638a3 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 2 Apr 2021 14:03:20 +0200 Subject: [PATCH 2/5] Wrote two git hooks (#2) --- .hooks/commit-msg | 18 ++++++++++++++++++ .hooks/pre-commit | 4 ++++ 2 files changed, 22 insertions(+) create mode 100755 .hooks/commit-msg create mode 100755 .hooks/pre-commit diff --git a/.hooks/commit-msg b/.hooks/commit-msg new file mode 100755 index 0000000..ec6c4c9 --- /dev/null +++ b/.hooks/commit-msg @@ -0,0 +1,18 @@ +#!/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` +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 + echo "(#$issue_num)" >> "$1" +fi diff --git a/.hooks/pre-commit b/.hooks/pre-commit new file mode 100755 index 0000000..32d1be5 --- /dev/null +++ b/.hooks/pre-commit @@ -0,0 +1,4 @@ +#!/usr/bin/env bash + +# Just lint the code before committing +make lint From e2493e7b1966d4f50548eed3c6d4c1e126ea85e7 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 2 Apr 2021 14:06:23 +0200 Subject: [PATCH 3/5] Updated pre-commit hook to run tests on important branches (#2) --- .hooks/pre-commit | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.hooks/pre-commit b/.hooks/pre-commit index 32d1be5..0072f2c 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -1,4 +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` + # Just lint the code before committing make lint + +# TODO should we add release branches here as well? +if [[ "$branch" =~ ^master|develop$ ]]; then + make test +fi From 0007652e68f44b3e65b0bc3b2c7cbb69ce5a6b69 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 2 Apr 2021 14:45:04 +0200 Subject: [PATCH 4/5] [#2] Fixed commit hook --- .hooks/commit-msg | 7 ++++--- .hooks/pre-commit | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/.hooks/commit-msg b/.hooks/commit-msg index ec6c4c9..81ec68e 100755 --- a/.hooks/commit-msg +++ b/.hooks/commit-msg @@ -10,9 +10,10 @@ issue_num=`echo "$branch" | grep -Po '^[0-9]+(?=-)'` 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; + >&2 echo "Couldn't derive issue number from branch. Please add one manually."; + exit 1; } - # Append issue number - echo "(#$issue_num)" >> "$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 index 0072f2c..3bd0b24 100755 --- a/.hooks/pre-commit +++ b/.hooks/pre-commit @@ -5,10 +5,10 @@ branch=`git rev-parse --abbrev-ref HEAD` -# Just lint the code before committing -make lint - # TODO should we add release branches here as well? if [[ "$branch" =~ ^master|develop$ ]]; then - make test + make test > /dev/null 2>&1 || { + >&2 echo "Tests failed. check 'make test' for more info."; + exit 1; + } fi From 4ec6236e26aa22454487e23f876d1cfcbcdf2916 Mon Sep 17 00:00:00 2001 From: Jef Roosens Date: Fri, 2 Apr 2021 14:48:38 +0200 Subject: [PATCH 5/5] [#2] Commit hook won't run on master now --- .hooks/commit-msg | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.hooks/commit-msg b/.hooks/commit-msg index 81ec68e..284ee8d 100755 --- a/.hooks/commit-msg +++ b/.hooks/commit-msg @@ -4,6 +4,10 @@ # 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