Skip to content

Commit

Permalink
Add a pre-commit hook (#3150)
Browse files Browse the repository at this point in the history
  • Loading branch information
tabdar-khan authored Mar 28, 2024
1 parent 540adef commit 67ca7ab
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
repos:
- repo: local
hooks:
- id: format-code
name: Format Code
entry: ./dev/format.sh
language: script
# Ensures the script runs from the repository root:
pass_filenames: false
stages: [commit]

- id: run-tests
name: Run Tests
entry: ./dev/test.sh
language: script
# Ensures the script runs from the repository root:
pass_filenames: false
stages: [commit]
27 changes: 27 additions & 0 deletions doc/source/contributor-tutorial-get-started-as-a-contributor.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,33 @@ Run Linters and Tests

$ ./dev/test.sh

Add a pre-commit hook
~~~~~~~~~~~~~~~~~~~~~

Developers may integrate a pre-commit hook into their workflow utilizing the `pre-commit <https://pre-commit.com/#install>`_ library. The pre-commit hook is configured to execute two primary operations: ``./dev/format.sh`` and ``./dev/test.sh`` scripts.

There are multiple ways developers can use this:

1. Install the pre-commit hook to your local git directory by simply running:

::
$ pre-commit install

- Each ``git commit`` will trigger the execution of formatting and linting/test scripts.
- If in a hurry, bypass the hook using ``--no-verify`` with the ``git commit`` command.
::
$ git commit --no-verify -m "Add new feature"
2. For developers who prefer not to install the hook permanently, it is possible to execute a one-time check prior to committing changes by using the following command:

::

$ pre-commit run --all-files
This executes the formatting and linting checks/tests on all the files without modifying the default behavior of ``git commit``.

Run Github Actions (CI) locally
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ check-wheel-contents = "==0.4.0"
GitPython = "==3.1.32"
PyGithub = "==2.1.1"
licensecheck = "==2024"
pre-commit = "==3.5.0"

[tool.isort]
line_length = 88
Expand Down

0 comments on commit 67ca7ab

Please sign in to comment.