Skip to content

Commit

Permalink
replace tools.sh with check.sh (using pre-commit)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimidRobot committed Nov 20, 2024
1 parent 7319707 commit 54f4ff9
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 34 deletions.
24 changes: 6 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,17 @@ to be run manually or with every commit:
```shell
pipenv run pre-commit install
```
- Run manually before commit:
- Run manually using helper dev script:
```shell
pipenv run pre-commit run -a
./dev/check.sh [FILE]
```
If no file(s) are specified, then it runs against all files:
```shell
./dev/check.sh
```
3. _(Optional)_ review the configuration file:
[`.pre-commit-config.yaml`](.pre-commit-config.yaml)
#### Using [`dev/tools.sh`][tools-sh] helper script
The [`dev/tools.sh`][tools-sh] helper script runs the static analysis tools
(`black`, `flake8`, and `isort`):
```shell
./dev/tools.sh
```
It can also accept command-line arguments to specify specific files or
directories to check:
```shell
./dev/tools.sh PATH/TO/MY/FILE.PY
```
[tools-sh]: /dev/tools.sh
[pre-commit]: https://pre-commit.com/
Expand Down
45 changes: 45 additions & 0 deletions dev/check.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
#
# Perform static analysis checks and reformat Python code using pre-commit
#
#### SETUP ####################################################################

set -o errexit
set -o errtrace
set -o nounset

# shellcheck disable=SC2154
trap '_es=${?};
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
printf " exited with a status of ${_es}\n";
exit ${_es}' ERR

DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"
# https://en.wikipedia.org/wiki/ANSI_escape_code
E0="$(printf "\e[0m")" # reset
E30="$(printf "\e[30m")" # black foreground
E107="$(printf "\e[107m")" # bright white background

#### FUNCTIONS ################################################################

print_header() {
# Print 80 character wide black on white heading with time
printf "${E30}${E107}# %-70s$(date '+%T') ${E0}\n" "${@}"
}

#### MAIN #####################################################################

cd "${DIR_REPO}"

print_header 'pre-commit'
echo 'See .pre-commit-config.yaml for pre-commit configuration.'
if [[ -n "${1:-}" ]]
then
# Run on files specified on command line
# shellcheck disable=SC2068
pipenv run pre-commit run --files ${@:-}
else
# Run on all files
pipenv run pre-commit run --all-files
fi
echo
16 changes: 0 additions & 16 deletions dev/tools.sh

This file was deleted.

0 comments on commit 54f4ff9

Please sign in to comment.