This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: make distutils use shutil
Type: enhancement Stage: resolved
Components: Distutils2 Versions: Python 3.1, Python 3.2, Python 3.3, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: tarek Nosy List: akitada, eric.araujo, pitrou, tarek
Priority: low Keywords:

Created on 2009-01-05 11:58 by tarek, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (6)
msg79129 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-01-05 11:58
In one sentence: 

Let's enhance shutil.copytree so we can drop distutils.[dir_util/file_util]

In details:

I am currently studying what could be removed from Distutils in order to
rely
on what is available in the standard library.

I have a concern about distutils.dir_util and distutils.file_util modules.

Distutils implements its own file and directory copy functions there, that
could be replaced by shutil ones, except four small features:

- verbose : each time a file is copied a "source -> target" is displayed
  in the output.
- dry_run : nothing is really copied
- update : each file will only be copied if they don't exist in the
  target path or if they are newer
- the copy_tree function returns the list of files copied (or that
  should have been copied when dry_run is True).

I think shutil could benefit from these small features, and            
       
distutils code could be refactored to use them.                        
       
                  
Here's a small proposal for distutils.copytree::                       
       
        
    copytree(src, dst, symlinks=False, ignore=None) -> None            
       
                
becomes:    
                
    copytree(src, dst, symlinks=False, ignore=None, update=False, 
             verbose=False, dry_run=False, logger=None) -> list of
copied files
            
where:          
                                                                       
       
- update    
 - if False, copytree behaves as usual: if os.path.samefile(source,
target) is True it raise an error                                      
                  
 - if True, the file is copied only if it's newer or doesn't exists,
otherwise it doesn't raise

- logger
  - if None, logger is set to logging.info

- verbose: if True, a logger.info("source -> target") call is made on
each copy

- dry_run: if True, the files are not really copied

Last, the function returns a tuple of copied files.

From there, distutils can work with shutil.copytree, shutil.copyfile and
shutil.copy2


Pro's:
 - distutils can rely on this function and its specialized modules dissapear
 - shutil.copytree becomes more powerful
 - less redundancy in the sdtlib

Con's:
 - the API signature is getting a bit complex
 - distutils use case might not be common enough
msg79136 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-01-05 12:36
I suggest a more generic and powerful API change:

    copytree(src, dst, symlinks=False, ignore=None) -> None            
       
becomes:    
                
    copytree(src, dst, symlinks=False, ignore=None, callback=None) -> None

where callback, if not None, is called with each (filename, src_dir,
dst_dir) and can return either True or False depending on whether the
copy must really occur or not.

Then you should be able implement the four distutils option in terms of
the callback.
msg79137 - (view) Author: Tarek Ziadé (tarek) * (Python committer) Date: 2009-01-05 12:53
Thanks for the tip Antoine,

That made me realize that 'ignore' is sufficient to address all cases in
distutils ! (it's a callable that does what you described in callback)

So I am transforming this ticket into a refactoring for distutils.

What classifier should I use in the ticket type ? (I was looking for
"refactoring")
msg79138 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2009-01-05 13:01
I don't know, perhaps "resource usage" - although it's probably meant
for runtime resources rather than source code resources. Not a big deal
anyway.
msg82953 - (view) Author: Akira Kitada (akitada) * Date: 2009-03-01 05:20
'ignore' was introduced in Python 2.6 but distutils has to keep Python
2.3 compatible.

See: http://bugs.python.org/issue5052

So I guess you have to wait some more years before
dropping distutils.dir_util and distutils.file_util.
msg103737 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2010-04-20 17:11
This has been done in Distutils2, see  http://hg.python.org/distutils2/rev/18dc3dba4075 and http://hg.python.org/distutils2/rev/98b70f92bf0a

Changing component and closing the bug, please reopen if I’m wrong :)

Regards
History
Date User Action Args
2022-04-11 14:56:43adminsetgithub: 49093
2010-04-20 17:11:48eric.araujosetstatus: open -> closed
versions: + Python 2.6, Python 2.5, Python 3.2, Python 3.3
messages: + msg103737

resolution: accepted
stage: resolved
2010-04-19 21:45:36tareksetnosy: pitrou, tarek, eric.araujo, akitada
components: + Distutils2, - Distutils
2010-04-08 23:57:20eric.araujosetnosy: + eric.araujo
2009-03-01 05:20:39akitadasetnosy: + akitada
messages: + msg82953
2009-01-05 13:01:13pitrousetmessages: + msg79138
2009-01-05 12:54:02tareksettitle: copytree improvments -> make distutils use shutil
2009-01-05 12:53:21tareksetpriority: low
assignee: tarek
messages: + msg79137
components: - Library (Lib)
2009-01-05 12:36:43pitrousetnosy: + pitrou
messages: + msg79136
2009-01-05 11:58:56tareksetcomponents: + Distutils
2009-01-05 11:58:23tarekcreate