@@ -25,6 +25,26 @@ 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_ALL_PY_FILES=$( git_tracked_files .py)
43
+ GIT_TRACKED_DOCSOURCE_RST_FILES=$( git_tracked_files .rst doc/source)
44
+ GIT_TRACKED_REFERENCE_RST_FILES=$( git_tracked_files .rst doc/source/reference)
45
+ GIT_TRACKED_DEVELOPMENT_RST_FILES=$( git_tracked_files .rst doc/source/development)
46
+
47
+
28
48
function invgrep {
29
49
# grep with inverse exist status and formatting for azure-pipelines
30
50
#
@@ -38,6 +58,8 @@ function invgrep {
38
58
return $(( ! $EXIT_STATUS ))
39
59
}
40
60
61
+ export -f invgrep; # needed because of the use of xargs to pass in $GIT_TRACKED_ALL as args
62
+
41
63
if [[ " $GITHUB_ACTIONS " == " true" ]]; then
42
64
FLAKE8_FORMAT=" ##[error]%(path)s:%(row)s:%(col)s:%(code)s:%(text)s"
43
65
INVGREP_PREPEND=" ##[error]"
@@ -52,7 +74,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
52
74
black --version
53
75
54
76
MSG=' Checking black formatting' ; echo $MSG
55
- black . --check
77
+ echo $GIT_TRACKED_ALL_PY_FILES | xargs black --check
56
78
RET=$(( $RET + $? )) ; echo $MSG " DONE"
57
79
58
80
# `setup.cfg` contains the list of error codes that are being ignored in flake8
@@ -62,7 +84,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
62
84
63
85
# pandas/_libs/src is C code, so no need to search there.
64
86
MSG=' Linting .py code' ; echo $MSG
65
- flake8 --format=" $FLAKE8_FORMAT " .
87
+ echo $GIT_TRACKED_ALL_PY_FILES | xargs flake8 --format=" $FLAKE8_FORMAT "
66
88
RET=$(( $RET + $? )) ; echo $MSG " DONE"
67
89
68
90
MSG=' Linting .pyx and .pxd code' ; echo $MSG
@@ -77,7 +99,7 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
77
99
flake8-rst --version
78
100
79
101
MSG=' Linting code-blocks in .rst documentation' ; echo $MSG
80
- flake8-rst doc/source --filename= * . rst --format=" $FLAKE8_FORMAT "
102
+ echo $GIT_TRACKED_DOCSOURCE_RST_FILES | xargs flake8- rst --format=" $FLAKE8_FORMAT "
81
103
RET=$(( $RET + $? )) ; echo $MSG " DONE"
82
104
83
105
# Check that cython casting is of the form `<type>obj` as opposed to `<type> obj`;
@@ -100,35 +122,38 @@ if [[ -z "$CHECK" || "$CHECK" == "lint" ]]; then
100
122
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
123
RET=$(( $RET + $? )) ; echo $MSG " DONE"
102
124
125
+
126
+ VALIDATE_CMD=$BASE_DIR /scripts/validate_unwanted_patterns.py
127
+
103
128
MSG=' Check for use of not concatenated strings' ; echo $MSG
104
129
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}" .
130
+ echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_to_concatenate" --format=" ##[error]{source_path}:{line_number}:{msg}" --no-override
106
131
else
107
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_to_concatenate" .
132
+ echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_to_concatenate" --no-override
108
133
fi
109
134
RET=$(( $RET + $? )) ; echo $MSG " DONE"
110
135
111
136
MSG=' Check for strings with wrong placed spaces' ; echo $MSG
112
137
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}" .
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
114
139
else
115
- $BASE_DIR /scripts/validate_unwanted_patterns.py --validation-type=" strings_with_wrong_placed_whitespace" .
140
+ echo $GIT_TRACKED_ALL_PY_FILES | xargs $VALIDATE_CMD --validation-type=" strings_with_wrong_placed_whitespace" --no-override
116
141
fi
117
142
RET=$(( $RET + $? )) ; echo $MSG " DONE"
118
143
119
144
MSG=' Check for import of private attributes across modules' ; echo $MSG
120
145
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/
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/
122
147
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/
148
+ $VALIDATE_CMD --validation-type=" private_import_across_module" --included-file-extensions=" py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored pandas/
124
149
fi
125
150
RET=$(( $RET + $? )) ; echo $MSG " DONE"
126
151
127
152
MSG=' Check for use of private functions across modules' ; echo $MSG
128
153
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/
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/
130
155
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/
156
+ $VALIDATE_CMD --validation-type=" private_function_across_module" --included-file-extensions=" py" --excluded-file-paths=pandas/tests,asv_bench/,pandas/_vendored,doc/ pandas/
132
157
fi
133
158
RET=$(( $RET + $? )) ; echo $MSG " DONE"
134
159
@@ -239,7 +264,7 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
239
264
RET=$(( $RET + $? )) ; echo $MSG " DONE"
240
265
241
266
MSG=' Check for extra blank lines after the class definition' ; echo $MSG
242
- invgrep -R --include=" *.py" --include=" *.pyx" -E ' class.*:\n\n( )+"""' .
267
+ invgrep -R --include=" *.py" --include=" *.pyx" -E ' class.*:\n\n( )+"""' pandas
243
268
RET=$(( $RET + $? )) ; echo $MSG " DONE"
244
269
245
270
MSG=' Check for use of {foo!r} instead of {repr(foo)}' ; echo $MSG
@@ -272,7 +297,7 @@ if [[ -z "$CHECK" || "$CHECK" == "patterns" ]]; then
272
297
273
298
MSG=' Check that no file in the repo contains trailing whitespaces' ; echo $MSG
274
299
INVGREP_APPEND=" <- trailing whitespaces found"
275
- invgrep -RI --exclude= \* .{svg,c,cpp,html,js} --exclude-dir=env " \s$" *
300
+ echo $GIT_TRACKED_ALL | xargs bash -c ' invgrep -RI "\s$" "$@" ' _
276
301
RET=$(( $RET + $? )) ; echo $MSG " DONE"
277
302
unset INVGREP_APPEND
278
303
fi
@@ -390,7 +415,7 @@ if [[ -z "$CHECK" || "$CHECK" == "docstrings" ]]; then
390
415
RET=$(( $RET + $? )) ; echo $MSG " DONE"
391
416
392
417
MSG=' Validate correct capitalization among titles in documentation' ; echo $MSG
393
- $BASE_DIR /scripts/validate_rst_title_capitalization.py $BASE_DIR /doc/source/development $BASE_DIR /doc/source/reference
418
+ echo " ${GIT_TRACKED_REFERENCE_RST_FILES} ${GIT_TRACKED_DEVELOPMENT_RST_FILES} " | xargs $BASE_DIR /scripts/validate_rst_title_capitalization.py
394
419
RET=$(( $RET + $? )) ; echo $MSG " DONE"
395
420
396
421
fi
0 commit comments