ppathspec 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ppathspec-0.1.0/.github/workflows/ci.yml +120 -0
- ppathspec-0.1.0/.gitignore +12 -0
- ppathspec-0.1.0/Cargo.lock +133 -0
- ppathspec-0.1.0/Cargo.toml +19 -0
- ppathspec-0.1.0/LICENSE +21 -0
- ppathspec-0.1.0/PKG-INFO +73 -0
- ppathspec-0.1.0/README.md +46 -0
- ppathspec-0.1.0/benchmarks/bench.py +118 -0
- ppathspec-0.1.0/pyproject.toml +60 -0
- ppathspec-0.1.0/python/ppathspec/__init__.py +42 -0
- ppathspec-0.1.0/python/ppathspec/__init__.pyi +30 -0
- ppathspec-0.1.0/python/ppathspec/_ppathspec.pyi +29 -0
- ppathspec-0.1.0/python/ppathspec/gitignore.py +218 -0
- ppathspec-0.1.0/python/ppathspec/pathspec.py +190 -0
- ppathspec-0.1.0/python/ppathspec/pattern.py +92 -0
- ppathspec-0.1.0/python/ppathspec/patterns/__init__.py +5 -0
- ppathspec-0.1.0/python/ppathspec/patterns/gitignore/__init__.py +7 -0
- ppathspec-0.1.0/python/ppathspec/patterns/gitignore/base.py +68 -0
- ppathspec-0.1.0/python/ppathspec/patterns/gitignore/basic.py +11 -0
- ppathspec-0.1.0/python/ppathspec/patterns/gitignore/spec.py +15 -0
- ppathspec-0.1.0/python/ppathspec/patterns/gitwildmatch.py +27 -0
- ppathspec-0.1.0/python/ppathspec/py.typed +0 -0
- ppathspec-0.1.0/python/ppathspec/util.py +276 -0
- ppathspec-0.1.0/src/gitignore.rs +903 -0
- ppathspec-0.1.0/src/lib.rs +178 -0
- ppathspec-0.1.0/src/normalize.rs +120 -0
- ppathspec-0.1.0/src/simd.rs +370 -0
- ppathspec-0.1.0/tests/test_adversarial_edge_cases.py +100 -0
- ppathspec-0.1.0/tests/test_concurrency_and_leaks.py +58 -0
- ppathspec-0.1.0/tests/test_differential_hypothesis.py +64 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
name: CI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [main]
|
|
6
|
+
tags: ["v*"]
|
|
7
|
+
pull_request:
|
|
8
|
+
|
|
9
|
+
permissions:
|
|
10
|
+
contents: read
|
|
11
|
+
|
|
12
|
+
jobs:
|
|
13
|
+
lint-and-test-rust:
|
|
14
|
+
runs-on: ubuntu-latest
|
|
15
|
+
steps:
|
|
16
|
+
- uses: actions/checkout@v4
|
|
17
|
+
- uses: dtolnay/rust-toolchain@stable
|
|
18
|
+
with:
|
|
19
|
+
components: rustfmt, clippy
|
|
20
|
+
- run: cargo fmt --check
|
|
21
|
+
- run: cargo clippy --all-targets -- -D warnings
|
|
22
|
+
- run: cargo test --lib
|
|
23
|
+
|
|
24
|
+
build-wheels:
|
|
25
|
+
strategy:
|
|
26
|
+
fail-fast: false
|
|
27
|
+
matrix:
|
|
28
|
+
include:
|
|
29
|
+
- os: ubuntu-latest
|
|
30
|
+
target: x86_64
|
|
31
|
+
args: --release --compatibility manylinux2014
|
|
32
|
+
run_tests: true
|
|
33
|
+
- os: ubuntu-latest
|
|
34
|
+
target: musl-x86_64
|
|
35
|
+
args: --release --compatibility musllinux_1_2
|
|
36
|
+
run_tests: false
|
|
37
|
+
- os: ubuntu-24.04-arm
|
|
38
|
+
target: aarch64
|
|
39
|
+
args: --release --compatibility manylinux2014
|
|
40
|
+
run_tests: true
|
|
41
|
+
- os: ubuntu-24.04-arm
|
|
42
|
+
target: musl-aarch64
|
|
43
|
+
args: --release --compatibility musllinux_1_2
|
|
44
|
+
run_tests: false
|
|
45
|
+
- os: macos-15
|
|
46
|
+
target: aarch64
|
|
47
|
+
args: --release
|
|
48
|
+
run_tests: true
|
|
49
|
+
- os: macos-15
|
|
50
|
+
target: x86_64
|
|
51
|
+
args: --release --target x86_64-apple-darwin
|
|
52
|
+
run_tests: false
|
|
53
|
+
- os: windows-latest
|
|
54
|
+
target: x64
|
|
55
|
+
args: --release
|
|
56
|
+
run_tests: true
|
|
57
|
+
runs-on: ${{ matrix.os }}
|
|
58
|
+
steps:
|
|
59
|
+
- uses: actions/checkout@v4
|
|
60
|
+
- uses: actions/setup-python@v5
|
|
61
|
+
with:
|
|
62
|
+
python-version: "3.12"
|
|
63
|
+
- uses: PyO3/maturin-action@v1
|
|
64
|
+
with:
|
|
65
|
+
command: build
|
|
66
|
+
args: ${{ matrix.args }} -o dist
|
|
67
|
+
manylinux: auto
|
|
68
|
+
- name: Check wheel metadata
|
|
69
|
+
shell: bash
|
|
70
|
+
run: |
|
|
71
|
+
python -m pip install --upgrade pip twine
|
|
72
|
+
twine check dist/*.whl
|
|
73
|
+
- name: Install and test abi3 wheel
|
|
74
|
+
if: matrix.run_tests
|
|
75
|
+
shell: bash
|
|
76
|
+
run: |
|
|
77
|
+
python -m pip install pytest hypothesis pathspec mypy ruff abi3audit
|
|
78
|
+
python -m pip install dist/*.whl
|
|
79
|
+
pytest -v
|
|
80
|
+
- name: Static typing, stubtest, and abi3audit (Linux)
|
|
81
|
+
if: runner.os == 'Linux' && matrix.run_tests
|
|
82
|
+
run: |
|
|
83
|
+
ruff format --check python tests
|
|
84
|
+
ruff check python tests
|
|
85
|
+
mypy --strict python/ppathspec
|
|
86
|
+
stubtest --ignore-disjoint-base ppathspec
|
|
87
|
+
abi3audit --strict dist/*.whl
|
|
88
|
+
- uses: actions/upload-artifact@v4
|
|
89
|
+
with:
|
|
90
|
+
name: wheels-${{ matrix.os }}-${{ matrix.target }}
|
|
91
|
+
path: dist/*.whl
|
|
92
|
+
|
|
93
|
+
build-sdist:
|
|
94
|
+
runs-on: ubuntu-latest
|
|
95
|
+
steps:
|
|
96
|
+
- uses: actions/checkout@v4
|
|
97
|
+
- uses: PyO3/maturin-action@v1
|
|
98
|
+
with:
|
|
99
|
+
command: sdist
|
|
100
|
+
args: -o dist
|
|
101
|
+
- uses: actions/upload-artifact@v4
|
|
102
|
+
with:
|
|
103
|
+
name: sdist
|
|
104
|
+
path: dist/*.tar.gz
|
|
105
|
+
|
|
106
|
+
publish:
|
|
107
|
+
if: startsWith(github.ref, 'refs/tags/v')
|
|
108
|
+
needs: [lint-and-test-rust, build-wheels, build-sdist]
|
|
109
|
+
runs-on: ubuntu-latest
|
|
110
|
+
environment: pypi
|
|
111
|
+
permissions:
|
|
112
|
+
id-token: write
|
|
113
|
+
steps:
|
|
114
|
+
- uses: actions/download-artifact@v4
|
|
115
|
+
with:
|
|
116
|
+
path: dist
|
|
117
|
+
merge-multiple: true
|
|
118
|
+
- uses: pypa/gh-action-pypi-publish@release/v1
|
|
119
|
+
with:
|
|
120
|
+
packages-dir: dist/
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 4
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "heck"
|
|
7
|
+
version = "0.5.0"
|
|
8
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
9
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
10
|
+
|
|
11
|
+
[[package]]
|
|
12
|
+
name = "libc"
|
|
13
|
+
version = "0.2.191"
|
|
14
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
15
|
+
checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
|
|
16
|
+
|
|
17
|
+
[[package]]
|
|
18
|
+
name = "once_cell"
|
|
19
|
+
version = "1.21.4"
|
|
20
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
21
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
22
|
+
|
|
23
|
+
[[package]]
|
|
24
|
+
name = "portable-atomic"
|
|
25
|
+
version = "1.15.0"
|
|
26
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
27
|
+
checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85"
|
|
28
|
+
|
|
29
|
+
[[package]]
|
|
30
|
+
name = "ppathspec"
|
|
31
|
+
version = "0.1.0"
|
|
32
|
+
dependencies = [
|
|
33
|
+
"pyo3",
|
|
34
|
+
]
|
|
35
|
+
|
|
36
|
+
[[package]]
|
|
37
|
+
name = "proc-macro2"
|
|
38
|
+
version = "1.0.107"
|
|
39
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
40
|
+
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
|
41
|
+
dependencies = [
|
|
42
|
+
"unicode-ident",
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
[[package]]
|
|
46
|
+
name = "pyo3"
|
|
47
|
+
version = "0.28.3"
|
|
48
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
49
|
+
checksum = "91fd8e38a3b50ed1167fb981cd6fd60147e091784c427b8f7183a7ee32c31c12"
|
|
50
|
+
dependencies = [
|
|
51
|
+
"libc",
|
|
52
|
+
"once_cell",
|
|
53
|
+
"portable-atomic",
|
|
54
|
+
"pyo3-build-config",
|
|
55
|
+
"pyo3-ffi",
|
|
56
|
+
"pyo3-macros",
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
[[package]]
|
|
60
|
+
name = "pyo3-build-config"
|
|
61
|
+
version = "0.28.3"
|
|
62
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
63
|
+
checksum = "e368e7ddfdeb98c9bca7f8383be1648fd84ab466bf2bc015e94008db6d35611e"
|
|
64
|
+
dependencies = [
|
|
65
|
+
"target-lexicon",
|
|
66
|
+
]
|
|
67
|
+
|
|
68
|
+
[[package]]
|
|
69
|
+
name = "pyo3-ffi"
|
|
70
|
+
version = "0.28.3"
|
|
71
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
72
|
+
checksum = "7f29e10af80b1f7ccaf7f69eace800a03ecd13e883acfacc1e5d0988605f651e"
|
|
73
|
+
dependencies = [
|
|
74
|
+
"libc",
|
|
75
|
+
"pyo3-build-config",
|
|
76
|
+
]
|
|
77
|
+
|
|
78
|
+
[[package]]
|
|
79
|
+
name = "pyo3-macros"
|
|
80
|
+
version = "0.28.3"
|
|
81
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
82
|
+
checksum = "df6e520eff47c45997d2fc7dd8214b25dd1310918bbb2642156ef66a67f29813"
|
|
83
|
+
dependencies = [
|
|
84
|
+
"proc-macro2",
|
|
85
|
+
"pyo3-macros-backend",
|
|
86
|
+
"quote",
|
|
87
|
+
"syn",
|
|
88
|
+
]
|
|
89
|
+
|
|
90
|
+
[[package]]
|
|
91
|
+
name = "pyo3-macros-backend"
|
|
92
|
+
version = "0.28.3"
|
|
93
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
+
checksum = "c4cdc218d835738f81c2338f822078af45b4afdf8b2e33cbb5916f108b813acb"
|
|
95
|
+
dependencies = [
|
|
96
|
+
"heck",
|
|
97
|
+
"proc-macro2",
|
|
98
|
+
"pyo3-build-config",
|
|
99
|
+
"quote",
|
|
100
|
+
"syn",
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
[[package]]
|
|
104
|
+
name = "quote"
|
|
105
|
+
version = "1.0.47"
|
|
106
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
107
|
+
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
|
108
|
+
dependencies = [
|
|
109
|
+
"proc-macro2",
|
|
110
|
+
]
|
|
111
|
+
|
|
112
|
+
[[package]]
|
|
113
|
+
name = "syn"
|
|
114
|
+
version = "2.0.119"
|
|
115
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
116
|
+
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
|
117
|
+
dependencies = [
|
|
118
|
+
"proc-macro2",
|
|
119
|
+
"quote",
|
|
120
|
+
"unicode-ident",
|
|
121
|
+
]
|
|
122
|
+
|
|
123
|
+
[[package]]
|
|
124
|
+
name = "target-lexicon"
|
|
125
|
+
version = "0.13.6"
|
|
126
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
127
|
+
checksum = "8c447be3a2abfa84b2d91680c56600bd6b2873866de27b36ec911be705e291da"
|
|
128
|
+
|
|
129
|
+
[[package]]
|
|
130
|
+
name = "unicode-ident"
|
|
131
|
+
version = "1.0.27"
|
|
132
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
133
|
+
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "ppathspec"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
license = "MIT"
|
|
6
|
+
description = "Fast gitignore-style file path pattern matching for Python"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
|
|
9
|
+
[lib]
|
|
10
|
+
name = "_ppathspec"
|
|
11
|
+
crate-type = ["cdylib", "rlib"]
|
|
12
|
+
|
|
13
|
+
[dependencies]
|
|
14
|
+
pyo3 = { version = "0.28", features = ["abi3-py39"] }
|
|
15
|
+
|
|
16
|
+
[profile.release]
|
|
17
|
+
lto = "thin"
|
|
18
|
+
codegen-units = 1
|
|
19
|
+
opt-level = 3
|
ppathspec-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 gateway12
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
ppathspec-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ppathspec
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Classifier: Development Status :: 4 - Beta
|
|
5
|
+
Classifier: Intended Audience :: Developers
|
|
6
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
7
|
+
Classifier: Operating System :: OS Independent
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
15
|
+
Classifier: Programming Language :: Rust
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Summary: Fast gitignore-style file path pattern matching for Python
|
|
20
|
+
Keywords: pathspec,gitignore,glob,pattern,matching,filesystem,rust
|
|
21
|
+
License-Expression: MIT
|
|
22
|
+
Requires-Python: >=3.9
|
|
23
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
24
|
+
Project-URL: Homepage, https://github.com/gatewaytofredom/ppathspec
|
|
25
|
+
Project-URL: Repository, https://github.com/gatewaytofredom/ppathspec
|
|
26
|
+
|
|
27
|
+
# ppathspec
|
|
28
|
+
|
|
29
|
+
[](https://github.com/gatewaytofredom/ppathspec/actions/workflows/ci.yml)
|
|
30
|
+
[](https://pypi.org/project/ppathspec/)
|
|
31
|
+
[](https://pypi.org/project/ppathspec/)
|
|
32
|
+
[](https://github.com/gatewaytofredom/ppathspec/blob/main/LICENSE)
|
|
33
|
+
|
|
34
|
+
Fast gitignore-style file path pattern matching for Python — a drop-in replacement for `pathspec` that is **6–11x faster** at compiling `.gitignore` rules and matching thousands of file paths.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install ppathspec
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
43
|
+
|
|
44
|
+
## Usage
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
from ppathspec import GitIgnoreSpec
|
|
48
|
+
|
|
49
|
+
spec = GitIgnoreSpec.from_lines(["*.pyc", "__pycache__/", "build/", "!build/keep.txt"])
|
|
50
|
+
spec.match_file("src/__pycache__/mod.cpython-312.pyc") # True
|
|
51
|
+
list(spec.match_files(["src/main.py", "build/out.o", "build/keep.txt"])) # ["build/out.o"]
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
## Performance
|
|
55
|
+
|
|
56
|
+
Benchmarked against `pathspec` v1.1.1 on a 31-rule `.gitignore` and 2,000 file paths:
|
|
57
|
+
|
|
58
|
+
| Workload | `pathspec` (x86-64) | `ppathspec` (x86-64) | `ppathspec` (Apple M4) |
|
|
59
|
+
|---|---:|---:|---:|
|
|
60
|
+
| Compile 31 rules (x200) | 17.28 ms | **1.47 ms** (11.8x) | **1.38 ms** (9.4x) |
|
|
61
|
+
| `match_file` (2,000 paths) | 12.02 ms | **1.57 ms** (7.7x) | **1.38 ms** (6.0x) |
|
|
62
|
+
| `match_files` (2,000 paths) | 11.82 ms | **1.51 ms** (7.8x) | **1.27 ms** (6.8x) |
|
|
63
|
+
|
|
64
|
+
## Under the hood
|
|
65
|
+
|
|
66
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
67
|
+
- Compact `cp39-abi3` wheel (`gil_used = false`, free-threaded Python ready) with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
68
|
+
- Verified with Hypothesis differential fuzzing against `pathspec` and tested as a drop-in replacement in `black`, `yamllint`, and `hatchling`
|
|
69
|
+
|
|
70
|
+
## License
|
|
71
|
+
|
|
72
|
+
MIT
|
|
73
|
+
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# ppathspec
|
|
2
|
+
|
|
3
|
+
[](https://github.com/gatewaytofredom/ppathspec/actions/workflows/ci.yml)
|
|
4
|
+
[](https://pypi.org/project/ppathspec/)
|
|
5
|
+
[](https://pypi.org/project/ppathspec/)
|
|
6
|
+
[](https://github.com/gatewaytofredom/ppathspec/blob/main/LICENSE)
|
|
7
|
+
|
|
8
|
+
Fast gitignore-style file path pattern matching for Python — a drop-in replacement for `pathspec` that is **6–11x faster** at compiling `.gitignore` rules and matching thousands of file paths.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install ppathspec
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Prebuilt wheels are included for Linux, macOS, and Windows (Python 3.9+, no Rust toolchain needed).
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from ppathspec import GitIgnoreSpec
|
|
22
|
+
|
|
23
|
+
spec = GitIgnoreSpec.from_lines(["*.pyc", "__pycache__/", "build/", "!build/keep.txt"])
|
|
24
|
+
spec.match_file("src/__pycache__/mod.cpython-312.pyc") # True
|
|
25
|
+
list(spec.match_files(["src/main.py", "build/out.o", "build/keep.txt"])) # ["build/out.o"]
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Performance
|
|
29
|
+
|
|
30
|
+
Benchmarked against `pathspec` v1.1.1 on a 31-rule `.gitignore` and 2,000 file paths:
|
|
31
|
+
|
|
32
|
+
| Workload | `pathspec` (x86-64) | `ppathspec` (x86-64) | `ppathspec` (Apple M4) |
|
|
33
|
+
|---|---:|---:|---:|
|
|
34
|
+
| Compile 31 rules (x200) | 17.28 ms | **1.47 ms** (11.8x) | **1.38 ms** (9.4x) |
|
|
35
|
+
| `match_file` (2,000 paths) | 12.02 ms | **1.57 ms** (7.7x) | **1.38 ms** (6.0x) |
|
|
36
|
+
| `match_files` (2,000 paths) | 11.82 ms | **1.51 ms** (7.8x) | **1.27 ms** (6.8x) |
|
|
37
|
+
|
|
38
|
+
## Under the hood
|
|
39
|
+
|
|
40
|
+
- Written in Rust (PyO3) with zero external runtime dependencies and runtime SIMD dispatch (AVX2 / SSE2 / ARM64 NEON)
|
|
41
|
+
- Compact `cp39-abi3` wheel (`gil_used = false`, free-threaded Python ready) with PEP 561 type stubs (`py.typed` + `__init__.pyi`)
|
|
42
|
+
- Verified with Hypothesis differential fuzzing against `pathspec` and tested as a drop-in replacement in `black`, `yamllint`, and `hatchling`
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import statistics
|
|
4
|
+
import time
|
|
5
|
+
|
|
6
|
+
import ppathspec
|
|
7
|
+
|
|
8
|
+
try:
|
|
9
|
+
import pathspec as ref_pathspec
|
|
10
|
+
except ImportError:
|
|
11
|
+
ref_pathspec = None # type: ignore[assignment]
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
GITIGNORE_LINES = [
|
|
15
|
+
"*.py[cod]",
|
|
16
|
+
"*$py.class",
|
|
17
|
+
"__pycache__/",
|
|
18
|
+
"*.so",
|
|
19
|
+
".Python",
|
|
20
|
+
"build/",
|
|
21
|
+
"develop-eggs/",
|
|
22
|
+
"dist/",
|
|
23
|
+
"downloads/",
|
|
24
|
+
"eggs/",
|
|
25
|
+
".eggs/",
|
|
26
|
+
"lib/",
|
|
27
|
+
"lib64/",
|
|
28
|
+
"parts/",
|
|
29
|
+
"sdist/",
|
|
30
|
+
"var/",
|
|
31
|
+
"wheels/",
|
|
32
|
+
"*.egg-info/",
|
|
33
|
+
".installed.cfg",
|
|
34
|
+
"*.egg",
|
|
35
|
+
".env",
|
|
36
|
+
".venv/",
|
|
37
|
+
"env/",
|
|
38
|
+
"venv/",
|
|
39
|
+
"ENV/",
|
|
40
|
+
".mypy_cache/",
|
|
41
|
+
".pytest_cache/",
|
|
42
|
+
".ruff_cache/",
|
|
43
|
+
"docs/_build/",
|
|
44
|
+
"node_modules/",
|
|
45
|
+
"!.venv/keep.txt",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
PATHS = [
|
|
49
|
+
"src/package/module.py",
|
|
50
|
+
"src/package/sub/helper.py",
|
|
51
|
+
"src/package/__pycache__/module.cpython-312.pyc",
|
|
52
|
+
"tests/unit/test_core.py",
|
|
53
|
+
"build/lib/package/core.so",
|
|
54
|
+
"docs/_build/html/index.html",
|
|
55
|
+
".mypy_cache/3.12/package/core.meta.json",
|
|
56
|
+
"node_modules/lodash/index.js",
|
|
57
|
+
"README.md",
|
|
58
|
+
"pyproject.toml",
|
|
59
|
+
] * 200 # 2,000 paths
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def bench_one(fn, iters: int = 5) -> float:
|
|
63
|
+
fn() # warmup
|
|
64
|
+
times = []
|
|
65
|
+
for _ in range(iters):
|
|
66
|
+
t0 = time.perf_counter()
|
|
67
|
+
fn()
|
|
68
|
+
times.append((time.perf_counter() - t0) * 1000.0)
|
|
69
|
+
return statistics.median(times)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def main() -> None:
|
|
73
|
+
ours_spec = ppathspec.GitIgnoreSpec.from_lines(GITIGNORE_LINES)
|
|
74
|
+
|
|
75
|
+
def ours_compile() -> None:
|
|
76
|
+
for _ in range(200):
|
|
77
|
+
ppathspec.GitIgnoreSpec.from_lines(GITIGNORE_LINES)
|
|
78
|
+
|
|
79
|
+
def ours_match_2k() -> None:
|
|
80
|
+
for p in PATHS:
|
|
81
|
+
ours_spec.match_file(p)
|
|
82
|
+
|
|
83
|
+
def ours_match_2k_batch() -> None:
|
|
84
|
+
list(ours_spec.match_files(PATHS))
|
|
85
|
+
|
|
86
|
+
t_ours_compile = bench_one(ours_compile)
|
|
87
|
+
t_ours_match = bench_one(ours_match_2k)
|
|
88
|
+
t_ours_batch = bench_one(ours_match_2k_batch)
|
|
89
|
+
|
|
90
|
+
print(f"ppathspec compile (x200): {t_ours_compile:.2f} ms")
|
|
91
|
+
print(f"ppathspec match_file (2k): {t_ours_match:.2f} ms")
|
|
92
|
+
print(f"ppathspec match_files (2k): {t_ours_batch:.2f} ms")
|
|
93
|
+
|
|
94
|
+
if ref_pathspec is not None:
|
|
95
|
+
ref_spec = ref_pathspec.GitIgnoreSpec.from_lines(GITIGNORE_LINES)
|
|
96
|
+
|
|
97
|
+
def ref_compile() -> None:
|
|
98
|
+
for _ in range(200):
|
|
99
|
+
ref_pathspec.GitIgnoreSpec.from_lines(GITIGNORE_LINES)
|
|
100
|
+
|
|
101
|
+
def ref_match_2k() -> None:
|
|
102
|
+
for p in PATHS:
|
|
103
|
+
ref_spec.match_file(p)
|
|
104
|
+
|
|
105
|
+
def ref_match_2k_batch() -> None:
|
|
106
|
+
list(ref_spec.match_files(PATHS))
|
|
107
|
+
|
|
108
|
+
t_ref_compile = bench_one(ref_compile)
|
|
109
|
+
t_ref_match = bench_one(ref_match_2k)
|
|
110
|
+
t_ref_batch = bench_one(ref_match_2k_batch)
|
|
111
|
+
|
|
112
|
+
print(f"pathspec compile (x200): {t_ref_compile:.2f} ms (speedup: {t_ref_compile / t_ours_compile:.2f}x)")
|
|
113
|
+
print(f"pathspec match_file (2k): {t_ref_match:.2f} ms (speedup: {t_ref_match / t_ours_match:.2f}x)")
|
|
114
|
+
print(f"pathspec match_files (2k): {t_ref_batch:.2f} ms (speedup: {t_ref_batch / t_ours_batch:.2f}x)")
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
if __name__ == "__main__":
|
|
118
|
+
main()
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["maturin>=1.7,<2.0"]
|
|
3
|
+
build-backend = "maturin"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "ppathspec"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Fast gitignore-style file path pattern matching for Python"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.9"
|
|
12
|
+
keywords = [
|
|
13
|
+
"pathspec",
|
|
14
|
+
"gitignore",
|
|
15
|
+
"glob",
|
|
16
|
+
"pattern",
|
|
17
|
+
"matching",
|
|
18
|
+
"filesystem",
|
|
19
|
+
"rust",
|
|
20
|
+
]
|
|
21
|
+
classifiers = [
|
|
22
|
+
"Development Status :: 4 - Beta",
|
|
23
|
+
"Intended Audience :: Developers",
|
|
24
|
+
"License :: OSI Approved :: MIT License",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
26
|
+
"Programming Language :: Python :: 3",
|
|
27
|
+
"Programming Language :: Python :: 3.9",
|
|
28
|
+
"Programming Language :: Python :: 3.10",
|
|
29
|
+
"Programming Language :: Python :: 3.11",
|
|
30
|
+
"Programming Language :: Python :: 3.12",
|
|
31
|
+
"Programming Language :: Python :: 3.13",
|
|
32
|
+
"Programming Language :: Python :: 3.14",
|
|
33
|
+
"Programming Language :: Rust",
|
|
34
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
35
|
+
"Typing :: Typed",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/gatewaytofredom/ppathspec"
|
|
40
|
+
Repository = "https://github.com/gatewaytofredom/ppathspec"
|
|
41
|
+
|
|
42
|
+
[tool.maturin]
|
|
43
|
+
python-source = "python"
|
|
44
|
+
module-name = "ppathspec._ppathspec"
|
|
45
|
+
features = ["pyo3/extension-module"]
|
|
46
|
+
|
|
47
|
+
[tool.ruff]
|
|
48
|
+
line-length = 120
|
|
49
|
+
target-version = "py39"
|
|
50
|
+
|
|
51
|
+
[tool.ruff.lint]
|
|
52
|
+
select = ["E", "F", "I", "UP", "B", "SIM"]
|
|
53
|
+
|
|
54
|
+
[tool.mypy]
|
|
55
|
+
python_version = "3.10"
|
|
56
|
+
strict = true
|
|
57
|
+
warn_unused_ignores = true
|
|
58
|
+
|
|
59
|
+
[tool.pytest.ini_options]
|
|
60
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Fast gitignore-style file path pattern matching for Python."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import warnings
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from . import patterns
|
|
9
|
+
from .gitignore import GitIgnoreSpec
|
|
10
|
+
from .pathspec import PathSpec
|
|
11
|
+
from .pattern import Pattern, RegexPattern
|
|
12
|
+
from .util import RecursivePathError, iter_tree, lookup_pattern, match_files
|
|
13
|
+
|
|
14
|
+
__version__ = "0.1.0"
|
|
15
|
+
__author__ = "gateway12"
|
|
16
|
+
__license__ = "MIT"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"GitIgnoreSpec",
|
|
20
|
+
"PathSpec",
|
|
21
|
+
"Pattern",
|
|
22
|
+
"RecursivePathError",
|
|
23
|
+
"RegexPattern",
|
|
24
|
+
"__author__",
|
|
25
|
+
"__license__",
|
|
26
|
+
"__version__",
|
|
27
|
+
"iter_tree",
|
|
28
|
+
"lookup_pattern",
|
|
29
|
+
"match_files",
|
|
30
|
+
"patterns",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def __getattr__(name: str) -> Any:
|
|
35
|
+
if name == "RecursionError":
|
|
36
|
+
warnings.warn(
|
|
37
|
+
"ppathspec.util.RecursionError is deprecated, use RecursivePathError instead.",
|
|
38
|
+
DeprecationWarning,
|
|
39
|
+
stacklevel=2,
|
|
40
|
+
)
|
|
41
|
+
return RecursivePathError
|
|
42
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
from . import patterns
|
|
6
|
+
from .gitignore import GitIgnoreSpec
|
|
7
|
+
from .pathspec import PathSpec
|
|
8
|
+
from .pattern import Pattern, RegexPattern
|
|
9
|
+
from .util import RecursivePathError, iter_tree, lookup_pattern, match_files
|
|
10
|
+
|
|
11
|
+
__version__: str
|
|
12
|
+
__author__: str
|
|
13
|
+
__license__: str
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"GitIgnoreSpec",
|
|
17
|
+
"PathSpec",
|
|
18
|
+
"Pattern",
|
|
19
|
+
"RecursivePathError",
|
|
20
|
+
"RegexPattern",
|
|
21
|
+
"__author__",
|
|
22
|
+
"__license__",
|
|
23
|
+
"__version__",
|
|
24
|
+
"iter_tree",
|
|
25
|
+
"lookup_pattern",
|
|
26
|
+
"match_files",
|
|
27
|
+
"patterns",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
def __getattr__(name: str) -> Any: ...
|