https://github.com/mherrmann/gitignore_parser
A spec-compliant gitignore parser for Python 3.5+
https://github.com/mherrmann/gitignore_parser
gig gitignore python python3
Last synced: 7 months ago
JSON representation
A spec-compliant gitignore parser for Python 3.5+
- Host: GitHub
- URL: https://github.com/mherrmann/gitignore_parser
- Owner: mherrmann
- License: mit
- Created: 2018-11-23T16:18:00.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2024-01-23T21:18:54.000Z (over 1 year ago)
- Last Synced: 2024-05-14T11:55:07.639Z (over 1 year ago)
- Topics: gig, gitignore, python, python3
- Language: Python
- Homepage:
- Size: 69.3 KB
- Stars: 161
- Watchers: 4
- Forks: 39
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gitignore_parser

[](https://badge.fury.io/py/gitignore-parser)A spec-compliant gitignore parser for Python
## Installation
pip install gitignore_parser
## Usage
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## Motivation
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 `/...`.## Contributing
I'm very open to merging PRs. But before you start working on one, please
read through my
[guidelines for PRs](https://gist.github.com/mherrmann/5ce21814789152c17abd91c0b3eaadca).
It will save us both time and unnecessary effort.## Attribution
The implementation is based on https://github.com/snark/ignorance/ by
Steve Cook.