This fork preserves the core logic of the original project. But it aggressively reorganizes, documents, type-hints, and fixes a couple of minor bugs. While I have no wish to own this code, the changes are too structurally radical to become a practical pull request back to the original author.
A spec-compliant gitignore parser for Python
pip install gitignore_parser
Suppose /home/michael/project/.gitignore contains the following:
__pycache__/
*.py[cod]
Then:
>>> from gitignore_parser import parse_gitignore
>>> matches = parse_gitignore('/home/michael/project/.gitignore')
>>> matches('/home/michael/project/main.py')
False
>>> matches('/home/michael/project/main.pyc')
True
>>> matches('/home/michael/project/dir/main.pyc')
True
>>> matches('/home/michael/project/__pycache__')
True
I couldn't find a good library for doing the above on PyPI. There are
several other libraries, but they don't seem to support all features,
be it the square brackets in *.py[cod] or top-level paths /....
I'm very open to merging PRs. But before you start working on one, please read through my guidelines for PRs. It will save us both time and unnecessary effort.
The implementation is based on https://github.com/snark/ignorance/ by Steve Cook.