From 54f4ff9e8974c8d21a1ffcd3e87518a1d7441755 Mon Sep 17 00:00:00 2001 From: Timid Robot Zehta Date: Wed, 20 Nov 2024 08:55:34 -0800 Subject: [PATCH] replace tools.sh with check.sh (using pre-commit) --- README.md | 24 ++++++------------------ dev/check.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ dev/tools.sh | 16 ---------------- 3 files changed, 51 insertions(+), 34 deletions(-) create mode 100755 dev/check.sh delete mode 100755 dev/tools.sh diff --git a/README.md b/README.md index 8b24f216..0a486c4b 100644 --- a/README.md +++ b/README.md @@ -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/ diff --git a/dev/check.sh b/dev/check.sh new file mode 100755 index 00000000..f8c6a065 --- /dev/null +++ b/dev/check.sh @@ -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 diff --git a/dev/tools.sh b/dev/tools.sh deleted file mode 100755 index e9aee64d..00000000 --- a/dev/tools.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/bash -#### SETUP #################################################################### -set -o errtrace -set -o nounset - -printf "\e[1m\e[7m %-80s\e[0m\n" 'isort' -pipenv run isort ${@:-.} -echo - -printf "\e[1m\e[7m %-80s\e[0m\n" 'black' -pipenv run black ${@:-.} -echo - -printf "\e[1m\e[7m %-80s\e[0m\n" 'flake8' -pipenv run flake8 ${@:-.} -echo