Skip to content

Commit 71d8663

Browse files
authored
Merge pull request #233 from creativecommons/enable-strip-whitespace
Enable workflows: Ensure no leading/trailing whitespace is included in specified repo(s)
2 parents 8f5786e + c1cb502 commit 71d8663

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

dev/tools.sh

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,54 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
2+
#
3+
# Run Python code tools (isort, black, flake8)
4+
#
25
#### SETUP ####################################################################
6+
7+
set -o errexit
38
set -o errtrace
49
set -o nounset
510

6-
printf "\e[1m\e[7m %-80s\e[0m\n" 'isort'
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+
E31="$(printf "\e[31m")" # red foreground
22+
E107="$(printf "\e[107m")" # bright white background
23+
24+
#### FUNCTIONS ################################################################
25+
26+
error_exit() {
27+
# Echo error message and exit with error
28+
echo -e "${E31}ERROR:${E0} ${*}" 1>&2
29+
exit 1
30+
}
31+
32+
print_header() {
33+
# Print 80 character wide black on white heading with time
34+
printf "${E30}${E107}# %-69s$(date '+%T') ${E0}\n" "${@}"
35+
}
36+
37+
#### MAIN #####################################################################
38+
39+
cd "${DIR_REPO}"
40+
41+
print_header 'isort'
42+
# shellcheck disable=SC2068
743
pipenv run isort ${@:-.}
844
echo
945

10-
printf "\e[1m\e[7m %-80s\e[0m\n" 'black'
46+
print_header 'black'
47+
# shellcheck disable=SC2068
1148
pipenv run black ${@:-.}
1249
echo
1350

14-
printf "\e[1m\e[7m %-80s\e[0m\n" 'flake8'
51+
print_header 'flake8'
52+
# shellcheck disable=SC2068
1553
pipenv run flake8 ${@:-.}
1654
echo

enable_workflows.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ def setup():
5050
args.dryrun = ""
5151
if not args.repos:
5252
raise ap.error("at least one (1) REPOSITORY must be specified")
53+
for i, repo in enumerate(args.repos):
54+
args.repos[i] = repo.strip()
5355
return args
5456

5557

0 commit comments

Comments
 (0)