Registry / data / py-walk

py-walk

JSON →
library0.3.3pypypi✓ verified 26d ago

py-walk is a Python library designed to filter filesystem paths based on .gitignore-like patterns. It aims to provide 100% compatibility with Git's wildmatch pattern syntax, making it useful for applications needing to mimic Git's file exclusion behavior. The library is currently at version 0.3.3 and appears to have an active, though not rapid, release cadence with recent patch updates.

pip install py-walk
INSTALL
IMPORT
SIG · PY-WALK
P
py-walk
datapythonv0.3.3
Install
1.6s avg
Import
98ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v0.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.104s · 18.2MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.092s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

walk
✓ from py_walk import walk
get_parser_from_text
✓ from py_walk import get_parser_from_text
get_parser_from_file
✓ from py_walk import get_parser_from_file

This quickstart demonstrates how to use `py-walk` to traverse a directory with gitignore-like patterns and how to create a parser to manually check individual paths. It first creates a dummy directory structure and then applies a set of exclusion patterns.

import os from py_walk import walk, get_parser_from_text # Create a dummy directory structure for demonstration if not os.path.exists('my_project'): os.makedirs('my_project/data') os.makedirs('my_project/src') with open('my_project/data/temp.bin', 'w') as f: f.write('binary data') with open('my_project/data/foo.bin', 'w') as f: f.write('important binary data') with open('my_project/src/main.py', 'w') as f: f.write('print("Hello")') with open('my_project/__pycache__/cache.pyc', 'w') as f: f.write('cache') with open('my_project/.env', 'w') as f: f.write('ENV_VAR=value') patterns = """ **/data/*.bin !**/data/foo.bin # exclude python cache and env files __pycache__/ *.py[cod] .env """ # Example 1: Walk a directory with patterns print("\n--- Walking 'my_project' with patterns ---") for path in walk('my_project', ignore=patterns): print(f"Included: {path}") # Example 2: Manually check paths against a parser print("\n--- Manually checking paths ---") parser = get_parser_from_text(patterns, base_dir='my_project') paths_to_check = [ 'my_project/data/temp.bin', 'my_project/data/foo.bin', 'my_project/src/main.py', 'my_project/__pycache__/cache.pyc', 'my_project/.env', 'my_project/README.md' # This file doesn't exist but we can check the pattern ] for p in paths_to_check: if not parser.match(p): print(f"'{p}' is NOT ignored (matches patterns if prefix is not '!')") else: print(f"'{p}' IS ignored") # Cleanup dummy directory (optional) import shutil # shutil.rmtree('my_project') # Uncomment to clean up
Debug
Known issues
gotchaDo not confuse `py-walk` with Python's standard library `os.walk`. While both traverse directory trees, `py-walk`'s primary function is to filter paths based on `.gitignore` style patterns, providing selective iteration based on these rules. `os.walk` simply provides an iterator for all files and directories.
fix
Understand that `py-walk` is for pattern-based filtering, and `os.walk` is for raw directory traversal. Use `py-walk` when `gitignore`-like logic is needed for path inclusion/exclusion.
affects: All versions
gotchaWhile `py-walk` aims for 100% compatibility with Git's `wildmatch` pattern syntax, the project's README encourages reporting any divergences. This suggests that in some complex or edge-case scenarios, its behavior might not perfectly mirror `git check-ignore`.
fix
For critical applications, thoroughly test patterns against actual `git check-ignore` behavior if absolute fidelity is required. Report any discrepancies to the library's GitHub repository.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'py_walk'
The 'py-walk' library has not been installed or is not accessible in the current Python environment, or the import statement uses an incorrect module name.
fix
Install the library using pip: `pip install py-walk`
AttributeError: module 'py_walk' has no attribute 'walk'
The `walk` function (or other main functions like `get_parser_from_text`) needs to be imported directly from the `py_walk` module, not accessed as an attribute of the module itself after a simple `import py_walk`.
fix
Use `from py_walk import walk` (or `from py_walk import walk, get_parser_from_text`) instead of `import py_walk`.
py-walk not filtering files correctly / py-walk vs os.walk
Developers often confuse `py-walk` with Python's standard `os.walk`. While both traverse directory trees, `py-walk`'s primary function is to filter paths based on `.gitignore`-like patterns, providing selective iteration based on these rules, whereas `os.walk` simply provides an iterator for all files and directories.
fix
Understand that `py-walk` is specifically for pattern-based file exclusion/inclusion using `.gitignore` syntax. Ensure patterns are correctly defined and passed to the `ignore` or `match` parameters of the `walk` function. If simple directory traversal without pattern matching is needed, `os.walk` is the appropriate tool.
Upgrade
Version history
0.3.3latest on PyPI · released Oct 26, 2024
Audit
Dependencies
pythonrequiredRequired Python version
Agent activity
15 hits · last 30 days
node
14
Resources
py-walk — pip install py-walk · libregistry