From 5f8dd65f6cfcb7f33e72b9371f325801835c9c83 Mon Sep 17 00:00:00 2001 From: Stephen Finucane Date: Sat, 15 Jun 2019 16:50:35 +0100 Subject: [PATCH] Integrate 'pre-commit' This nifty tool provides a extensible way to configure pre-commit hooks to do everything from running linters to spellchecking [1] and has already been adopted by a few OpenStack projects [2]. Let's start using it as a faster, more automatic alternative to the 'fast8' tox target and iterate on it as we find more things to use it for. The 'fast8' target is not deprecated though a note is included for end-users to alert them to this great new tool. Note that the 'check-executables-have-shebangs' actually failed and highlighted that the 'contributor/development-environment.rst' document was marked as executable when it shouldn't have been. This is corrected. [1] https://pre-commit.com/ [2] https://review.opendev.org/#/q/file:.pre-commit-config.yaml Change-Id: I256e75eceeb3495dce04885ca42d16adb4160cf3 Signed-off-by: Stephen Finucane --- .pre-commit-config.yaml | 21 +++++++++++++++++++ .../contributor/development-environment.rst | 12 +++++++++++ tools/flake8wrap.sh | 7 +++++++ 3 files changed, 40 insertions(+) create mode 100644 .pre-commit-config.yaml mode change 100755 => 100644 doc/source/contributor/development-environment.rst diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000000..8b64ef712f --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,21 @@ +--- +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v2.4.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix', 'lf'] + - id: check-byte-order-marker + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: debug-statements + - id: flake8 + additional_dependencies: + - hacking>=1.1.0,<1.2.0 + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: https://github.com/Lucas-C/pre-commit-hooks + rev: v1.1.7 + hooks: + - id: remove-tabs diff --git a/doc/source/contributor/development-environment.rst b/doc/source/contributor/development-environment.rst old mode 100755 new mode 100644 index 1fc5a72212..32b8f8334e --- a/doc/source/contributor/development-environment.rst +++ b/doc/source/contributor/development-environment.rst @@ -163,6 +163,18 @@ Note that some unit and functional tests use a database. See the file ``tools/test-setup.sh`` on how the databases are set up in the OpenStack CI environment and replicate it in your test environment. +Using the pre-commit hook +========================= + +Nova makes use of the `pre-commit framework `__ to +allow running of some linters on each commit. This must be enabled locally to +function: + +.. code-block:: shell + + $ pip install --user pre-commit + $ pre-commit install --allow-missing-config + Using a remote debugger ======================= diff --git a/tools/flake8wrap.sh b/tools/flake8wrap.sh index ab3269df7f..c7478ac484 100755 --- a/tools/flake8wrap.sh +++ b/tools/flake8wrap.sh @@ -13,8 +13,15 @@ if test "x$1" = "x-HEAD" ; then shift files=$(git diff --name-only HEAD~1 | tr '\n' ' ') echo "Running flake8 on ${files}" + echo "" + echo "Consider using the 'pre-commit' tool instead." + echo "" + echo " pip install --user pre-commit" + echo " pre-commit install --allow-missing-config" + echo "" diff -u --from-file /dev/null ${files} | flake8 --diff "$@" else echo "Running flake8 on all files" + echo "" exec flake8 "$@" fi