-
-
Notifications
You must be signed in to change notification settings - Fork 33.9k
gh-85809: Ensure shutil.make_archive accepts path-like objects in all cases #143668
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
base: main
Are you sure you want to change the base?
gh-85809: Ensure shutil.make_archive accepts path-like objects in all cases #143668
Conversation
Support for path-like objects such as `Pathlib.path` in `shutil.make_archive`. The change ensures path-like support for all parameters regardless of input. Added lightweight tests and updated documentation including examples.
|
@serhiy-storchaka nicely described the suggested approach in #94844 (comment). Wondering if it is possible get a PR review for this. |
Doc/library/shutil.rst
Outdated
| *root_dir* is a directory that will be the root directory of the | ||
| archive, all paths in the archive will be relative to it; for example, | ||
| we typically chdir into *root_dir* before creating the archive. | ||
| *root_dir* is the :term:`path-like object` specifying a directory that will |
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.
Strings are also accepted. And support of path-like objects is not guaranteed -- it only works because the standard archivers support this. Explicit support in the make_archive() code is needed.
This is another undocumented implementation detail, but integer can also work (if it is a file descriptor of the open directory) on some platforms. If this worked in some cases, it would be better to ensure that it still works in that cases. We should also consider to make this an officially supported feature, like path-like objects.
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.
Done, documented as per the suggestion and ensured make_archive now supports path-like root_dir explicitly.
Regarding integer case, would it be reasonable to open a separate issue and document the integer feature there?
This change ensures
shutil.make_archiveaccepts path-like objects such asPathlib.pathfor all parameters regardless of input. Includes lightweight tests and updated documentation with refreshed examples.While
shutil.make_archivedid supportPathlib.pathinputs in some cases, this behavior was undocumented, untested and resulted in an exception ifroot_dirwasNone. This case is well described in #94844 (comment).This PR addresses the above issue following this suggested approach.
📚 Documentation preview 📚: https://cpython-previews--143668.org.readthedocs.build/