Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added walk() #37

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions gitignorefile/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,25 @@ def ignored(path, is_dir=None, ignore_names=DEFAULT_IGNORE_NAMES):
return Cache(ignore_names=ignore_names)(path, is_dir=is_dir)


def walk(path, walker=os.walk, ignore_names=DEFAULT_IGNORE_NAMES):
"""FIXME

Args:
path (str): FIXME
walker (FIXME): FIXME
ignore_names (list[str], optional): List of names of ignore files.

Returns:
FIXME
"""

cache = Cache(ignore_names=ignore_names)
for root, dirs, files, *rest in walker(path):
dirs[:] = [x for x in dirs if x != ".git" and not cache(os.path.join(root, x), is_dir=True)]
files[:] = [x for x in files if not cache(os.path.join(root, x), is_dir=False)]
yield (root, dirs, files, *rest)


class Cache:
"""Caches information about different `.gitignore` files in the directory tree.

Expand Down