rignore
rignore is a Python module that provides high-performance, Rust-powered file system traversal functionality. It efficiently walks through directories while respecting various ignore rules, such as those found in `.gitignore` files. It wraps the Rust `ignore` crate using PyO3, offering a fast and customizable API. The current version is 0.7.6, with a relatively active release cadence.
Warnings
- gotcha The `overrides` parameter acts as a whitelist. If provided, only files matching these override patterns (and not explicitly excluded by a `!` in an override) will be included, effectively ignoring all other ignore rules (like `.gitignore`) unless re-included by the overrides. This can lead to unexpected file exclusions if not carefully constructed.
- gotcha By default, `rignore.walk` respects standard `.gitignore` files. If you also provide `additional_ignores` or `read_git_ignore=True`, be mindful of potential redundancies or conflicting rules, especially if you expect certain files to be ignored that are later re-included by less specific `additional_ignores`.
Install
-
pip install rignore
Imports
- walk
from rignore import walk
Quickstart
import rignore
import os
# Create a dummy directory structure for demonstration
os.makedirs('my_project/src', exist_ok=True)
os.makedirs('my_project/build', exist_ok=True)
with open('my_project/.gitignore', 'w') as f:
f.write('*.tmp\n')
f.write('/build/\n')
with open('my_project/src/main.py', 'w') as f: pass
with open('my_project/src/temp.tmp', 'w') as f: pass
with open('my_project/build/output.log', 'w') as f: pass
print('Files found by rignore.walk:')
for file_path in rignore.walk('my_project'):
print(file_path)
# Clean up (optional)
import shutil
shutil.rmtree('my_project')