classification
Title: add exist_ok to shutil.copytree
Type: enhancement Stage: patch review
Components: Library (Lib) Versions: Python 3.5
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: elias, eric.araujo, giampaolo.rodola, hynek, justin.myers, ncoghlan, r.david.murray, tarek, thehesiod
Priority: normal Keywords: patch

Created on 2014-03-04 04:55 by thehesiod, last changed 2018-06-12 09:43 by giampaolo.rodola.

Files
File name Uploaded Description Edit
shutil-copytree-exist_ok.patch elias, 2014-03-04 05:21 Issue 20849: add exist_ok to shutil.copytree
Pull Requests
URL Status Linked Edit
PR 2977 closed Ofekmeister, 2017-08-01 21:36
Messages (11)
msg212691 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-04 04:55
it would be REALLY nice (and REALLY easy) to add a parameter: exist_ok and pass this to os.makedirs with the same parameter name so you can use copytree to append a src dir to an existing dst dir.
msg212692 - (view) Author: Elias Zamaria (elias) * Date: 2014-03-04 05:21
Here is a patch that adds the option.

I am not very familiar with the internals of shutil and os so I would recommend that someone else review it.

I haven't added any tests. I can try to if anyone wants but I am not sure how long it will take me or if I will find the time any time soon.
msg212756 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-05 01:36
awesome, thanks so much!!
msg212901 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-07 21:41
Contrary to makedirs, there could be two interpretations for exist_ok in copytree: a) if a directory or file already exists in the destination, ignore it and go ahead  b) only do that for directories.

The proposed patch does b), but the cp tool does a).  It’s not clear to me which is best.  Can you start a discussion on the python-ideas mailing list?
msg212945 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-08 23:18
how about instead we rename the new parameter to dirs_exists_ok or something like that since the method already allows for existing files.
msg212948 - (view) Author: Elias Zamaria (elias) * Date: 2014-03-09 00:03
I am not sure. I am not on the python-ideas mailing list, and I am not sure
what adding and maintaining the discussion would entail, or if I would have
the time to do it or want to deal with the clutter in my inbox. I just
committed this patch because it seemed like it would be quick and easy.

I can start the discussion if anyone specifically wants me to, but I don't
want to let anyone down.

On Fri, Mar 7, 2014 at 1:41 PM, Éric Araujo <report@bugs.python.org> wrote:

>
> Éric Araujo added the comment:
>
> Contrary to makedirs, there could be two interpretations for exist_ok in
> copytree: a) if a directory or file already exists in the destination,
> ignore it and go ahead  b) only do that for directories.
>
> The proposed patch does b), but the cp tool does a).  It's not clear to me
> which is best.  Can you start a discussion on the python-ideas mailing list?
>
> ----------
> nosy: +eric.araujo
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue20849>
> _______________________________________
>
msg212949 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-09 01:10
I personally dont think this is worth investing the time for a discussion.
If the maintainers dont want to accept this or a minor variation without a
discussion ill just keep my local monkeypatch :)  thanks again for the
quick patch Elias!
On Mar 8, 2014 4:03 PM, "Elias Zamaria" <report@bugs.python.org> wrote:

>
> Elias Zamaria added the comment:
>
> I am not sure. I am not on the python-ideas mailing list, and I am not sure
> what adding and maintaining the discussion would entail, or if I would have
> the time to do it or want to deal with the clutter in my inbox. I just
> committed this patch because it seemed like it would be quick and easy.
>
> I can start the discussion if anyone specifically wants me to, but I don't
> want to let anyone down.
>
> On Fri, Mar 7, 2014 at 1:41 PM, Éric Araujo <report@bugs.python.org>
> wrote:
>
> >
> > Éric Araujo added the comment:
> >
> > Contrary to makedirs, there could be two interpretations for exist_ok in
> > copytree: a) if a directory or file already exists in the destination,
> > ignore it and go ahead  b) only do that for directories.
> >
> > The proposed patch does b), but the cp tool does a).  It's not clear to
> me
> > which is best.  Can you start a discussion on the python-ideas mailing
> list?
> >
> > ----------
> > nosy: +eric.araujo
> >
> > _______________________________________
> > Python tracker <report@bugs.python.org>
> > <http://bugs.python.org/issue20849>
> > _______________________________________
> >
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue20849>
> _______________________________________
>
msg213611 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2014-03-15 01:44
Adding some core devs to get their opinion on this proposal.
msg213620 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2014-03-15 02:15
I don't know what "the method already allows for existing files" means.  Since the target directory can't exist, there can be no existing files.

In unix, this kind of capability is provided by a combination of shell globbing and 'cp -r', and by default it does replace existing files.  So it would be reasonable for exists_ok to mean exactly that: replace anything that currently exists, if it does.

I think that would be a reasonable API, but the implementation isn't as simple as just passing through the exists_ok flag to makedirs.

I do not think that *just* making it OK for the destination directory to exist would be a good API.
msg213647 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-15 09:01
Ya. The original request I think is ok because by allowing that flag it
will replace files and dirs.
On Mar 14, 2014 7:15 PM, "R. David Murray" <report@bugs.python.org> wrote:

>
> R. David Murray added the comment:
>
> I don't know what "the method already allows for existing files" means.
>  Since the target directory can't exist, there can be no existing files.
>
> In unix, this kind of capability is provided by a combination of shell
> globbing and 'cp -r', and by default it does replace existing files.  So it
> would be reasonable for exists_ok to mean exactly that: replace anything
> that currently exists, if it does.
>
> I think that would be a reasonable API, but the implementation isn't as
> simple as just passing through the exists_ok flag to makedirs.
>
> I do not think that *just* making it OK for the destination directory to
> exist would be a good API.
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue20849>
> _______________________________________
>
msg214055 - (view) Author: Alexander Mohr (thehesiod) * Date: 2014-03-19 05:39
btw, I believe the solution is as simple as stated as that's what I'm doing locally and its behaving exactly as intended.
History
Date User Action Args
2018-06-12 09:43:10giampaolo.rodolasetnosy: + giampaolo.rodola
2017-12-09 03:47:52martin.panterlinkissue32247 superseder
2017-08-01 21:36:24Ofekmeistersetpull_requests: + pull_request3020
2015-03-12 13:07:10r.david.murraylinkissue23638 superseder
2014-04-23 19:36:59justin.myerssetnosy: + justin.myers
2014-03-19 05:39:11thehesiodsetmessages: + msg214055
2014-03-15 09:01:29thehesiodsetmessages: + msg213647
2014-03-15 02:15:54r.david.murraysetmessages: + msg213620
2014-03-15 01:44:14eric.araujosetnosy: + ncoghlan, tarek, r.david.murray, hynek
messages: + msg213611
2014-03-09 01:10:42thehesiodsetmessages: + msg212949
2014-03-09 00:03:23eliassetmessages: + msg212948
2014-03-08 23:18:12thehesiodsetmessages: + msg212945
2014-03-07 21:41:50eric.araujosetnosy: + eric.araujo
messages: + msg212901
2014-03-05 01:36:23thehesiodsetmessages: + msg212756
2014-03-04 14:01:27berker.peksagsetstage: patch review
versions: - Python 3.3, Python 3.4
2014-03-04 05:21:28eliassetfiles: + shutil-copytree-exist_ok.patch

nosy: + elias
messages: + msg212692

keywords: + patch
2014-03-04 04:55:22thehesiodcreate