From f8379b8b672b9a94f555f6243240ddf221d14f51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Havelka?= Date: Mon, 31 Jul 2023 16:20:26 +0200 Subject: [PATCH] =?UTF-8?q?Kontroly=20Pythonu=20u=C5=BE=20nevedeme?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _git_hooks/README.md | 16 ------------ _git_hooks/pre-commit | 30 --------------------- _git_hooks/update | 61 ------------------------------------------- 3 files changed, 107 deletions(-) delete mode 100644 _git_hooks/README.md delete mode 100755 _git_hooks/pre-commit delete mode 100755 _git_hooks/update diff --git a/_git_hooks/README.md b/_git_hooks/README.md deleted file mode 100644 index e74e5c53..00000000 --- a/_git_hooks/README.md +++ /dev/null @@ -1,16 +0,0 @@ -git hooks -========= - -Kontrola stylu pythoních zdrojáků pomocí flake8. Kontrolujeme jen změny, -abychom nenutili lidi dělat nesouvisející úpravy, které by rozbíjely historii -(git blame). - -pre-commit ----------- -* kontrola změn před commitnutím -* instalace: lokálně zkopírovat do .git/hooks (musí být spustitelný) - -update ------- -* kontrola změn přicházejících s pushem -* instalace: na atreyi zkopírovat do /akce/MaM/MaMweb/mamweb.git/hooks diff --git a/_git_hooks/pre-commit b/_git_hooks/pre-commit deleted file mode 100755 index f78840d4..00000000 --- a/_git_hooks/pre-commit +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -# -# Git hook script to verify what is about to be committed. -# Checks that the changes don't introduce new flake8 errors. - -TMPDIFF=`tempfile` -FLAKE8="`git rev-parse --show-toplevel`/bin/flake8" - -status=0 - -# select only changed python files which are not migrations -changed=`git diff --cached --name-only | grep 'py$' | grep -v 'migrations/[0-9]'` -if [ -z $changed ] ; then - # Nothing to check. Note the exit is necessary -- we would not pass any - # paths to git diff below and it would output the diff unfiltered. - exit 0 -fi - -git diff --unified=1 --cached HEAD -- $changed > $TMPDIFF - -# only do the check when there are some changes to be commited -# otherwise flake8 would hang waiting for input -if [ -s $TMPDIFF ] ; then - cat $TMPDIFF | $FLAKE8 --diff - status=$? -fi - -rm -f $TMPDIFF - -exit $status diff --git a/_git_hooks/update b/_git_hooks/update deleted file mode 100755 index c700a1b1..00000000 --- a/_git_hooks/update +++ /dev/null @@ -1,61 +0,0 @@ -#!/bin/sh - -# git update hook to check that pushed changes don't introduce new flake8 -# errors - -# --- Command line -refname="$1" -oldrev="$2" -newrev="$3" - -# --- Safety check -if [ -z "$GIT_DIR" ]; then - echo "Don't run this script from the command line." >&2 - echo " (if you want, you could supply GIT_DIR then run" >&2 - echo " $0 )" >&2 - exit 1 -fi - -if [ -z "$refname" -o -z "$oldrev" -o -z "$newrev" ]; then - echo "usage: $0 " >&2 - exit 1 -fi - - -TMPDIR=`mktemp -d` -TMPDIFF=`tempfile` - -[ $refname != "refs/heads/master" -a $refname != "refs/heads/stable" ] && exit 0 - -# select only changed python files which are not migrations -changed=`git diff --name-only $oldrev $newrev | grep 'py$' | grep -v 'migrations/[0-9]'` -if [ -z $changed ] ; then - # Nothing to check. Note the exit is necessary -- we would not pass any - # paths to git diff below and it would output the diff unfiltered. - exit 0 -fi - -git diff --unified=1 $oldrev $newrev -- $changed >${TMPDIFF} - -# there is no working tree in bare git repository, so we recreate it for flake8 -git archive $newrev | tar -x -C ${TMPDIR} - -cd ${TMPDIR} -# report only errors on lines in diff -# (if threre was flake8 installed on atrey, we could just call flake8) -/akce/MaM/WWW/mamweb-test/bin/flake8 --diff <${TMPDIFF} -status=$? -if [ $status != 0 ] ; then - echo - echo -n "Změny, které se snažíte pushnout, obsahují kód v pythonu " - echo -n "nevyhovující flake8 (viz výše). Opravte je a zkuste to znovu. " - echo -n "Nezapomeňte, že můžete editovat historii (git commit --amend, " - echo -n "git rebase -i). Pokud byste chybu příště raději odhalili už při " - echo "commitu, zkopírujte si pre-commit hook z _git_hooks do .git/hooks." - echo -fi - -rm -rf ${TMPDIR} -rm -f ${TMPDIFF} - -exit $status