-
Notifications
You must be signed in to change notification settings - Fork 43
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
Moving files via UPath.rename
to absolute path locations
#206
Comments
Hi @falexwolf Thank you for reporting the issue. And thanks for offering to contribute! PRs are very welcome. As you've pointed out, we won't easily manage to be in line with pathlib here, due to the fact that we don't have a concept of cwd for remote filesystems. Your suggested fix is good, and I would add a check to make sure that the provided target uses the same protocol (this is seemingly broken in the current version too): def rename(
self,
target,
*,
recursive=False,
maxdepth=None,
**kwargs,
): # fixme: non-standard
target_protocol = get_upath_protocol(target)
if target_protocol and target_protocol != self.protocol:
raise ValueError(f"expected protocol {self.protocol!r}, got: {target_protocol!r}")
if not isinstance(target, UPath):
target = UPath(target)
if not target.is_absolute():
target = self.parent.joinpath(target).resolve()
... If you could add a test for a filesystem that has an empty Cheers, |
Thanks, Andreas! Will give it a shot! |
Hi, @ap-- , tried implementing this and observed
Would you recommend adding custom |
No worries I got back from holiday yesterday and am going through my backlog in the evenings now. I'll provide more feedback later tonight or tomorrow. And thank you so much for contributing! |
Because of this:
universal_pathlib/upath/core.py
Lines 942 to 954 in 380144c
the following happens:
To allow moving files across directories,
.rename()
should behave as it does in pathlib:An easy fix would be to replace
with
This still clashes with pathlib because pathlib resolves relative to the CWD and not relative to
self
, but that's another discussion.Let me know if you accept a PR for this!
The text was updated successfully, but these errors were encountered: