Skip to content

elifarley/file-matcher

This branch is 5 commits ahead of mherrmann/gitignore_parser:master.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

604066a · Dec 20, 2024

History

71 Commits
Dec 20, 2024
Dec 20, 2024
Aug 13, 2020
Nov 24, 2018
Oct 16, 2020
Dec 20, 2024
Aug 7, 2023
Aug 7, 2023
Jan 19, 2024
Dec 20, 2024

Repository files navigation

gitignore_parser

CI PyPI version

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. It will save us both time and unnecessary effort.

Attribution

The implementation is based on https://github.com/snark/ignorance/ by Steve Cook.

About

A file matcher, compatible with .gitignore syntax

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 100.0%