@@ -25,6 +25,24 @@ BASE_DIR="$(dirname $0)/.."
25
25
RET=0
26
26
CHECK=$1
27
27
28
+
29
+ # Get lists of files tracked by git:
30
+
31
+ function quote_if_needed {
32
+ awk ' { print $0 ~ /.*\s+.*/ ? "\""$0"\"" : $0 }'
33
+ }
34
+
35
+ function git_tracked_files {
36
+ [[ ! -z " $1 " ]] && local patt=" \\ ${1} $" || local patt=" $"
37
+ local subdir=$2
38
+ git ls-tree --name-only -r HEAD $subdir | grep -e $patt | quote_if_needed
39
+ }
40
+
41
+ GIT_TRACKED_ALL=$( git_tracked_files)
42
+ GIT_TRACKED_PY_FILES=$( git_tracked_files .py)
43
+ GIT_TRACKED_RST_FILES=$( git_tracked_files .rst doc/source)
44
+
45
+
28
46
function invgrep {
29
47
# grep with inverse exist status and formatting for azure-pipelines
30
48
#
@@ -38,6 +56,8 @@ function invgrep {
38
56
return $(( ! $EXIT_STATUS ))
39
57
}
40
58
59
+ export -f invgrep; # needed because of the use of xargs to pass in $GIT_TRACKED_ALL as args
60
+
41
61
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
42
62
FLAKE8_FORMAT=" ##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
43
63
INVGREP_PREPEND=" ##[error]"
@@ -52,7 +72,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
52
72
black --version
53
73
54
74
MSG=' Checking black formatting' ; echo $MSG
55
- black . --check
75
+ echo $GIT_TRACKED_PY_FILES | xargs black --check
56
76
RET=$(( $RET + $? )) ; echo $MSG " DONE"
57
77
58
78
# `setup.cfg` contains the list of error codes that are being ignored in flake8
@@ -62,7 +82,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
62
82
63
83
# pandas/_libs/src is C code, so no need to search there.
64
84
MSG=' Linting .py code' ; echo $MSG
65
- flake8 --format=" $FLAKE8_FORMAT " .
85
+ echo $GIT_TRACKED_PY_FILES | xargs flake8 --format=" $FLAKE8_FORMAT "
66
86
RET=$(( $RET + $? )) ; echo $MSG " DONE"
67
87
68
88
MSG=' Linting .pyx and .pxd code' ; echo $MSG
@@ -77,7 +97,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
77
97
flake8-rst --version
78
98
79
99
MSG=' Linting code-blocks in .rst documentation' ; echo $MSG
80
- flake8-rst doc/source --filename= * . rst --format=" $FLAKE8_FORMAT "
100
+ echo $GIT_TRACKED_RST_FILES | xargs flake8- rst --format=" $FLAKE8_FORMAT "
81
101
RET=$(( $RET + $? )) ; echo $MSG " DONE"
82
102
83
103
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
@@ -100,35 +120,38 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
100
120
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
101
121
RET=$(( $RET + $? )) ; echo $MSG " DONE"
102
122
123
+
124
+ VALIDATE_CMD=$BASE_DIR /scripts/validate_unwanted_patterns.py
125
+
103
126
MSG=' Check for use of not concatenated strings' ; echo $MSG
104
127
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
105
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_to_concatenate" --format=" ##[error]{source_path}:{line_number}:{msg}" .
128
+ echo $GIT_TRACKED_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_to_concatenate" --format=" ##[error]{source_path}:{line_number}:{msg}" --no-override
106
129
else
107
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_to_concatenate" .
130
+ echo $GIT_TRACKED_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_to_concatenate" --no-override
108
131
fi
109
132
RET=$(( $RET + $? )) ; echo $MSG " DONE"
110
133
111
134
MSG=' Check for strings with wrong placed spaces' ; echo $MSG
112
135
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
113
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_with_wrong_placed_whitespace" --format=" ##[error]{source_path}:{line_number}:{msg}" .
136
+ echo $GIT_TRACKED_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_with_wrong_placed_whitespace" --format=" ##[error]{source_path}:{line_number}:{msg}" --no-override
114
137
else
115
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_with_wrong_placed_whitespace" .
138
+ echo $GIT_TRACKED_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_with_wrong_placed_whitespace" --no-override
116
139
fi
117
140
RET=$(( $RET + $? )) ; echo $MSG " DONE"
118
141
119
142
MSG=' Check for import of private attributes across modules' ; echo $MSG
120
143
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
121
- $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/
144
+ $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/
122
145
else
123
- $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/
146
+ $VALIDATE_CMD --validation-type=" private_import_across_module" --included-file-extensions=" py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
124
147
fi
125
148
RET=$(( $RET + $? )) ; echo $MSG " DONE"
126
149
127
150
MSG=' Check for use of private functions across modules' ; echo $MSG
128
151
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
129
- $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/
152
+ $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/
130
153
else
131
- $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/
154
+ $VALIDATE_CMD --validation-type=" private_function_across_module" --included-file-extensions=" py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ pandas/
132
155
fi
133
156
RET=$(( $RET + $? )) ; echo $MSG " DONE"
134
157
@@ -137,11 +160,11 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
137
160
138
161
# Imports - Check formatting using isort see setup.cfg for settings
139
162
MSG=' Check import format using isort' ; echo $MSG
140
- ISORT_CMD= " isort --quiet --check-only pandas asv_bench scripts web"
163
+ ISORT_OPTIONS= " --quiet --check-only pandas asv_bench scripts web"
141
164
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
142
- eval $ISORT_CMD | awk ' {print "##[error]" $0}' ; RET=$(( $RET + ${PIPESTATUS[0]} ))
165
+ echo GIT_TRACKED_PY_FILES | xargs isort $ISORT_OPTIONS | awk ' {print "##[error]" $0}' ; RET=$(( $RET + ${PIPESTATUS[0]} ))
143
166
else
144
- eval $ISORT_CMD
167
+ echo GIT_TRACKED_PY_FILES | xargs isort $ISORT_OPTIONS
145
168
fi
146
169
RET=$(( $RET + $? )) ; echo $MSG " DONE"
147
170
@@ -239,7 +262,7 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
239
262
RET=$(( $RET + $? )) ; echo $MSG " DONE"
240
263
241
264
MSG=' Check for extra blank lines after the class definition' ; echo $MSG
242
- invgrep -R --include=" *.py" --include=" *.pyx" -E ' class.*:\n\n( )+"""' .
265
+ invgrep -R --include=" *.py" --include=" *.pyx" -E ' class.*:\n\n( )+"""' pandas
243
266
RET=$(( $RET + $? )) ; echo $MSG " DONE"
244
267
245
268
MSG=' Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
@@ -272,7 +295,7 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
272
295
273
296
MSG=' Check that no file in the repo contains trailing whitespaces' ; echo $MSG
274
297
INVGREP_APPEND=" <- trailing whitespaces found"
275
- invgrep -RI --exclude= \* .{svg,c,cpp,html,js} --exclude-dir=env " \s$" *
298
+ echo $GIT_TRACKED_ALL | xargs bash -c ' invgrep -RI "\s$" "$@" ' _
276
299
RET=$(( $RET + $? )) ; echo $MSG " DONE"
277
300
unset INVGREP_APPEND
278
301
fi
0 commit comments