Skip to content

Commit

Permalink
feat: --skip-XXX flags added (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
bagxi authored Sep 10, 2021
1 parent 30b9a23 commit 58fe81b
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 14 deletions.
47 changes: 36 additions & 11 deletions bin/catalyst-check-codestyle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set -e # o pipefail -v
usage()
{
cat << USAGE >&2
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [files [files ...]]
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [--skip-isort] [--skip-black]\
[--skip-flake8] [files [files ...]]
Python code style checker
Expand All @@ -17,6 +18,9 @@ files files that need to be checked, all files\
optional arguments:
-h, --help show this help message and exit
-l, --line-length INT maximum length that any line may be
--skip-isort skip isort Python imports checker
--skip-black skip black Python code checker
--skip-flake8 skip flake8 linter
USAGE
exit 0
}
Expand All @@ -26,6 +30,9 @@ USAGE

FILES=""
LINE_LENGTH=79
SKIP_ISORT=""
SKIP_BLACK=""
SKIP_FLAKE8=""

while (( "$#" )); do
case "$1" in
Expand All @@ -36,6 +43,18 @@ while (( "$#" )); do
LINE_LENGTH=$2
shift 2
;;
--skip-isort)
SKIP_ISORT="true"
shift
;;
--skip-black)
SKIP_BLACK="true"
shift
;;
--skip-flake8)
SKIP_FLAKE8="true"
shift
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
Expand All @@ -60,15 +79,21 @@ fi


# ~ ~ ~ ~ ~ code checking ~ ~ ~ ~ ~
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort \
--diff \
--check-only \
-- ${FILES}
if [[ -z "${SKIP_ISORT}" ]]; then
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort \
--diff \
--check-only \
-- ${FILES}
fi

black --check --diff --line-length "${LINE_LENGTH}" -- ${FILES}
if [[ -z "${SKIP_BLACK}" ]]; then
black --check --diff --line-length "${LINE_LENGTH}" -- ${FILES}
fi

LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-flake8 \
--show-source \
--statistics \
--count \
-- ${FILES}
if [[ -z "${SKIP_FLAKE8}" ]]; then
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-flake8 \
--show-source \
--statistics \
--count \
-- ${FILES}
fi
23 changes: 20 additions & 3 deletions bin/catalyst-make-codestyle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ set -e # o pipefail -v
usage()
{
cat << USAGE >&2
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [files [files ...]]
usage: $(basename "$0") [-h] [-l LINE_LENGTH] [--skip-isort] [--skip-black]\
[files [files ...]]
Python code formatter
Expand All @@ -17,6 +18,8 @@ files files that need to be checked, all files\
optional arguments:
-h, --help show this help message and exit
-l, --line-length INT maximum length that any line may be
--skip-isort skip isorts Python imports formatter
--skip-black skip black Python code formatter
USAGE
exit 0
}
Expand All @@ -26,6 +29,8 @@ USAGE

FILES=""
LINE_LENGTH=79
SKIP_ISORT=""
SKIP_BLACK=""

while (( "$#" )); do
case "$1" in
Expand All @@ -36,6 +41,14 @@ while (( "$#" )); do
LINE_LENGTH=$2
shift 2
;;
--skip-isort)
SKIP_ISORT="true"
shift
;;
--skip-black)
SKIP_BLACK="true"
shift
;;
-*|--*=) # unsupported flags
echo "Error: Unsupported flag $1" >&2
exit 1
Expand All @@ -60,6 +73,10 @@ fi


# ~ ~ ~ ~ ~ code formatting ~ ~ ~ ~ ~
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort --apply -- ${FILES}
if [[ -z "${SKIP_ISORT}" ]]; then
LINE_LENGTH="${LINE_LENGTH}" catalyst-codestyle-isort --apply -- ${FILES}
fi

black --line-length "${LINE_LENGTH}" -- ${FILES}
if [[ -z "${SKIP_BLACK}" ]]; then
black --line-length "${LINE_LENGTH}" -- ${FILES}
fi

0 comments on commit 58fe81b

Please sign in to comment.