Skip to content

Commit d262ff1

Browse files
committed
BLD: extract GH Actions check function to avoid duplication
Cherry-picked from 8611fe6
1 parent 44ab7a1 commit d262ff1

File tree

1 file changed

+27
-20
lines changed

1 file changed

+27
-20
lines changed

ci/code_checks.sh

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ BASE_DIR="$(dirname $0)/.."
2525
RET=0
2626
CHECK=$1
2727

28+
29+
function quote_if_needed {
30+
awk '{ print $0 ~ /.*\s+.*/ ? "\""$0"\"" : $0 }'
31+
}
32+
2833
function invgrep {
2934
# grep with inverse exist status and formatting for azure-pipelines
3035
#
@@ -38,13 +43,27 @@ function invgrep {
3843
return $((! $EXIT_STATUS))
3944
}
4045

46+
function if_gh_actions {
47+
# If this is running on GitHub Actions, echo the argument list, otherwise
48+
# echo the empty string.
49+
# Used to conditionally pass command-line arguments as in
50+
# $(if_gh_actions --baz spam) | xargs foo --bar
51+
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
52+
for arg in "$@"; do echo $arg; done | quote_if_needed
53+
else
54+
echo ""
55+
fi
56+
}
57+
58+
4159
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
4260
FLAKE8_FORMAT="##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
4361
INVGREP_PREPEND="##[error]"
4462
else
4563
FLAKE8_FORMAT="default"
4664
fi
4765

66+
4867
### LINTING ###
4968
if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
5069

@@ -93,36 +112,24 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
93112
cpplint --quiet --extensions=c,h --headers=h --recursive --filter=-readability/casting,-runtime/int,-build/include_subdir pandas/_libs/src/*.h pandas/_libs/src/parser pandas/_libs/ujson pandas/_libs/tslibs/src/datetime pandas/_libs/*.cpp
94113
RET=$(($RET + $?)) ; echo $MSG "DONE"
95114

115+
116+
VALIDATE_CMD=$BASE_DIR/scripts/validate_unwanted_patterns.py
117+
FMT_ARGS=$(if_gh_actions --format="##[error]{source_path}:{line_number}:{msg}")
118+
96119
MSG='Check for use of not concatenated strings' ; echo $MSG
97-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
98-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate" --format="##[error]{source_path}:{line_number}:{msg}" .
99-
else
100-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="strings_to_concatenate" .
101-
fi
120+
echo $FMT_ARGS | xargs $VALIDATE_CMD --validation-type="strings_to_concatenate" .
102121
RET=$(($RET + $?)) ; echo $MSG "DONE"
103122

104123
MSG='Check for strings with wrong placed spaces' ; echo $MSG
105-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
106-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace" --format="##[error]{source_path}:{line_number}:{msg}" .
107-
else
108-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="strings_with_wrong_placed_whitespace" .
109-
fi
124+
echo $FMT_ARGS | xargs $VALIDATE_CMD --validation-type="strings_with_wrong_placed_whitespace" .
110125
RET=$(($RET + $?)) ; echo $MSG "DONE"
111126

112127
MSG='Check for import of private attributes across modules' ; echo $MSG
113-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
114-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored --format="##[error]{source_path}:{line_number}:{msg}" pandas/
115-
else
116-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_import_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
117-
fi
128+
echo $FMT_ARGS | xargs $VALIDATE_CMD --validation-type="private_import_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
118129
RET=$(($RET + $?)) ; echo $MSG "DONE"
119130

120131
MSG='Check for use of private functions across modules' ; echo $MSG
121-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
122-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ --format="##[error]{source_path}:{line_number}:{msg}" pandas/
123-
else
124-
$BASE_DIR/scripts/validate_unwanted_patterns.py --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ pandas/
125-
fi
132+
echo $FMT_ARGS | xargs $VALIDATE_CMD --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ pandas/
126133
RET=$(($RET + $?)) ; echo $MSG "DONE"
127134

128135
echo "isort --version-number"

0 commit comments

Comments
 (0)