Skip to main content

Gitignore-style path matching

Project description

Project Status: Active — The project has reached a stable, usable state and is being actively developed. CI Status coverage pyversions MIT License

GitHub | PyPI | Documentation | Issues | Changelog

gitmatch provides gitignore-style pattern matching of file paths. Simply pass in a sequence of gitignore patterns and you’ll get back an object for testing whether a given relative path matches the patterns.

Installation

gitmatch requires Python 3.8 or higher. Just use pip for Python 3 (You have pip, right?) to install it:

python3 -m pip install gitmatch

Examples

Basic usage:

>>> import gitmatch
>>> gi = gitmatch.compile(["foo", "!bar", "*.dir/"])
>>> bool(gi.match("foo"))
True
>>> bool(gi.match("bar"))
False
>>> bool(gi.match("quux"))
False
>>> bool(gi.match("foo/quux"))
True
>>> bool(gi.match("foo/bar"))
True
>>> bool(gi.match("bar/foo"))
True
>>> bool(gi.match("bar/quux"))
False
>>> bool(gi.match("foo.dir"))
False
>>> bool(gi.match("foo.dir/"))
True

See what pattern was matched:

>>> m1 = gi.match("foo/bar")
>>> m1 is None
False
>>> bool(m1)
True
>>> m1.pattern
'foo'
>>> m1.path
'foo'
>>> m2 = gi.match("bar")
>>> m2 is None
False
>>> bool(m2)
False
>>> m2.pattern
'!bar'
>>> m2.pattern_obj.negative
True
>>> m3 = gi.match("quux")
>>> m3 is None
True

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitmatch-0.2.0.tar.gz (16.2 kB view details)

Uploaded Source

Built Distribution

gitmatch-0.2.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file gitmatch-0.2.0.tar.gz.

File metadata

  • Download URL: gitmatch-0.2.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for gitmatch-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b9e1b4b9336f5013b30a9929fdc037a68e3971e2c30545d8ba50a4e81931a0a5
MD5 6c6ea66a7c420955cdd328eae1e33184
BLAKE2b-256 c4033b7dc756867ccef54f99c72b96b431c72c9161d80851eebab8ac247ef32b

See more details on using hashes here.

File details

Details for the file gitmatch-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: gitmatch-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.4

File hashes

Hashes for gitmatch-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9c67d74b9dd32e06ffd0a079cffdcc764e9d8a0281b981487ed21699c030e1a0
MD5 7fbc60865d80dfedb8e9fa88621ab72e
BLAKE2b-256 288305bd9481ccd80f497936e2587ee846106af862a7dae8a52116b35e1d4082

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page