Skip to content

Commit

Permalink
Merge pull request #70 from iacopy/69-pre-commit-black
Browse files Browse the repository at this point in the history
justfile, pre-commit-hook: add black-hook recipe
  • Loading branch information
iacopy authored Sep 28, 2024
2 parents 22619b8 + 4c2c2a2 commit 39d1fe3
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,10 @@ install-hooks:
# install pre-push hook
echo "just test" > .git/hooks/pre-push&&chmod +x .git/hooks/pre-push

black-hook:
# ensures that all your commits contain Python code formatted according to Black’s rules.
cp pre-commit-black .git/hooks/pre-commit&&chmod +x .git/hooks/pre-commit

# bootstrap your virtualenv (deprecated)
setenv VIRTUALENV:
@echo Create virtualenv and use it to install requirements
Expand Down
10 changes: 10 additions & 0 deletions pre-commit-black
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh

# Run Black on all Python files
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')
if [ -n "$files" ]; then
echo "Running Black on Python files..."
black $files
# Add the formatted files back to the staging area
git add $files
fi

0 comments on commit 39d1fe3

Please sign in to comment.