[Python-Dev] ​improvement on shutil.make_archive

356 views
Skip to first unread message

Zhao Lee

unread,
Aug 20, 2018, 10:58:06 AM8/20/18
to python-dev
The current behavior of shutil.make_archive caused many issues , the problem is mainly on the extracted archive directory hierarchy. These are the proofs:

https://stackoverflow.com/questions/50156657/unexpected-file-using-shutil-make-archive-to-compress-file
For example , if I want to create a zip archive of the pip package (path specified by pip.__path__[0])), 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__[0]).parent), and then the base_dir parameter the final path component of the pip package path(base_dir=Path(pip.__path__[0]).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:
https://stackoverflow.com/questions/45245079/python-how-to-use-shutil-make-archive
https://stackoverflow.com/questions/30049201/how-to-compress-a-file-with-shutil-make-archive-in-python






 

Paul Moore

unread,
Aug 20, 2018, 11:21:14 AM8/20/18
to redsto...@163.com, Python Dev

Thanks for your interest, and for pointing out this problem.
Personally, I don't see that much of an issue with the current
documentation of base_dir and root_dir. But as a native English
speaker with a pretty long history of working with and reading
programming documentation, that's easy for me to say...

I expect that PR suggesting some improvements to the documentation
would be very welcome - in particular, the section would almost
certainly benefit from some examples. If that's something you'd feel
comfortable doing, that would be great.

Paul
_______________________________________________
Python-Dev mailing list
Pytho...@python.org
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: https://mail.python.org/mailman/options/python-dev/dev-python%2Bgarchive-30976%40googlegroups.com

Serhiy Storchaka

unread,
Aug 20, 2018, 1:29:27 PM8/20/18
to pytho...@python.org
20.08.18 18:18, Paul Moore пише:

> I expect that PR suggesting some improvements to the documentation
> would be very welcome - in particular, the section would almost
> certainly benefit from some examples. If that's something you'd feel
> comfortable doing, that would be great.

There is an open documentation issue for shutil.make_archive():
https://bugs.python.org/issue22021

Reply all
Reply to author
Forward
0 new messages