From f78520f7d04918c314644feba7db339425390d7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleix=20Conchillo=20Flaqu=C3=A9?= Date: Wed, 15 Jan 2025 13:44:21 -0800 Subject: [PATCH] add pre-commit hooks Fixes #945 --- .pre-commit-config.yaml | 7 +++++++ README.md | 13 +++++++++++-- dev-requirements.txt | 1 + pyproject.toml | 2 +- scripts/pre-commit.sh | 3 +++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 .pre-commit-config.yaml create mode 100755 scripts/pre-commit.sh diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 000000000..6906b571b --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,7 @@ +repos: + - repo: local + hooks: + - id: ruff-format-hook + name: Check ruff formatting + entry: sh scripts/pre-commit.sh + language: system diff --git a/README.md b/README.md index ae7a91538..2c16f24c5 100644 --- a/README.md +++ b/README.md @@ -160,15 +160,24 @@ From the root of this repo, run the following: ```shell pip install -r dev-requirements.txt -python -m build ``` -This builds the package. To use the package locally (e.g. to run sample files), run +This will install the necessary development dependencies. Also, make sure you install the git pre-commit hooks: + +```shell +pre-commit install +``` + +The hooks will just save you time when you submit a PR by making sure your code follows the project rules. + +To use the package locally (e.g. to run sample files), run: ```shell pip install --editable ".[option,...]" ``` +The `--editable` option makes sure you don't have to run `pip install` again and you can just edit the project files locally. + If you want to use this package from another directory, you can run: ```shell diff --git a/dev-requirements.txt b/dev-requirements.txt index ba5023f07..2a9c68581 100644 --- a/dev-requirements.txt +++ b/dev-requirements.txt @@ -1,6 +1,7 @@ build~=1.2.2 grpcio-tools~=1.69.0 pip-tools~=7.4.1 +pre-commit~=4.0.1 pyright~=1.1.392 pytest~=8.3.4 ruff~=0.9.1 diff --git a/pyproject.toml b/pyproject.toml index d2dba8b98..ee842a533 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,7 +93,7 @@ local_scheme = "no-local-version" fallback_version = "0.0.0-dev" [tool.ruff] -exclude = ["*_pb2.py"] +exclude = [".git", "*_pb2.py"] line-length = 100 [tool.ruff.lint] diff --git a/scripts/pre-commit.sh b/scripts/pre-commit.sh new file mode 100755 index 000000000..22f00313d --- /dev/null +++ b/scripts/pre-commit.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +NO_COLOR=1 ruff format --diff