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

AnyPath.rmtree() does not work with local paths #383

Open
parviste-fortum opened this issue Nov 29, 2023 · 2 comments
Open

AnyPath.rmtree() does not work with local paths #383

parviste-fortum opened this issue Nov 29, 2023 · 2 comments

Comments

@parviste-fortum
Copy link

I'm using cloudpathlib.AnyPath to be able to fall back to a local filesystem for e.g. testing. However, it seems that AnyPath.rmtree() does not work correctly if the path points to the local filesystem. E.g.

import cloudpathlib
p = cloudpathlib.AnyPath("testdir")
p.mkdir()
p.rmtree()

results in

Traceback (most recent call last):
  File "/workspaces/scoutingtool/backend/test.py", line 4, in <module>
    p.rmtree()
    ^^^^^^^^
AttributeError: 'PosixPath' object has no attribute 'rmtree'

It would be nice if AnyPath supported rmtree(). The workaround is to check if the path points to the local filesystem, and then using shutil.rmtree() instead in that case, but that complicates the code a bit.

@pjbull
Copy link
Member

pjbull commented Dec 1, 2023

@parviste We've got an open feature request to have a clutil model that implements the shutil methods and handles both CloudPath and Path scenarios. #189

Would something like that work for you?

Since AnyPath just dispatches to a Path or CloudPath instance, I think that will be the cleanest implementation. The only other option would be patching the built in Path objects to have some of these shared utility methods with CloudPath, which is not preferred.

@parviste-fortum
Copy link
Author

I think having something like clutil would work, but in that case it would IMHO be a good idea to deprecate any functionality in CloudPath (e.g. rmtree) that is not in Path, to really make it possible to use AnyPath as mostly a drop-in replacement for CloudPath.

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