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

Add ignore argument to copytree that lets one filter stuff out #145

Closed
pjbull opened this issue May 20, 2021 · 7 comments · Fixed by #272
Closed

Add ignore argument to copytree that lets one filter stuff out #145

pjbull opened this issue May 20, 2021 · 7 comments · Fixed by #272
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@pjbull
Copy link
Member

pjbull commented May 20, 2021

shutil.copytree has an ignore argument that lets one filter stuff out. Would be nice to support that too, but maybe it can be a future enhnacement.

https://docs.python.org/3/library/shutil.html#shutil.copytree

Originally posted by @jayqi in #142 (comment)


Seems like shutil just supports callables, and we may even just be able to point users to the same pattern constructor: https://docs.python.org/3/library/shutil.html#shutil.ignore_patterns

@aaossa
Copy link
Contributor

aaossa commented Sep 23, 2022

Is this issue still available? If that's the case I could work on this.

Seems like applying the filter in this section should do the trick right?

for subpath in self.iterdir():
if subpath.is_file():
subpath.copy(
destination / subpath.name, force_overwrite_to_cloud=force_overwrite_to_cloud
)
elif subpath.is_dir():
subpath.copytree(
destination / subpath.name, force_overwrite_to_cloud=force_overwrite_to_cloud
)

Python does something similar I think, by iterating the paths and ignoring those that must be ignored. Relevant code:

About the callable that defines which objects to ignore, seems like Python's implementation is already good enough, maybe just use the same object (i.e., use the shutil version)? Relevant Python source code: https://github.com/python/cpython/blob/a4ac14faa5c2be433738dfbbed14b0eaa1a2399e/Lib/shutil.py#L441-L451

@pjbull
Copy link
Member Author

pjbull commented Sep 24, 2022

@aaossa Thanks for digging in here. First pass read of what you outlined seems right to me, thanks. Happy to take a PR with an implementation like that. Thanks!

@aaossa
Copy link
Contributor

aaossa commented Sep 26, 2022

Sure, I'll be working on this in the upcoming days 👌

@aaossa
Copy link
Contributor

aaossa commented Sep 26, 2022

Created the PR with the proposed implementation in #272 . Every test is passed, including two tests added to confirm that the argument works as expected.

@pjbull
Copy link
Member Author

pjbull commented Sep 27, 2022

Merged into the main branch, thanks!

@pjbull pjbull closed this as completed Sep 27, 2022
@noamsgl
Copy link

noamsgl commented Aug 21, 2023

Could not find the ignore argument in the Documentation (https://cloudpathlib.drivendata.org/v0.6/api-reference/cloudpath/#cloudpathlib.cloudpath.CloudPath.copytree)
Is there a reason this was left out?

@jayqi
Copy link
Member

jayqi commented Aug 21, 2023

Hi @noamsgl, this is only available in v0.11.0 and higher. You linked to the v0.6 version of the docs. There's a menu that lets you change the version at the top left of the documentation website.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants