add pre-commit hooks

Fixes #945
This commit is contained in:
Aleix Conchillo Flaqué
2025-01-15 13:44:21 -08:00
parent bb4766455d
commit f78520f7d0
5 changed files with 23 additions and 3 deletions

7
.pre-commit-config.yaml Normal file
View File

@@ -0,0 +1,7 @@
repos:
- repo: local
hooks:
- id: ruff-format-hook
name: Check ruff formatting
entry: sh scripts/pre-commit.sh
language: system

View File

@@ -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

View File

@@ -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

View File

@@ -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]

3
scripts/pre-commit.sh Executable file
View File

@@ -0,0 +1,3 @@
#!/bin/sh
NO_COLOR=1 ruff format --diff