Skip to content

Commit a862b6a

Browse files
Copilotmmcky
andauthored
Add comprehensive Python warning types and exclude-warning option to warning-checker (#202)
* Initial plan * Add comprehensive warning types to default configuration - Updated default warnings to include all Python warning types - Added UserWarning, PendingDeprecationWarning, RuntimeWarning, ImportWarning, UnicodeWarning, BytesWarning, ResourceWarning, EncodingWarning - Updated documentation and examples to reflect new comprehensive defaults - Added test case for new warning types detection - Maintains backward compatibility with existing configurations Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com> * Implement exclude-warning feature with comprehensive tests Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com> * Fix test file to eliminate duplicate warning detections in CI tests Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: mmcky <8263752+mmcky@users.noreply.github.com> Co-authored-by: Matt McKay <mmcky@users.noreply.github.com>
1 parent a1fc8a9 commit a862b6a

File tree

7 files changed

+500
-16
lines changed

7 files changed

+500
-16
lines changed

.github/actions/check-warnings/README.md

Lines changed: 51 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
88

99
- Scans HTML files for configurable Python warnings **within code cell outputs only**
1010
- Prevents false positives by only checking warnings in `cell_output` HTML elements
11-
- Supports multiple warning types (SyntaxWarning, DeprecationWarning, FutureWarning)
11+
- Supports multiple warning types (all Python warning types by default: UserWarning, DeprecationWarning, PendingDeprecationWarning, SyntaxWarning, RuntimeWarning, FutureWarning, ImportWarning, UnicodeWarning, BytesWarning, ResourceWarning, EncodingWarning)
1212
- Provides detailed output about warnings found
1313
- Optionally fails the workflow when warnings are detected
1414
- **Creates GitHub issues** with detailed warning reports
@@ -32,7 +32,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
3232
uses: QuantEcon/meta/.github/actions/check-warnings@main
3333
with:
3434
html-path: './_build/html'
35-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
35+
# Uses comprehensive default warnings (all Python warning types)
3636
fail-on-warning: 'true' # This will post a comment to the PR if warnings are found
3737
```
3838
@@ -43,7 +43,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
4343
uses: QuantEcon/meta/.github/actions/check-warnings@main
4444
with:
4545
html-path: './_build/html'
46-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
46+
# Uses comprehensive default warnings (all Python warning types)
4747
fail-on-warning: 'false'
4848
create-issue: 'true'
4949
issue-title: 'Python Warnings Found in Documentation Build'
@@ -56,7 +56,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
5656
uses: QuantEcon/meta/.github/actions/check-warnings@main
5757
with:
5858
html-path: './_build/html'
59-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
59+
# Uses comprehensive default warnings (all Python warning types)
6060
fail-on-warning: 'false'
6161
create-issue: 'true'
6262
issue-title: 'Python Warnings Found in Documentation Build'
@@ -70,7 +70,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
7070
uses: QuantEcon/meta/.github/actions/check-warnings@main
7171
with:
7272
html-path: './_build/html'
73-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
73+
# Uses comprehensive default warnings (all Python warning types)
7474
fail-on-warning: 'true'
7575
create-artifact: 'true'
7676
artifact-name: 'python-warning-report'
@@ -83,7 +83,7 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
8383
uses: QuantEcon/meta/.github/actions/check-warnings@main
8484
with:
8585
html-path: './_build/html'
86-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
86+
# Uses comprehensive default warnings (all Python warning types)
8787
fail-on-warning: 'false'
8888
create-issue: 'true'
8989
issue-title: 'Python Warnings Detected in Build'
@@ -92,6 +92,42 @@ This GitHub Action scans HTML files for Python warnings and optionally fails the
9292
artifact-name: 'detailed-warning-report'
9393
```
9494
95+
### Excluding Specific Warning Types
96+
97+
Sometimes you may want to temporarily exclude certain warning types (e.g., when dealing with upstream warnings that take time to fix):
98+
99+
```yaml
100+
- name: Check for Python warnings excluding upstream warnings
101+
uses: QuantEcon/meta/.github/actions/check-warnings@main
102+
with:
103+
html-path: './_build/html'
104+
exclude-warning: 'UserWarning' # Exclude single warning type
105+
fail-on-warning: 'true'
106+
```
107+
108+
```yaml
109+
- name: Check for Python warnings excluding multiple warning types
110+
uses: QuantEcon/meta/.github/actions/check-warnings@main
111+
with:
112+
html-path: './_build/html'
113+
exclude-warning: 'UserWarning,RuntimeWarning,ResourceWarning' # Exclude multiple warnings
114+
fail-on-warning: 'true'
115+
```
116+
117+
### Custom Warning Types with Exclusions
118+
119+
You can combine custom warning lists with exclusions:
120+
121+
```yaml
122+
- name: Check for specific warnings but exclude problematic ones
123+
uses: QuantEcon/meta/.github/actions/check-warnings@main
124+
with:
125+
html-path: './_build/html'
126+
warnings: 'UserWarning,DeprecationWarning,RuntimeWarning,ResourceWarning'
127+
exclude-warning: 'ResourceWarning' # Check all above except ResourceWarning
128+
fail-on-warning: 'true'
129+
```
130+
95131
### Using Outputs
96132
97133
```yaml
@@ -215,7 +251,8 @@ If you're only using the basic warning check functionality, only `contents: read
215251
| Input | Description | Required | Default |
216252
|-------|-------------|----------|---------|
217253
| `html-path` | Path to directory containing HTML files to scan | No | `.` |
218-
| `warnings` | Comma-separated list of warnings to check for | No | `SyntaxWarning,DeprecationWarning,FutureWarning` |
254+
| `warnings` | Comma-separated list of warnings to check for | No | `UserWarning,DeprecationWarning,PendingDeprecationWarning,SyntaxWarning,RuntimeWarning,FutureWarning,ImportWarning,UnicodeWarning,BytesWarning,ResourceWarning,EncodingWarning` |
255+
| `exclude-warning` | Comma-separated list of warnings to exclude from checking (can be a single warning or multiple warnings) | No | `` |
219256
| `fail-on-warning` | Whether to fail the workflow if warnings are found | No | `true` |
220257
| `create-issue` | Whether to create a GitHub issue when warnings are found | No | `false` |
221258
| `issue-title` | Title for the GitHub issue when warnings are found | No | `Python Warnings Found in Documentation Build` |
@@ -276,7 +313,7 @@ jobs:
276313
uses: QuantEcon/meta/.github/actions/check-warnings@main
277314
with:
278315
html-path: './_build/html'
279-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
316+
# Uses comprehensive default warnings (all Python warning types)
280317
fail-on-warning: ${{ github.event_name == 'push' }} # Fail on push, warn on PR
281318
create-issue: ${{ github.event_name == 'push' }} # Create issues for main branch
282319
notify: 'maintainer1,reviewer2' # Assign issues to team members
@@ -313,7 +350,12 @@ This action is particularly useful for:
313350
314351
3. **Customize warning types**: Adjust the `warnings` input to match your project's needs.
315352

316-
4. **Path considerations**: Make sure the `html-path` points to where your build process outputs HTML files.
353+
4. **Exclude problematic warnings temporarily**: Use `exclude-warning` to temporarily exclude warnings from upstream dependencies or issues that take time to fix:
354+
```yaml
355+
exclude-warning: 'UserWarning,RuntimeWarning' # Exclude multiple warnings
356+
```
357+
358+
5. **Path considerations**: Make sure the `html-path` points to where your build process outputs HTML files.
317359

318360
5. **Integration with existing workflows**: This action can be easily added to existing CI/CD pipelines.
319361

.github/actions/check-warnings/action.yml

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@ inputs:
1010
warnings:
1111
description: 'Comma-separated list of warnings to check for'
1212
required: false
13-
default: 'SyntaxWarning,DeprecationWarning,FutureWarning'
13+
default: 'UserWarning,DeprecationWarning,PendingDeprecationWarning,SyntaxWarning,RuntimeWarning,FutureWarning,ImportWarning,UnicodeWarning,BytesWarning,ResourceWarning,EncodingWarning'
14+
exclude-warning:
15+
description: 'Comma-separated list of warnings to exclude from checking (can be a single warning or multiple warnings)'
16+
required: false
17+
default: ''
1418
fail-on-warning:
1519
description: 'Whether to fail the workflow if warnings are found'
1620
required: false
@@ -63,6 +67,7 @@ runs:
6367
# Parse inputs
6468
HTML_PATH="${{ inputs.html-path }}"
6569
WARNINGS="${{ inputs.warnings }}"
70+
EXCLUDE_WARNINGS="${{ inputs.exclude-warning }}"
6671
FAIL_ON_WARNING="${{ inputs.fail-on-warning }}"
6772
6873
echo "Scanning HTML files in: $HTML_PATH"
@@ -71,6 +76,46 @@ runs:
7176
# Convert comma-separated warnings to array
7277
IFS=',' read -ra WARNING_ARRAY <<< "$WARNINGS"
7378
79+
# Handle exclude-warning parameter
80+
if [ -n "$EXCLUDE_WARNINGS" ]; then
81+
echo "Excluding warnings: $EXCLUDE_WARNINGS"
82+
# Convert comma-separated exclude warnings to array
83+
IFS=',' read -ra EXCLUDE_ARRAY <<< "$EXCLUDE_WARNINGS"
84+
85+
# Create a new array with warnings not in exclude list
86+
FILTERED_WARNING_ARRAY=()
87+
for warning in "${WARNING_ARRAY[@]}"; do
88+
# Remove leading/trailing whitespace from warning
89+
warning=$(echo "$warning" | xargs)
90+
exclude_warning=false
91+
92+
# Check if this warning should be excluded
93+
for exclude in "${EXCLUDE_ARRAY[@]}"; do
94+
# Remove leading/trailing whitespace from exclude warning
95+
exclude=$(echo "$exclude" | xargs)
96+
if [ "$warning" = "$exclude" ]; then
97+
exclude_warning=true
98+
break
99+
fi
100+
done
101+
102+
# Add to filtered array if not excluded
103+
if [ "$exclude_warning" = false ]; then
104+
FILTERED_WARNING_ARRAY+=("$warning")
105+
fi
106+
done
107+
108+
# Replace WARNING_ARRAY with filtered array
109+
WARNING_ARRAY=("${FILTERED_WARNING_ARRAY[@]}")
110+
111+
# Show final warning list
112+
if [ ${#WARNING_ARRAY[@]} -eq 0 ]; then
113+
echo "⚠️ All warnings have been excluded. No warnings will be checked."
114+
else
115+
echo "Final warning list after exclusions: ${WARNING_ARRAY[*]}"
116+
fi
117+
fi
118+
74119
# Initialize counters
75120
TOTAL_WARNINGS=0
76121
WARNING_DETAILS=""
@@ -150,6 +195,12 @@ runs:
150195
for file in "${FILES[@]}"; do
151196
echo "Checking file: $file"
152197
198+
# Skip warning check if no warnings to check for
199+
if [ ${#WARNING_ARRAY[@]} -eq 0 ]; then
200+
echo "No warnings to check for in $file (all excluded)"
201+
continue
202+
fi
203+
153204
for warning in "${WARNING_ARRAY[@]}"; do
154205
# Remove leading/trailing whitespace from warning
155206
warning=$(echo "$warning" | xargs)

.github/actions/check-warnings/examples.md

Lines changed: 97 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
uses: QuantEcon/meta/.github/actions/check-warnings@main
4040
with:
4141
html-path: './_build/html'
42-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
42+
# Uses comprehensive default warnings (all Python warning types)
4343
fail-on-warning: 'true'
4444
```
4545
@@ -158,7 +158,7 @@ jobs:
158158
uses: QuantEcon/meta/.github/actions/check-warnings@main
159159
with:
160160
html-path: './_build/html'
161-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning,UserWarning'
161+
# Uses comprehensive default warnings (all Python warning types)
162162
fail-on-warning: 'false' # Don't fail on warnings
163163
create-issue: ${{ github.event_name == 'push' }} # Create issues only on push to main
164164
issue-title: 'Python Warnings in Documentation Build - ${{ github.sha }}'
@@ -267,10 +267,103 @@ jobs:
267267
uses: QuantEcon/meta/.github/actions/check-warnings@main
268268
with:
269269
html-path: './output'
270-
warnings: ${{ github.event.inputs.custom_warnings || 'SyntaxWarning,DeprecationWarning,FutureWarning' }}
270+
warnings: ${{ github.event.inputs.custom_warnings || 'UserWarning,RuntimeWarning,ResourceWarning' }}
271271
fail-on-warning: 'true'
272272
```
273273
274+
## Example 6b: Excluding Specific Warning Types
275+
276+
```yaml
277+
name: Check with Warning Exclusions
278+
279+
on:
280+
push:
281+
branches: [ main ]
282+
283+
jobs:
284+
warning-check-with-exclusions:
285+
runs-on: ubuntu-latest
286+
287+
steps:
288+
- name: Checkout repository
289+
uses: actions/checkout@v4
290+
291+
- name: Build documentation
292+
run: |
293+
jupyter-book build .
294+
295+
- name: Check for warnings excluding upstream issues
296+
uses: QuantEcon/meta/.github/actions/check-warnings@main
297+
with:
298+
html-path: './_build/html'
299+
exclude-warning: 'UserWarning' # Exclude problematic upstream warnings
300+
fail-on-warning: 'true'
301+
```
302+
303+
## Example 6c: Multiple Warning Exclusions
304+
305+
```yaml
306+
name: Check with Multiple Warning Exclusions
307+
308+
on:
309+
pull_request:
310+
branches: [ main ]
311+
312+
jobs:
313+
warning-check-multiple-exclusions:
314+
runs-on: ubuntu-latest
315+
316+
steps:
317+
- name: Checkout repository
318+
uses: actions/checkout@v4
319+
320+
- name: Build documentation
321+
run: |
322+
jupyter-book build .
323+
324+
- name: Check for warnings excluding multiple types
325+
uses: QuantEcon/meta/.github/actions/check-warnings@main
326+
with:
327+
html-path: './_build/html'
328+
exclude-warning: 'UserWarning,RuntimeWarning,ResourceWarning' # Exclude multiple warning types
329+
fail-on-warning: 'true'
330+
create-artifact: 'true'
331+
artifact-name: 'filtered-warning-report'
332+
```
333+
334+
## Example 6d: Custom Warnings with Exclusions
335+
336+
```yaml
337+
name: Custom Warnings with Exclusions
338+
339+
on:
340+
schedule:
341+
- cron: '0 2 * * 1' # Weekly on Monday
342+
343+
jobs:
344+
custom-warning-check-with-exclusions:
345+
runs-on: ubuntu-latest
346+
347+
steps:
348+
- name: Checkout repository
349+
uses: actions/checkout@v4
350+
351+
- name: Build project
352+
run: |
353+
make build
354+
355+
- name: Check for specific warnings but exclude problematic ones
356+
uses: QuantEcon/meta/.github/actions/check-warnings@main
357+
with:
358+
html-path: './output'
359+
warnings: 'UserWarning,DeprecationWarning,RuntimeWarning,FutureWarning,ResourceWarning'
360+
exclude-warning: 'ResourceWarning,RuntimeWarning' # Exclude known upstream issues
361+
fail-on-warning: 'false'
362+
create-issue: 'true'
363+
issue-title: 'Critical Python Warnings Found (Filtered)'
364+
notify: 'team-lead'
365+
```
366+
274367
## Example 7: Matrix Strategy
275368
276369
```yaml
@@ -308,7 +401,7 @@ jobs:
308401
uses: QuantEcon/meta/.github/actions/check-warnings@main
309402
with:
310403
html-path: './_build/html'
311-
warnings: 'SyntaxWarning,DeprecationWarning,FutureWarning'
404+
# Uses comprehensive default warnings (all Python warning types)
312405
fail-on-warning: 'false'
313406

314407
- name: Upload HTML artifacts if warnings found

0 commit comments

Comments
 (0)