-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-20849: add dirs_exist_ok to shutil.copytree #8792
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
Conversation
|
Hey, could you please fix the news check while waiting for a review? I just hit this same thing myself and was about to file a PR maybe ten minutes after you with basically same contents. I to be honest think there's some merit to the critique on the ticket while this was my first idea as well. If you compare cp to shutil.copytree, cp has a --no-clobber so it creates directories but allows not overwriting existing files. While yours is a very backwards-compatible interpretation, I kinda think cp's way of doing it makes more sense than both the old and new Python idea of copytree |
|
Hello! Your branch contains unwanted changes to get-pip and a patch file. If you’re using git on the command line, a nice tip is to use Graphical git clients usually have a diff hunk selection screen that serves the same purpose. |
|
@merwok wrote:
Sorry about that! Fixed in the latest revision.
Nice, thanks for the tip! @nanonyme wrote:
Done in the latest revision.
No way! Solidarity, @nanonyme. Extra funny coincidence given how long this issue has been around.
I agree. Will wait for a maintainer to weigh in on how to proceed. |
e783b52 to
24f03ee
Compare
|
@giampaolo @vstinner The PR looks OK to my eyes, should we merge it? |
Misc/NEWS.d/next/Library/2018-08-16-16-47-15.bpo-20849.YWJECC.rst
Outdated
Show resolved
Hide resolved
|
Thanks for reviewing @1st1! Since the others you pinged haven’t been able to respond yet, is there anyone else who should review before this can be merged? The rest of the month will be busy for me so hoping to land while I still have the spare cycles. |
|
Any maintainers up for giving this a look some time soon? Cheers 3 months ago @1st1 wrote:
|
|
As I said on the bug tracker I think the new argument should be called "dirs_exists_ok" (EDIT: "dirs_exist_ok") instead of "exists_ok" so that it's clear that the behavior does not affect files. Other than that the patch is fine with me but it should be updated as it has conflicts with master. |
9a1016b to
2279717
Compare
|
Thanks for replying @giampaolo! This has been labeled as "awaiting review" since Aug 16 and nobody commented on bpo-20849 since I did on Aug 17, so I didn't realize you were awaiting changes on this before it could be merged.
Rebased on latest master. (Had to resolve conflicts from your bpo-33695 changes, which I hadn't noticed before – nice changes!) All tests are passing on CI (including the
I don't follow – this does affect files. Are you mistakenly thinking that this patch implements option (b) described in Éric Araujo's comment (as he said the original patch did), whereas this patch actually implements option (a) (i.e. it behaves like BSD From the docs I wrote for this: "If exist_ok is true, the destination directory may already exist, and existing files in the destination tree will be overwritten by matching files in the source tree." (emphasis added) Also:
So can this be merged as-is before there are any further conflicts? |
Doc/library/shutil.rst
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(I assumed this can't land in a 3.7.x release. Can it?)
(Unfortunately GNU |
|
You're right that "exist_ok" argument matches |
|
Just a bit of an out-of-the-box thought: how about replace_existing/overwrite instead of all these exist_ok and dirs_exist_ok? |
|
Same problem (doesn't tell who's the target). |
I think using the word "target" instead of "destination" is muddying the waters in this discussion. If we stick to using the word "destination" instead of "target", which is the term used in the function description itself, then isn't it clear that we're talking about the
I'm having trouble making any sense of this unless you meant "exist_ok=True" here. Did you? If so, then even with "dirs_exist_ok=True", couldn't that still be misinterpreted as "files with the same name might be skipped since this only applies to directories"? |
No, it's not, because "exists_ok" is meant for directories only and what
It cannot be misinterpreted because of the "dirs_" bit. It's clear it's about directories and not about files or both. |
2279717 to
6cf8e53
Compare
|
I have renamed the argument I'm still not following your logic but prefer to defer so this can be merged.
To be fair, that was in the context of someone else's patch from 5 years ago, which implemented behavior (b). This patch implements behavior (a).
I just meant that now the argument name says nothing about what happens to files. Before you were imagining a user who didn't read the docs and jumping to the wrong conclusion about what happens to files. I don't think the new name really prevents that. |
Doc/library/shutil.rst
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would simply rephrase it as something along these lines:
*dirs_exist_ok* dictates whether to raise an exception in case *dst* as well as
any missing parent directory already exists. I would not talk about the overwriting of files because the argument specifically targets directories and has nothing to do with files. When copying a big directory another process may create files in the dst directory which conflicts with the ones living in src, and they are always overwritten even when dirs_exist_ok=False.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The behavior of dirs_exist_ok=False (raising an exception) is already documented in the previous paragraph, so your rephrasing of this paragraph seems redundant. The purpose of this paragraph was to document the behavior of dirs_exist_ok=True.
I've just removed the part that talks about files.
Misc/NEWS.d/next/Library/2018-08-16-16-47-15.bpo-20849.YWJECC.rst
Outdated
Show resolved
Hide resolved
|
A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated. Once you have made the requested changes, please leave a comment on this pull request containing the phrase |
6cf8e53 to
acbbd3a
Compare
|
@bedevere-bot I have made the requested changes; please review again |
|
Thanks for making the requested changes! @giampaolo: please review the changes made to this pull request. |
acbbd3a to
8a0c7d2
Compare
8a0c7d2 to
4a9c7ca
Compare
4a9c7ca to
dbb9162
Compare
|
Looks good. Merging. |
|
Thanks @giampaolo! Can this be considered for backporting to 3.7.x? If so I would be happy to submit another PR for that. |
|
;-) |
It looks like the original author of #2977 lost interest, and it would still be really useful to have this, so I thought I'd pick it back up.
https://bugs.python.org/issue20849