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

walk with filter does not recurse into non-filter-matching subdirectories #147

Closed
AndydeCleyre opened this issue Oct 2, 2014 · 1 comment

Comments

@AndydeCleyre
Copy link
Contributor

The problem can be demonstrated with the following code:

#!/usr/bin/env python3
from plumbum import local
from plumbum.cmd import touch


root = local.path('root_dir')
root.mkdir()
with local.cwd(root):
    touch('root.py')

    sub = local.path('sub_dir')
    sub.mkdir()
    with local.cwd(sub):
        touch('misses_this.py')

    sub2 = local.path('matching_sub_dir.py')
    sub2.mkdir()
    with local.cwd(sub2):
        touch('catches_this.py')
        touch('irrelevant.notpy')

print('Unfiltered:', *list(root.walk()), sep='\n')
print('Filtered:', *list(root.walk(lambda fn: str(fn).endswith('.py'))), sep='\n')

Which yields:

Unfiltered:
/.../root_dir/root.py
/.../root_dir/sub_dir
/.../root_dir/sub_dir/misses_this.py
/.../root_dir/matching_sub_dir.py
/.../root_dir/matching_sub_dir.py/catches_this.py
/.../root_dir/matching_sub_dir.py/irrelevant.notpy
Filtered:
/.../root_dir/root.py
/.../root_dir/matching_sub_dir.py
/.../root_dir/matching_sub_dir.py/catches_this.py

Note that the Filtered list should include /.../root_dir/sub_dir/misses_this.py.

Looking at plumbum/path/base.py, I think the solution might be dedenting lines 84, 85 and 86 a block, turning

for p in self.list():
    if filter(p):
        yield p
        if p.isdir():
            for p2 in p.walk(filter):
                yield p2

into

for p in self.list():
    if filter(p):
        yield p
    if p.isdir():
        for p2 in p.walk(filter):
            yield p2
@tomerfiliba
Copy link
Owner

i thought i took care of it already. feel free to submit a pull request.
thanks

-tomer


Tomer Filiba
tomerfiliba.com http://www.facebook.com/tomerfiliba
http://il.linkedin.com/in/tomerfiliba

On Thu, Oct 2, 2014 at 10:51 PM, Andy Kluger notifications@github.com
wrote:

The problem can be demonstrated with the following code:

#!/usr/bin/env python3from plumbum import localfrom plumbum.cmd import touch

root = local.path('root_dir')root.mkdir()with local.cwd(root):
touch('root.py')

sub = local.path('sub_dir')
sub.mkdir()
with local.cwd(sub):
    touch('misses_this.py')

sub2 = local.path('matching_sub_dir.py')
sub2.mkdir()
with local.cwd(sub2):
    touch('catches_this.py')
    touch('irrelevant.notpy')

print('Unfiltered:', *list(root.walk()), sep='\n')print('Filtered:', *list(root.walk(lambda fn: str(fn).endswith('.py'))), sep='\n')

Which yields:

Unfiltered:
/.../root_dir/root.py
/.../root_dir/sub_dir
/.../root_dir/sub_dir/misses_this.py
/.../root_dir/matching_sub_dir.py
/.../root_dir/matching_sub_dir.py/catches_this.py
/.../root_dir/matching_sub_dir.py/irrelevant.notpy
Filtered:
/.../root_dir/root.py
/.../root_dir/matching_sub_dir.py
/.../root_dir/matching_sub_dir.py/catches_this.py

Note that the Filtered list should include
/.../root_dir/sub_dir/misses_this.py.

Looking at plumbum/path/base.py, I think the solution might be dedenting
lines 84, 85 and 86 a block, turning

for p in self.list():
if filter(p):
yield p
if p.isdir():
for p2 in p.walk(filter):
yield p2

into

for p in self.list():
if filter(p):
yield p
if p.isdir():
for p2 in p.walk(filter):
yield p2


Reply to this email directly or view it on GitHub
#147.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants