StatReload: exclude hidden / cache directories when scanning for .py files - #2995
Open
RachelXiaolan wants to merge 1 commit into
Open
StatReload: exclude hidden / cache directories when scanning for .py files#2995RachelXiaolan wants to merge 1 commit into
RachelXiaolan wants to merge 1 commit into
Conversation
…anning for .py files
StatReload.iter_py_files() previously did a recursive rglob('*.py') and
yielded every match, including files inside .venv/, .mypy_cache/,
.pytest_cache/, .ruff_cache/ and .git/. WatchFilesReload's FileFilter
already excludes these (via watch_filter), but the stat-based reload
implementation did not — so users running with watchfiles not installed
saw spurious reloads on:
- venv installs (pip install writes into .venv/*.py)
- type-checker cache writes (.mypy_cache)
- test runner cache (.pytest_cache)
- linter cache (.ruff_cache)
- git operations that touch .git/hooks/*.py
Fix: add a small static _DEFAULT_EXCLUDE_DIRS tuple to StatReload and
skip any path whose parts intersect it. This matches the spirit of
WatchFilesReload's FileFilter defaults without taking a runtime
dependency on watchfiles.
Tests: tests/supervisors/test_statreload_filter.py covers .venv,
.mypy_cache, .git exclusion plus a sanity test for real .py in a
non-excluded subdir. Before fix: 2/2 failing. After: 2/2 passing.
Full uvicorn test suite (supervisors + config): 150+ passed, no
regressions.
Refs: AI-2138
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
StatReload.iter_py_files()does a recursiverglob("*.py")and yields every match, including.pyfiles inside.venv/,.mypy_cache/,.pytest_cache/,.ruff_cache/, and.git/.WatchFilesReload'sFileFilteralready excludes these (via watch_filter), but the stat-based reloader does not — so users running withwatchfilesnot installed see spurious reloads on venv installs, type-checker cache writes, linter cache writes, and git operations that touch.git/hooks/*.py.Fix
Add a small static
_DEFAULT_EXCLUDE_DIRStuple toStatReloadand skip any path whose parts intersect it. Mirrors the spirit ofWatchFilesReload.FileFilterdefaults without taking a runtime dependency on watchfiles.Reproducer
Before the fix: prints
app.py,.venv/lib/somelib.py,.mypy_cache/x.py— the latter two cause spurious reloads.After the fix: prints only
app.py.Tests
tests/supervisors/test_statreload_filter.py— 2 cases:test_statreload_excludes_hidden_dirs— fails before, passes aftertest_statreload_includes_app_in_subdir— sanity check that real.pyin a non-excluded subdir is still watchedTest run:
tests/supervisors/: 28 passed (full supervisors suite)tests/test_config.py: 122 passedRefs: AI-2138 (bug-hunter Strategy B, source-code audit)