Skip to content

Commit 58fe81b

Browse files
authored
feat: --skip-XXX flags added (#17)
1 parent 30b9a23 commit 58fe81b

2 files changed

Lines changed: 56 additions & 14 deletions

File tree

bin/catalyst-check-codestyle

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ set -e # o pipefail -v
66
usage()
77
{
88
cat << USAGE >&2
9-
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [files [files ...]]
9+
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [--skip-isort] [--skip-black]\
10+
[--skip-flake8] [files [files ...]]
1011
1112
Python code style checker
1213
@@ -17,6 +18,9 @@ files files that need to be checked, all files\
1718
optional arguments:
1819
-h, --help show this help message and exit
1920
-l, --line-length INT maximum length that any line may be
21+
--skip-isort skip isort Python imports checker
22+
--skip-black skip black Python code checker
23+
--skip-flake8 skip flake8 linter
2024
USAGE
2125
exit 0
2226
}
@@ -26,6 +30,9 @@ USAGE
2630

2731
FILES=""
2832
LINE_LENGTH=79
33+
SKIP_ISORT=""
34+
SKIP_BLACK=""
35+
SKIP_FLAKE8=""
2936

3037
while (( "$#" )); do
3138
case "$1" in
@@ -36,6 +43,18 @@ while (( "$#" )); do
3643
LINE_LENGTH=$2
3744
shift 2
3845
;;
46+
--skip-isort)
47+
SKIP_ISORT="true"
48+
shift
49+
;;
50+
--skip-black)
51+
SKIP_BLACK="true"
52+
shift
53+
;;
54+
--skip-flake8)
55+
SKIP_FLAKE8="true"
56+
shift
57+
;;
3958
-*|--*=) # unsupported flags
4059
echo "Error: Unsupported flag $1" >&2
4160
exit 1
@@ -60,15 +79,21 @@ fi
6079

6180

6281
# ~ ~ ~ ~ ~ code checking ~ ~ ~ ~ ~
63-
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort \
64-
--diff \
65-
--check-only \
66-
-- ${FILES}
82+
if [[ -z "${SKIP_ISORT}" ]]; then
83+
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort \
84+
--diff \
85+
--check-only \
86+
-- ${FILES}
87+
fi
6788

68-
black --check --diff --line-length "${LINE_LENGTH}" -- ${FILES}
89+
if [[ -z "${SKIP_BLACK}" ]]; then
90+
black --check --diff --line-length "${LINE_LENGTH}" -- ${FILES}
91+
fi
6992

70-
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-flake8 \
71-
--show-source \
72-
--statistics \
73-
--count \
74-
-- ${FILES}
93+
if [[ -z "${SKIP_FLAKE8}" ]]; then
94+
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-flake8 \
95+
--show-source \
96+
--statistics \
97+
--count \
98+
-- ${FILES}
99+
fi

bin/catalyst-make-codestyle

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ set -e # o pipefail -v
66
usage()
77
{
88
cat << USAGE >&2
9-
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [files [files ...]]
9+
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [--skip-isort] [--skip-black]\
10+
[files [files ...]]
1011
1112
Python code formatter
1213
@@ -17,6 +18,8 @@ files files that need to be checked, all files\
1718
optional arguments:
1819
-h, --help show this help message and exit
1920
-l, --line-length INT maximum length that any line may be
21+
--skip-isort skip isorts Python imports formatter
22+
--skip-black skip black Python code formatter
2023
USAGE
2124
exit 0
2225
}
@@ -26,6 +29,8 @@ USAGE
2629

2730
FILES=""
2831
LINE_LENGTH=79
32+
SKIP_ISORT=""
33+
SKIP_BLACK=""
2934

3035
while (( "$#" )); do
3136
case "$1" in
@@ -36,6 +41,14 @@ while (( "$#" )); do
3641
LINE_LENGTH=$2
3742
shift 2
3843
;;
44+
--skip-isort)
45+
SKIP_ISORT="true"
46+
shift
47+
;;
48+
--skip-black)
49+
SKIP_BLACK="true"
50+
shift
51+
;;
3952
-*|--*=) # unsupported flags
4053
echo "Error: Unsupported flag $1" >&2
4154
exit 1
@@ -60,6 +73,10 @@ fi
6073

6174

6275
# ~ ~ ~ ~ ~ code formatting ~ ~ ~ ~ ~
63-
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort --apply -- ${FILES}
76+
if [[ -z "${SKIP_ISORT}" ]]; then
77+
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort --apply -- ${FILES}
78+
fi
6479

65-
black --line-length "${LINE_LENGTH}" -- ${FILES}
80+
if [[ -z "${SKIP_BLACK}" ]]; then
81+
black --line-length "${LINE_LENGTH}" -- ${FILES}
82+
fi

0 commit comments

Comments
 (0)