Skip to content

Commit 90302ca

Browse files
committed
BLD: refactor code_checks.sh to avoid duplication due to GH Actions check
1 parent dd5678e commit 90302ca

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

ci/code_checks.sh

+22-20
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,20 @@ else
6767
FLAKE8_FORMAT="default"
6868
fi
6969

70+
71+
function if_gh_actions {
72+
# If this is running on GitHub Actions, echo the argument list, otherwise
73+
# echo the empty string.
74+
# Used to conditionally pass command-line arguments as in
75+
# $(if_gh_actions --baz spam) | xargs foo --bar
76+
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
77+
for arg in "$@"; do echo $arg; done | quote_if_needed
78+
else
79+
echo ""
80+
fi
81+
}
82+
83+
7084
### LINTING ###
7185
if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
7286

@@ -126,35 +140,23 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
126140
VALIDATE_CMD=$BASE_DIR/scripts/validate_unwanted_patterns.py
127141

128142
MSG='Check for use of not concatenated strings' ; echo $MSG
129-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
130-
echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type="strings_to_concatenate" --format="##[error]{source_path}:{line_number}:{msg}" --no-override
131-
else
132-
echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type="strings_to_concatenate" --no-override
133-
fi
143+
ARGS=$({ if_gh_actions --format="##[error]{source_path}:{line_number}:{msg}"; echo $GIT_TRACKED_ALL_PY_FILES; })
144+
echo $ARGS | xargs $VALIDATE_CMD --validation-type="strings_to_concatenate" --no-override
134145
RET=$(($RET + $?)) ; echo $MSG "DONE"
135146

136147
MSG='Check for strings with wrong placed spaces' ; echo $MSG
137-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
138-
echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type="strings_with_wrong_placed_whitespace" --format="##[error]{source_path}:{line_number}:{msg}" --no-override
139-
else
140-
echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type="strings_with_wrong_placed_whitespace" --no-override
141-
fi
148+
ARGS=$({ if_gh_actions --format="##[error]{source_path}:{line_number}:{msg}"; echo $GIT_TRACKED_ALL_PY_FILES; })
149+
echo $ARGS | xargs $VALIDATE_CMD --validation-type="strings_with_wrong_placed_whitespace" --no-override
142150
RET=$(($RET + $?)) ; echo $MSG "DONE"
143151

144152
MSG='Check for import of private attributes across modules' ; echo $MSG
145-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
146-
$VALIDATE_CMD --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/
147-
else
148-
$VALIDATE_CMD --validation-type="private_import_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
149-
fi
153+
ARGS=$(if_gh_actions --format="##[error]{source_path}:{line_number}:{msg}")
154+
echo $ARGS | xargs $VALIDATE_CMD --validation-type="private_import_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
150155
RET=$(($RET + $?)) ; echo $MSG "DONE"
151156

152157
MSG='Check for use of private functions across modules' ; echo $MSG
153-
if [[ "$GITHUB_ACTIONS" == "true" ]]; then
154-
$VALIDATE_CMD --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/
155-
else
156-
$VALIDATE_CMD --validation-type="private_function_across_module" --included-file-extensions="py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ pandas/
157-
fi
158+
ARGS=$(if_gh_actions --format="##[error]{source_path}:{line_number}:{msg}")
159+
echo $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/
158160
RET=$(($RET + $?)) ; echo $MSG "DONE"
159161

160162
echo "isort --version-number"

0 commit comments

Comments
 (0)