From bb3fbb5d4ce468eb4a4860180a54a3ee1483235e Mon Sep 17 00:00:00 2001 From: Priyanshi Gaur Date: Wed, 13 Mar 2024 04:26:38 +0530 Subject: [PATCH] Add documentation for pre-commit hook Signed-off-by: Priyanshi Gaur --- .pre-commit-config.yaml | 3 +-- README.md | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d8e7662..af0220a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -36,7 +36,6 @@ repos: - --fix=no - id: trailing-whitespace -repos: - repo: local hooks: - id: black @@ -55,4 +54,4 @@ repos: name: "isort" entry: isort --filter-files language: system - types: ["file", "python", "text"] \ No newline at end of file + types: ["file", "python", "text"] diff --git a/README.md b/README.md index 8a27312..f58dd4f 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,26 @@ follow these steps: ### Static analysis +#### Using [`pre-commit`][pre-commit] +1. Install pre-commit + +- Using pip: + ```shell + pip install pre-commit + ``` +- Using homebrew: + ```shell + brew install pre-commit + ``` + +2. Install the git hook scripts + ```shell + pre-commit install + ``` + +It will run on every commit automatically. + +#### Using [`dev/tools.sh`][tools-sh] helper script The [`dev/tools.sh`][tools-sh] helper script runs the static analysis tools (`black`, `flake8`, and `isort`): ```shell @@ -89,6 +109,7 @@ directories to check: ``` [tools-sh]: /dev/tools.sh +[pre-commit]: https://pre-commit.com/ ### Resources @@ -100,12 +121,14 @@ directories to check: - [isort][isort]: _A Python utility / library to sort imports_ - (It doesn't import any libraries, it only sorts and formats them.) - [ppypa/pipenv][pipenv]: _Python Development Workflow for Humans._ +- [pre-commit][pre-commit]: A framework for managing and maintaining multi-language pre-commit hooks. [ccospyguide]: https://opensource.creativecommons.org/contributing-code/python-guidelines/ [black]: https://github.com/psf/black [flake8]: https://gitlab.com/pycqa/flake8 [isort]: https://pycqa.github.io/isort/ [pipenv]: https://github.com/pypa/pipenv +[pre-commit]: https://pre-commit.com/ ### GitHub Actions @@ -115,7 +138,7 @@ GitHub Actions workflow performs static analysis (`black`, `flake8`, and `isort`) on committed changes. The workflow is triggered automatically when you push changes to the main branch or open a pull request. -[workflow-static-analysis]: .github/workflows/python_static_analysis.yml +[workflow-static-analysis]: .github/workflows/static_analysis.yml ## Data sources