You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
One can either replace it with shutil.move which works, or one could
add another method to Pathlib.move(...) with similar signature and return value, which calls shutil.move under the hood.
Before submitting a patch for that, I would like to get feedback for that.
Now, this is hardly a patch. I need to submit a PR with proper docs, tests and NEWS entry... I will be glad to work on it. However, I guess I need someone to "sponsor" it and merge it.
barneygale commented on Jan 14, 2022
barneygalemannequin
Mannequin
More actions
shutil.move() accepts a copy_function argument:
shutil.move(src, dst, copy_function=copy2)
It's possible to set copy_function=copy to skip copying file metadata.
oz123 commented on Jan 15, 2022
oz123mannequin
MannequinAuthor
More actions
Thanks for the answer, it makes sense now. Yes, I would adopt this.
Allowing users to use copy2 (or any other functio ...) using a keyword.
barneygale commented on Jan 15, 2022
barneygalemannequin
Mannequin
More actions
Fair enough. Users who wanted to avoid copying file metadata would then do something like this, I suppose?
I guess the downside here is that users would still need to import shutil to do this. But I see the utility of allowing any copy_function to be supplied!
Hey @oz123, I've just spotted that this issue is a duplicate of #73991. There's some more discussion there. I'll resolve this issue as a duplicate, and re-title your PR. Hope that's alright, thanks!
Activity
oz123 commentedon Jan 9, 2022
Pathlib.rename will fail across file system with:
OSError: [Errno 18] Invalid cross-device link
e.g:
-> path_dict["current_path"].rename(path_dict["destination"])
(Pdb) n
OSError: [Errno 18] Invalid cross-device link: '/tmp/pipenv-k1m0oynt-yaml/PyYAML-6.0/lib/yaml' -> '/home/oz123/Software/pipenv/pipenv/patched/yaml3'
This is because it uses os.rename under the hood:
https://github.com/python/cpython/blob/3.10/Lib/pathlib.py#L306
One can either replace it with
shutil.movewhich works, or one couldadd another method to Pathlib.move(...) with similar signature and return value, which calls
shutil.moveunder the hood.Before submitting a patch for that, I would like to get feedback for that.
barneygale commentedon Jan 14, 2022
Sounds good. Would you expose the
copy_functionargument in pathlib, or do something else (likemetadata=True)?oz123 commentedon Jan 14, 2022
@Barney, I am not sure that I understand your question.
I think adding another method
Pathlib.PathandPathlib._Accessoris my preferred way. The would be something like:Now, this is hardly a patch. I need to submit a PR with proper docs, tests and NEWS entry... I will be glad to work on it. However, I guess I need someone to "sponsor" it and merge it.
barneygale commentedon Jan 14, 2022
shutil.move() accepts a
copy_functionargument:It's possible to set
copy_function=copyto skip copying file metadata.oz123 commentedon Jan 15, 2022
Thanks for the answer, it makes sense now. Yes, I would adopt this.
Allowing users to use
copy2(or any other functio ...) using a keyword.barneygale commentedon Jan 15, 2022
Fair enough. Users who wanted to avoid copying file metadata would then do something like this, I suppose?
I guess the downside here is that users would still need to
import shutilto do this. But I see the utility of allowing any copy_function to be supplied!barneygale commentedon Apr 14, 2023
Hey @oz123, I've just spotted that this issue is a duplicate of #73991. There's some more discussion there. I'll resolve this issue as a duplicate, and re-title your PR. Hope that's alright, thanks!