From 6d77bc827a5daed9c3d5cd7e0b713ab193115f71 Mon Sep 17 00:00:00 2001 From: suzhengwei Date: Tue, 30 May 2023 17:22:23 +0800 Subject: [PATCH] add pre-commit This tool provides a extensible way to configure pre-commit hooks to do something from running linters to spell-checking and it proved to be useful. Change-Id: I77cf6c85559989bd051798e601640e0039342924 --- .pre-commit-config.yaml | 27 +++++++++++++++++++++++++++ HACKING.rst | 15 +++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..52b94266 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,27 @@ +--- +default_language_version: + # force all unspecified python hooks to run python3 + python: python3 +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.3.0 + hooks: + - id: trailing-whitespace + - id: mixed-line-ending + args: ['--fix', 'lf'] + exclude: '.*\.(svg)$' + - id: check-byte-order-marker + - id: check-merge-conflict + - id: debug-statements + - id: check-yaml + files: .*\.(yaml|yml)$ + - repo: local + hooks: + - id: flake8 + name: flake8 + additional_dependencies: + - hacking>=3.0.1,<3.1.0 + language: python + entry: flake8 + files: '^.*\.py$' + exclude: '^(doc|releasenotes|tools)/.*$' diff --git a/HACKING.rst b/HACKING.rst index b507140e..21d00108 100644 --- a/HACKING.rst +++ b/HACKING.rst @@ -45,3 +45,18 @@ Masakari Specific Commandments - [M332] Yield must always be followed by a space when yielding a value. - [M333] Policy registration should be in the central location ``masakari/policies/`` - [M334] Do not use the oslo_policy.policy.Enforcer.enforce() method. + +Use of pre-commit checks +------------------------ +`pre-commit`_ is a software tool that allows us to manage pre-commit checks as +part of the Git repository's configuration +and to run checks as Git pre-commit hooks (or other types of Git hooks) +automatically on developer machines. +It helps to catch and fix common issues before they get pushed to the server. +After the installation of the tool (e.g. on Fedora via +`sudo dnf install pre-commit`) simply `cd` to the Git repository and run +`pre-commit install` to let the tool install its Git pre-commit hook. +From now on these predefined checks will run on files that you change in new +Git commits. + +.. _pre-commit: https://pre-commit.com/