Add fnmatch pattern support to include_files()#5
Open
hyeeyoungkim wants to merge 2 commits into
Open
Conversation
- Wrap parse_args() and main() in if __name__ guard - Add import guard tests (tests/test_import_guard.py) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Rewrite include_files() to use fnmatch.fnmatch() for pattern matching - Fix substring-matching bug (checked `in` on raw string, not split list) - Remove dead code (exclude_files split but never used) - Remove debug print() statements - Add .strip() for whitespace handling in comma-separated patterns - Update -ef help text to document wildcard support (*, ?, [seq]) - Add 12 unit tests in tests/test_include_files.py - Add *.egg-info/ to .gitignore Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
include_files()to support fnmatch glob patterns (*,?,[seq]) in-excludedFileNames, fixing two bugs in the process-efhelp text to document pattern supportProblem
include_files()has two bugs and a missing feature:Substring matching bug (line 1603):
if file_name in list_to_excludechecks for substring membership in the raw comma-separated string, not in the split list. For example, filename"dat"incorrectly matches exclusion list"data,photo.jpg".Dead code (line 1600):
exclude_files = list_to_exclude.split(",")is created but never referenced — the split list is discarded and the raw string is used instead.No pattern support: The function only does (broken) exact matching. Callers who need glob-style exclusion (e.g.,
._*for macOS resource forks,~$*for Office temp files) must pre-resolve patterns to exact filenames before calling yesc.Change
Rewrote
include_files()from 13 lines to 5:fnmatch.fnmatch()for each pattern (adds wildcard support; exact names still match sincefnmatch("Thumbs.db", "Thumbs.db")isTrue)"._*, ~$*")print()statementsUpdated help text for
-excludedFileNamesto mention pattern support.Impact
yesc.py -ef "._*,~$*,Thumbs.db"works