[Python-Dev] improvement on shutil.make_archive
redstone-cold at 163.com
Mon Aug 20 04:42:09 EDT 2018
The current behavior of shutil.make_archive caused many issues , the problem is mainly on the extracted archive directory hierarchy. These are the proofs:
For example , if I want to create a zip archive of the pip package (path specified by pip.__path__)), and need a directory named pip to hold the files and folders which originally reside in the pip package when unpacking the archive, then I need give root_dirparameter of shutil.make_archive the parent directory of the pippackage path (root_dir=Path(pip.__path__).parent), and then the base_dir parameter the final path component of the pip package path(base_dir=Path(pip.__path__).name) , so it is os.path.join(root_dir, base_dir) that specified the directory to archive , so weird !!!
I suggest to change shutil.make_archive(base_name, format[, root_dir[, base_dir]]) to shutil.make_archive(base_name, format[, archived_dir[, archive_prfix]]) where archived_dirdenotes the path to be archived and archive_prfix denotes the common prefix of all files and directories in the archive (it is just a path component and we shouldn’t assume the existence of it on the file system).
If the current behavior of shutil.make_archive won’t be changed , I’d suggest improve its doc, because so many people couldn’t grasp the use of shutil.make_archive even consulting the doc , these are the proofs:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-Dev