Skip to content

Commit 792dddf

Browse files
aoutifrakdevkapilbansal
authored andcommitted
[qa] Add --ignore-pattern option to exclude files from QA checks #299
- Introduced --ignore-pattern <file_pattern> option to allow users to exclude specific files or directories. - Supports ignoring patterns like node_modules and env, which are unnecessary for QA checks. - Ensured compatibility with existing QA check functionality. This enhancement provides flexibility in excluding non-essential files Fixes #299
1 parent ecc72c1 commit 792dddf

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

openwisp-qa-check

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -52,33 +52,27 @@ echoerr() { echo "$@" 1>&2; }
5252

5353
runcheckendline() {
5454
flag=0
55-
5655
# Start with basic exclusions
5756
exclude_patterns=("./.*" "*/.git/*" "*/*.egg-info/*" "*.min.*" "*.svg")
58-
5957
# Add user-provided ignore pattern if specified
6058
if [ -n "$IGNORE_PATTERN" ]; then
6159
echo "Ignoring: $IGNORE_PATTERN"
6260
exclude_patterns+=("$IGNORE_PATTERN")
6361
fi
64-
6562
# Build the exclusion arguments
6663
exclude_args=""
6764
for pattern in "${exclude_patterns[@]}"; do
68-
exclude_args="$exclude_args -path '$pattern'"
65+
exclude_args="$exclude_args -path $pattern"
6966
done
70-
7167
# Find command that uses eval to properly handle the arguments
72-
find_command="find . -type f $exclude_args -exec grep -Iq . {} \; -print"
73-
68+
find_command="find . -type f -not $exclude_args -exec grep -Iq . {} \; -print"
7469
# Run the find and process results
7570
while IFS= read -r file; do
7671
if [ "$(tail -c 1 "$file")" != "" ]; then
7772
echo "$file needs newline at the end"
7873
flag=1
7974
fi
8075
done < <(eval "$find_command")
81-
8276
if [ $flag -ne 0 ]; then
8377
echoerr "ERROR: Blank endline check failed!"
8478
FAILURE=1
@@ -137,11 +131,9 @@ runcheckmigrations() {
137131

138132
runflake8() {
139133
EXCLUDE_PATTERN=".git,__pycache__,build,dist,*.egg-info"
140-
141134
if [ -n "$IGNORE_PATTERN" ]; then
142-
EXCLUDE_PATTERN="$IGNORE_PATTERN"
135+
EXCLUDE_PATTERN="$EXCLUDE_PATTERN,$IGNORE_PATTERN"
143136
fi
144-
145137
flake8 --exclude="$EXCLUDE_PATTERN" . &&
146138
echo "SUCCESS: Flake8 check successful!" ||
147139
{
@@ -171,24 +163,13 @@ runisort() {
171163
}
172164

173165
runblack() {
166+
black_args="-S --check --diff --quiet"
174167
if [ -n "$IGNORE_PATTERN" ]; then
175168
# Convert shell pattern to regex pattern for Black
176169
BLACK_EXCLUDE=$(echo "$IGNORE_PATTERN" | sed 's/\./\\./g' | sed 's/\*/.*/g')
177-
178-
black -S --exclude "$BLACK_EXCLUDE" --check --diff --quiet . &&
179-
echo "SUCCESS: Black check successful!" ||
180-
{
181-
echoerr "ERROR: Black check failed! Hint: did you forget to run openwisp-qa-format?"
182-
FAILURE=1
183-
}
184-
else
185-
black --check --diff --quiet . &&
186-
echo "SUCCESS: Black check successful!" ||
187-
{
188-
echoerr "ERROR: Black check failed! Hint: did you forget to run openwisp-qa-format?"
189-
FAILURE=1
190-
}
170+
black_args="$black_args --exclude \"$BLACK_EXCLUDE\""
191171
fi
172+
eval "black $black_args ."
192173
}
193174

194175
runcheckcommit() {

0 commit comments

Comments
 (0)