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.10 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.3.0.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitmatch-0.3.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gitmatch-0.3.0.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for gitmatch-0.3.0.tar.gz
Algorithm Hash digest
SHA256 f3da0fe64c1ee74b276e2aa61be8a6abf5a41eacf8d931b7953b2333d47138ce
MD5 6bd4ca6fd86e7ae153210a98673aaaf0
BLAKE2b-256 887efdbaa640ba205b7555c6d6312e9fe58633a515ffe63b04d18ee2af0a6cdd

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gitmatch-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for gitmatch-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ee33a6521e36008f330cb658227522af22c8e2c3bf19475483c009dec81ed9cd
MD5 126bbd6a45af323ef1bb1dcc2ef71d0d
BLAKE2b-256 72f8f00732b330d20662d7c573dd134a6489760c4ea3e91169f57071b004b2fb

See more details on using hashes here.

Supported by

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