diff --git a/Makefile.python b/Makefile.python index 2a4d0fa..f05e488 100644 --- a/Makefile.python +++ b/Makefile.python @@ -1,48 +1,54 @@ # -*- mode: Makefile -*- PYMODULE := $(shell basename `pwd` | sed 's/-/./g') PYDIR := $(shell basename `pwd` | sed 's%-%/%g') PYTHON_BIN := $(shell test -d bin/ && find bin/ -type f -executable | xargs egrep -H '^\#.*python' | cut -f 1 -d :) TEST_DIRS := $(shell find . -name tests -type d) NOSE = python3 -m nose NOSEFLAGS = -sv --with-doctest CODESPELL = codespell CODESPELLFLAGS = FLAKE = python3 -m flake8 FLAKEFLAGS = LINT = pylint3 LINTFLAGS = --rcfile=../pylintrc all: .PHONY: test test: $(NOSE) $(NOSEFLAGS) $(TEST_DIRS) .PHONY: coverage coverage: $(NOSE) $(NOSEFLAGS) --with-coverage --cover-package $(PYMODULE) --cover-inclusive --cover-branches $(TEST_DIRS) .PHONY: check check-flake check-codespell check: check-flake check-codespell check-flake: $(FLAKE) $(FLAKEFLAGS) swh $(PYTHON_BIN) check-codespell: find . -name '*.py' | xargs $(CODESPELL) $(CODESPELLFLAGS) +.PHONY: check-staged +check-staged: + git diff -z --staged --name-only -- '*.py' \ + | xargs -0 -L1 -i'{}' /bin/sh -c \ + "git show ':{}' | $(FLAKE) $(FLAKEFLAGS) --stdin-display-name '{}' -" + .PHONY: lint lint: $(LINT) $(LINTFLAGS) $(PYMODULE) .PHONY: docs docs: make -C docs .PHONY: distclean # clean up Python bytecode files. Also consider random *.pyc files, in case # Python 2.x has been run by mistake distclean: find . -type d -name __pycache__ | xargs rm -rf find . -type f -name '*.pyc' -delete diff --git a/bin/git-add-pre-commit-hook b/bin/git-add-pre-commit-hook index 530d4fd..427040d 100755 --- a/bin/git-add-pre-commit-hook +++ b/bin/git-add-pre-commit-hook @@ -1,19 +1,19 @@ #!/bin/bash if [ -z "$1" -o ! -d "$1" ] ; then echo "Usage: git-add-pre-commit-hook LOCAL_REPO_DIR" echo "E.g.: git-add-pre-commit-hook swh-core" exit 1 fi HOOK=".git/hooks/pre-commit" cd "$1" if ! [ -x "$HOOK" ] ; then cat > "$HOOK" <