gitmatch
raw JSON → 0.3.0 verified Fri May 01 auth: no python
Library for matching file paths against gitignore-style patterns. Version 0.3.0, released infrequently.
pip install gitmatch Common errors
error ImportError: cannot import name 'PathMatch' from 'gitmatch' ↓
cause The class is named GitMatch, not PathMatch.
fix
Use 'from gitmatch import GitMatch'.
error TypeError: 'GitMatch' object is not callable ↓
cause In 0.3.0, the GitMatch object is no longer callable; you must call .matches().
fix
Use matcher.matches(path) instead of matcher(path).
error ValueError: Pattern must be a string ↓
cause GitMatch expects patterns as strings, not pathlib.Path objects.
fix
Convert Path objects to strings: GitMatch([str(p) for p in patterns])
Warnings
gotcha GitMatch expects patterns relative to the root, not absolute paths. Do not include leading slashes. ↓
fix Use patterns like '*.log' not '/tmp/*.log'.
gotcha The GitMatch constructor does not accept pathlib.Path objects directly; convert to str first. ↓
fix matcher = GitMatch([str(p) for p in patterns])
breaking In version 0.3.0, the API changed: GitMatch instances are no longer callable. Use .matches() instead. ↓
fix Replace matcher(path) with matcher.matches(path).
Imports
- GitMatch wrong
from gitmatch import PathMatchcorrectfrom gitmatch import GitMatch - match
from gitmatch import match
Quickstart
from gitmatch import GitMatch
patterns = ['*.pyc', '__pycache__/']
matcher = GitMatch(patterns)
print(matcher.matches('foo.pyc')) # True
print(matcher.matches('main.py')) # False