-
-
Notifications
You must be signed in to change notification settings - Fork 177
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Utility to format Python code before pushing new commits
- Loading branch information
1 parent
4245137
commit 8b53e78
Showing
1 changed file
with
28 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#!/bin/bash | ||
|
||
BASE_REVISION=$1 | ||
|
||
echo $BASE_REVISION | ||
|
||
|
||
if [ -z "$BASE_REVISION" ]; then | ||
BASE_REVISION="beta" | ||
elif [ "$BASE_REVISION" == "-l" ] || [ "$BASE_REVISION" == "--last" ]; then | ||
BASE_REVISION=$(git log --oneline| head -n 1 | awk '{ print $1}') | ||
fi | ||
|
||
# First, do not touch formatting but fix: | ||
# - single/double quotes (--select Q) | ||
# - sort imports (--select I) | ||
# - unused imports (--select F401) | ||
# - deprecated `mock` (--select UP026) | ||
# - extraneous-parentheses (--select UP034) | ||
# - Unnecessary parentheses after class definition (--select UP039) | ||
# - Indentation warning (--select W1) | ||
# - No newline at end of file (--select W292) | ||
echo "Using ruff..." | ||
git diff --name-only "$BASE_REVISION" | grep '.py' | xargs ruff check --select Q --select I --select F401 --select UP026 --select UP034 --select UP039 --select W292 --fix | ||
|
||
# Applying Black format on changes (since $BASE_REVISION) | ||
echo "Using darker..." | ||
darker -i -r "$BASE_REVISION" |