Skip to content

Commit

Permalink
chore(repo): Add lefthook
Browse files Browse the repository at this point in the history
This commit adds [Lefthook](https://github.com/evilmartians/lefthook/)
as a way to manage Git Hooks and automatically run ruff, PyRight and a
commit message validator on commit.

For now, `ruff` and `pyright` validators are turned off since there are
many errors. They will be turned on once we have fixed the errors.
  • Loading branch information
serramatutu committed Apr 29, 2024
1 parent fd533ab commit 5aa200d
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .lefthook/commit-msg/template-checker
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

# This script takes in some text from STDIN (presumably a commit message)
# and validates whether it adheres to our commit message format.
#
# We are using Conventional Commits as a commit message format.
# See: https://www.conventionalcommits.org/en/v1.0.0/

INPUT_FILE=$1

PATTERN="^((chore|ci|docs|feat|fix|perf|refactor|revert|test)(\(\w+\))?(!)?(: (.*\s*)*))"
grep -E "$PATTERN" $INPUT_FILE
MATCH=$?

if [ $MATCH -ne 0 ]; then
echo "Bad commit message. Must be in Conventional Commits style.\n\nSee: https://www.conventionalcommits.org/en/v1.0.0/"
exit 1
fi

5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,8 @@ pip install -e .
```

Working out from the `jafgen` command, you can see the main entrypoint in `jaffle_shop_generator/cli.py`. This calls the simulation found in `jafgen/simulation.py`. The simulation is where most of the magic happens.

We recommend installing our githook scripts locally. To do that, install [Lefthook](https://github.com/evilmartians/lefthook) and run
```
lefthook install
```
1 change: 1 addition & 0 deletions dev-requirements.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ruff
pytest
pyright
setuptools
8 changes: 8 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# This file was autogenerated by uv via the following command:
# uv pip compile dev-requirements.in -o dev-requirements.txt
exceptiongroup==1.2.1
# via pytest
iniconfig==2.0.0
# via pytest
nodeenv==1.8.0
# via pyright
packaging==24.0
# via pytest
pluggy==1.5.0
# via pytest
pyright==1.1.360
pytest==8.1.1
ruff==0.4.2
setuptools==69.5.1
# via nodeenv
tomli==2.0.1
# via pytest
10 changes: 10 additions & 0 deletions lefthook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pre-commit:
commands:
# ruff:
# run: .venv/bin/ruff check --fix
# pyright:
# run: .venv/bin/pyright

commit-msg:
template-checker:
runner: bash
19 changes: 19 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,22 @@ jafgen = "jafgen.cli:app"

[project.optional-dependencies]
dev = ["ruff", "pytest"]

[tool.ruff.lint]
select = [
"E", # Pycodestyle
"F", # Pyflakes
"W", # Whitespace
"D", # Pydocs
"T20", # Print statements
"I", # isort
]
# Allow autofix for all enabled rules (when `--fix`) is provided.
fixable = [
"A", "B", "C", "D", "E", "F", "G", "I", "N", "Q", "S", "T", "W", "ANN", "ARG", "BLE", "COM", "DJ", "DTZ", "EM",
"ERA", "EXE", "FBT", "ICN", "INP", "ISC", "NPY", "PD", "PGH", "PIE", "PL", "PT", "PTH", "PYI", "RET", "RSE", "RUF",
"SIM", "SLF", "TCH", "TID", "TRY", "UP", "YTT"
]

[tool.pydocstyle]
convention = "google"

0 comments on commit 5aa200d

Please sign in to comment.