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
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])
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).

Create a matcher from a list of patterns and test paths.

from gitmatch import GitMatch

patterns = ['*.pyc', '__pycache__/']
matcher = GitMatch(patterns)
print(matcher.matches('foo.pyc'))  # True
print(matcher.matches('main.py'))   # False