Skip to content

Add fnmatch pattern support to include_files()#5

Open
hyeeyoungkim wants to merge 2 commits into
decirella:mainfrom
hyeeyoungkim:pr/fix-include-files-fnmatch
Open

Add fnmatch pattern support to include_files()#5
hyeeyoungkim wants to merge 2 commits into
decirella:mainfrom
hyeeyoungkim:pr/fix-include-files-fnmatch

Conversation

@hyeeyoungkim

Copy link
Copy Markdown

Summary

  • Rewrite include_files() to support fnmatch glob patterns (*, ?, [seq]) in -excludedFileNames, fixing two bugs in the process
  • Update -ef help text to document pattern support

Problem

include_files() has two bugs and a missing feature:

  1. Substring matching bug (line 1603): if file_name in list_to_exclude checks 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".

  2. 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.

  3. 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:

def include_files(file_name, list_to_exclude):
    if list_to_exclude:
        import fnmatch
        for pattern in list_to_exclude.split(","):
            if fnmatch.fnmatch(file_name, pattern.strip()):
                return False
    return True
  • Iterates the split list instead of checking substring membership (fixes bug 1)
  • Uses fnmatch.fnmatch() for each pattern (adds wildcard support; exact names still match since fnmatch("Thumbs.db", "Thumbs.db") is True)
  • Strips whitespace from each pattern (handles "._*, ~$*")
  • Removes dead code and debug print() statements

Updated help text for -excludedFileNames to mention pattern support.

Impact

  • CLI with exact names: Now works correctly (was broken by substring bug)
  • CLI with patterns: New capability — yesc.py -ef "._*,~$*,Thumbs.db" works
  • Library import: Same signature, backwards compatible
  • PyInstaller: No change

hyeeyoungkim and others added 2 commits March 23, 2026 14:25
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant