跳转到主要内容

Gitignore-style路径匹配

项目描述

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

GitHub | PyPI | 文档 | 问题 | 变更日志

gitmatch 提供了 gitignore 样式的文件路径模式匹配。只需传入一系列 gitignore 模式,即可返回一个用于测试给定相对路径是否匹配这些模式的对象。

安装

gitmatch 需要 Python 3.8 或更高版本。只需使用 Python 3 的 pip 安装即可(您有 pip,对吧?)

python3 -m pip install gitmatch

示例

基本用法

>>> 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

查看匹配的模式

>>> 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

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源分发

gitmatch-0.2.0.tar.gz (16.2 kB 查看哈希值)

上传时间

构建分发

gitmatch-0.2.0-py3-none-any.whl (8.0 kB 查看哈希值)

上传时间 Python 3

支持者