feat(settings): add max_file_size to filter oversized files - #248
Merged
Conversation
settings.yml could only filter by glob, so keeping bundled or generated files out of the index meant enumerating them in exclude_patterns, which does not scale for a project carrying several plugin trees of minified JavaScript. Add an optional max_file_size to project settings. It accepts a plain byte count or a binary-unit suffix (500KB, 1.5MB), and is applied by a matcher wrapper in file_walk, so every consumer of the project's file matching honors it from one place rather than each walker growing its own size check. Omitting the key keeps today's behavior of indexing files of any size. Files that cannot be stat'd are left to the underlying matcher instead of being dropped, since a size limit should not be what decides an unreadable file's fate. Closes cocoindex-io#179
CI mypy runs over tests/ too and flagged the type: ignore as unused; importing FilePathMatcher gives the helper a real annotation.
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.
Closes #179.
Problem
settings.ymlcan only filter by glob, so keeping bundled or generated files out of the index means enumerating them inexclude_patterns. The issue describes a WordPress project where WooCommerce, Elementor, and LearnPress each ship minified.jsbundles; there is no scalable pattern for "all of those, wherever they are, because they are large".Change
Adds an optional
max_file_sizeto project settings:1048576) or a binary-unit suffix:B,KB,MB,GB, case-insensitive, fractional allowed (1.5MB). Parsing lives inparse_file_sizeand rejects empty, non-numeric, zero, negative, andboolvalues with a clearValueError.SizeLimitedMatcherwrapper infile_walk.build_matcher, so it composes with the existing glob and.gitignorelayers and every consumer of the project's file matching picks it up from one place, rather than each walker growing its own size check. That meansccc grepskips the same files as the indexer; the module docstring already frames the matcher as the single source of truth for "which files count as part of the project", so I kept the setting on that side of the line. Happy to scope it to indexing only if you would rather grep stay size-blind.max_file_sizeatNoneand behavior exactly as it is today.max_file_sizebytes is kept.One deliberate call: a file that cannot be stat'd (broken symlink, a race with a delete) is left to the underlying matcher rather than dropped. A size limit should not be the thing that decides an unreadable file's fate, and silently dropping it would make the cap look like it had matched something it never measured.
min_file_sizefrom the issue's "could also be useful" note is not included; it seemed better to land the requested filter first than to add a knob with no reported use case.Tests
tests/test_file_walk.pymax_file_sizebytestests/test_settings.pyparse_file_sizetable over units, spacing, case, fractions, and plain bytesparse_file_sizerejects empty / non-numeric / zero / negative /bool/None/ listmax_file_sizethrough save and loadNonemax_file_size: 500KBin the YAML parses to bytesNegative control: unwiring
SizeLimitedMatcherfrombuild_matcherturns the two size-filtering walk tests red, so they do witness the behavior.Validation
Run against a venv without the
sentence-transformersextra, sincetorchhas no x86_64 macOS wheel on this host:pytest tests/test_file_walk.py tests/test_settings.py— 66 passedpytest tests/ -m "not docker_e2e"— 26 failed / 245 passed; the same 26 fail on an unmodified checkout in this environment (they needsentence-transformers), and the delta is +8, exactly the tests added hereruff check .— cleanruff format --check src/ tests/— clean (README.mdis reported unformatted both before and after this change, so I left it alone)mypy src/cocoindex_code/file_walk.py src/cocoindex_code/settings.py— cleanDocs
README's
settings.ymlsection gains the key, the accepted formats, the inclusive-limit and default-off semantics, and a note that it applies toccc greptoo. The "after editing ..." list now mentionsmax_file_size, since it is a file-matching change with the same no-restart-needed workflow.AI assistance
Written with AI assistance (Claude). The design choice worth flagging for review is the one above: putting the cap in
build_matcherrather than in the indexer, which is what makes it apply toccc grepas well.