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: tarfile does not support pathlib
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.7, Python 3.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, brett.cannon, ethan.furman, lars.gustaebel, ned.deily, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2016-09-21 07:31 by ethan.furman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
open-tarfile.stoneleaf.patch ethan.furman, 2016-09-21 07:31 review
issue28230_v2.diff berker.peksag, 2016-10-10 13:04 review
test_tarfile_pathlike.patch serhiy.storchaka, 2016-10-10 21:06 review
Pull Requests
URL Status Linked Edit
PR 512 merged serhiy.storchaka, 2017-03-06 11:37
PR 559 merged serhiy.storchaka, 2017-03-08 09:17
Messages (9)
msg278414 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-10-10 13:04
Here's an updated patch with different tests and documentation changes. I simplified Lib/tarfile.py a bit (see my review comments)

A slightly off-topic question: I had to update both docstrings and documentation. Should we use this as an opportunity to simplify the docstrings?
msg278416 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-10 13:36
There are two kinds of paths in tarinfo:

1) External paths that correspond to filesystem paths. The path of the tar file itself, patches of added files and target directory for extraction. Supporting path protocol looks reasonable for them.

1) Internal paths, they are just string keys inside an archive. They come from TarFile.getnames() and always are strings. I'm not sure that pathlib have relation to this. This issue needs more thoughts. I would not haste with this.
msg278428 - (view) Author: Ethan Furman (ethan.furman) * (Python committer) Date: 2016-10-10 16:45
As Serhiy was alluding to, if the incoming path is for the actual tar file and is only passed along to Python itself then we probably don't need to worry about os.fspath().  For names that will be interally stored, or are for accessing internal files, then the proper sequence is check for and call os.fspath if necessary, and then double-check that the name to be used is a str.  The double-check is needed because os.fspath may return a bytes object, which tar does not allow.
msg278444 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-10-10 21:06
It seems to me that tarfile already supports path protocol for all external patches and no changes for tarfile are needed.

Proposed patch adds tests for (already implemented) support of pathlike protocol in tarfile.
msg288604 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-02-26 17:21
Serhiy's patch looks good to me, but it would be nice to document the support for PathLike objects in the tarfile documentation.
msg289096 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-06 11:41
Updated documentation.

Note that path-like objects are supported only for external names. Internal names are not OS paths.
msg289671 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-03-15 12:52
PR 512 has been merged and backported to 3.6 branch. I think this can be closed now. Thanks, Ethan and Serhiy!
msg290265 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 22:41
New changeset 666165fddf499e80d10a5d9263846ec4534f6a2a by Serhiy Storchaka in branch '3.6':
[3.6] bpo-28230: Document the pathlib support in tarfile and add tests. (#559)
https://github.com/python/cpython/commit/666165fddf499e80d10a5d9263846ec4534f6a2a
msg290267 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-03-24 22:41
New changeset c45cd167d403d7d98078d5fc4a37b16195dc7a35 by Serhiy Storchaka in branch 'master':
bpo-28230: Document the pathlib support in tarfile and add tests. (#512)
https://github.com/python/cpython/commit/c45cd167d403d7d98078d5fc4a37b16195dc7a35
History
Date User Action Args
2022-04-11 14:58:37adminsetgithub: 72417
2017-03-24 22:41:49serhiy.storchakasetmessages: + msg290267
2017-03-24 22:41:28serhiy.storchakasetmessages: + msg290265
2017-03-15 12:52:09berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg289671

stage: patch review -> resolved
2017-03-08 09:17:05serhiy.storchakasetpull_requests: + pull_request460
2017-03-06 11:41:06serhiy.storchakasetmessages: + msg289096
2017-03-06 11:37:55serhiy.storchakasetpull_requests: + pull_request421
2017-02-26 17:21:40berker.peksagsetmessages: + msg288604
2016-10-10 21:06:20serhiy.storchakasetfiles: + test_tarfile_pathlike.patch

messages: + msg278444
2016-10-10 18:59:40ned.deilysetnosy: + lars.gustaebel
2016-10-10 16:45:16ethan.furmansetmessages: + msg278428
2016-10-10 13:36:42serhiy.storchakasetmessages: + msg278416
2016-10-10 13:04:44berker.peksagsetfiles: + issue28230_v2.diff

messages: + msg278414
2016-10-05 10:36:18berker.peksagsetcomponents: + Library (Lib)
2016-10-05 09:26:45berker.peksagsetnosy: + berker.peksag
2016-09-23 21:34:43ned.deilysetnosy: + ned.deily

versions: + Python 3.7
2016-09-21 08:14:19serhiy.storchakasetnosy: + serhiy.storchaka
2016-09-21 07:31:34ethan.furmancreate