-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preliminary work for applying black to the code base
- Loading branch information
1 parent
d9b7bce
commit ec9bbeb
Showing
4 changed files
with
83 additions
and
3 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,33 @@ | ||
# Minimal Makefile for automating recurring tasks during development | ||
# | ||
# Copyright (c) 2023, Till Biskup | ||
# 2023-12-06 | ||
|
||
.PHONY: docs tests help | ||
.DEFAULT_GOAL := help | ||
|
||
help: | ||
@echo "This makefile automates different recurring tasks" | ||
@echo "" | ||
@echo "The following targets are available:" | ||
@echo "" | ||
@echo "docs - create documentation using Sphinx" | ||
@echo "tests - run unittests" | ||
@echo "check - check code using prospector" | ||
@echo "black - format code using Black" | ||
|
||
docs: | ||
@echo "Create documentation using Sphinx" | ||
$(MAKE) -C docs html | ||
|
||
tests: | ||
@echo "Run unittests" | ||
cd tests/ && python -m unittest discover -s . -t . | ||
|
||
check: | ||
@echo "Check code using prospector... this may take a while" | ||
prospector | ||
|
||
black: | ||
@echo "Automatically format code using Black" | ||
black -l 78 . --extend-exclude templates |
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 |
---|---|---|
@@ -1 +1 @@ | ||
0.10.0.dev3 | ||
0.10.0.dev4 |
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,43 @@ | ||
#!/usr/bin/env bash | ||
# | ||
# Autoformat Python files currently in git staging area. | ||
# | ||
# Intended for using in pre-commit hook | ||
# | ||
# Formatter, formatter options and exclude pattern can be set. | ||
# | ||
# Note that due to calling the formatter explicitly for files, exclude patterns | ||
# via formatter options are likely to not work. Hence the list of files to be | ||
# reformatted needs to be filtered beforehand. | ||
# | ||
# Existence of the formatter is checked, and if it is not present, | ||
# the script silently exits. | ||
# | ||
# Only Python files in the staging area are reformatted and afterwards | ||
# re-added to the staging area. | ||
# | ||
# Copyright (c) 2023, Till Biskup | ||
# 2023-12-06 | ||
|
||
FORMATTER="black" | ||
FORMATTER_OPTIONS="-l 78" | ||
EXCLUDE_PATTERN="templates" | ||
|
||
if ! command -v $FORMATTER &> /dev/null | ||
then | ||
exit | ||
fi | ||
|
||
if \[ -n "$EXCLUDE_PATTERN" \]; | ||
then | ||
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR -- '*.py' | grep -v $EXCLUDE_PATTERN) | ||
else | ||
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR -- '*.py') | ||
fi | ||
|
||
for file in $CHANGED_FILES | ||
do | ||
echo "Reformat '$file' using '$FORMATTER $FORMATTER_OPTIONS'" | ||
$FORMATTER $FORMATTER_OPTIONS "$file" | ||
git add "$file" | ||
done |
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