Skip to content

Commit 54f4ff9

Browse files
committed
replace tools.sh with check.sh (using pre-commit)
1 parent 7319707 commit 54f4ff9

File tree

3 files changed

+51
-34
lines changed

3 files changed

+51
-34
lines changed

README.md

+6-18
Original file line numberDiff line numberDiff line change
@@ -144,29 +144,17 @@ to be run manually or with every commit:
144144
```shell
145145
pipenv run pre-commit install
146146
```
147-
- Run manually before commit:
147+
- Run manually using helper dev script:
148148
```shell
149-
pipenv run pre-commit run -a
149+
./dev/check.sh [FILE]
150+
```
151+
If no file(s) are specified, then it runs against all files:
152+
```shell
153+
./dev/check.sh
150154
```
151155
3. _(Optional)_ review the configuration file:
152156
[`.pre-commit-config.yaml`](.pre-commit-config.yaml)
153157
154-
155-
#### Using [`dev/tools.sh`][tools-sh] helper script
156-
157-
The [`dev/tools.sh`][tools-sh] helper script runs the static analysis tools
158-
(`black`, `flake8`, and `isort`):
159-
```shell
160-
./dev/tools.sh
161-
```
162-
163-
It can also accept command-line arguments to specify specific files or
164-
directories to check:
165-
```shell
166-
./dev/tools.sh PATH/TO/MY/FILE.PY
167-
```
168-
169-
[tools-sh]: /dev/tools.sh
170158
[pre-commit]: https://pre-commit.com/
171159
172160

dev/check.sh

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Perform static analysis checks and reformat Python code using pre-commit
4+
#
5+
#### SETUP ####################################################################
6+
7+
set -o errexit
8+
set -o errtrace
9+
set -o nounset
10+
11+
# shellcheck disable=SC2154
12+
trap '_es=${?};
13+
printf "${0}: line ${LINENO}: \"${BASH_COMMAND}\"";
14+
printf " exited with a status of ${_es}\n";
15+
exit ${_es}' ERR
16+
17+
DIR_REPO="$(cd -P -- "${0%/*}/.." && pwd -P)"
18+
# https://en.wikipedia.org/wiki/ANSI_escape_code
19+
E0="$(printf "\e[0m")" # reset
20+
E30="$(printf "\e[30m")" # black foreground
21+
E107="$(printf "\e[107m")" # bright white background
22+
23+
#### FUNCTIONS ################################################################
24+
25+
print_header() {
26+
# Print 80 character wide black on white heading with time
27+
printf "${E30}${E107}# %-70s$(date '+%T') ${E0}\n" "${@}"
28+
}
29+
30+
#### MAIN #####################################################################
31+
32+
cd "${DIR_REPO}"
33+
34+
print_header 'pre-commit'
35+
echo 'See .pre-commit-config.yaml for pre-commit configuration.'
36+
if [[ -n "${1:-}" ]]
37+
then
38+
# Run on files specified on command line
39+
# shellcheck disable=SC2068
40+
pipenv run pre-commit run --files ${@:-}
41+
else
42+
# Run on all files
43+
pipenv run pre-commit run --all-files
44+
fi
45+
echo

dev/tools.sh

-16
This file was deleted.

0 commit comments

Comments
 (0)