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: Register .whl as a unpack format in shutil unpack
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: dchimeno, domdfcoding, pdxjohnny
Priority: normal Keywords:

Created on 2020-03-04 10:24 by dchimeno, last changed 2022-04-11 14:59 by admin.

Messages (3)
msg363341 - (view) Author: Daniel Chimeno (dchimeno) * Date: 2020-03-04 10:24
While working on project with Python wheels I found myself adding:

````
import shutil
shutil.register_unpack_format('whl', ['.whl'], shutil._unpack_zipfile)

````

Since PEP 427 explicitly says wheels are ZIP-format archive. https://www.python.org/dev/peps/pep-0427/

I wonder if it's loable to register the unpack format by default so the 
shutil.unpack_archive() function works without adding it.
msg396800 - (view) Author: Dominic Davis-Foster (domdfcoding) * Date: 2021-06-30 20:44
I have run into this myself and was surprised unpack_archive didn't support wheels. I would like to see support added, and don't mind doing the work myself.

That said, I can see there being an issue with the number of supported zip-based formats ballooning: Java JARs, Android APKs etc.
However, wheels have a use case for easily extracting them -- that's how they're installed. I can't see a use case for being able to *easily* extract other formats.

If there's no opposition I will start work on a PR.
msg405008 - (view) Author: John Andersen (pdxjohnny) * Date: 2021-10-25 23:43
I ran into this today. Using a wrapper function around _make_zipfile due to https://github.com/python/cpython/blob/d5650a1738fe34f6e1db4af5f4c4edb7cae90a36/Lib/shutil.py#L817-L819 where there is a check for if the format is zip then don't pass owner and group.

```
def make_whlfile(*args, owner=None, group=None, **kwargs):
    return shutil._make_zipfile(*args, **kwargs)


shutil.register_archive_format("whl", make_whlfile, description="Wheel file")
shutil.register_unpack_format(
    "whl", [".whl"], shutil._unpack_zipfile, description="Wheel file"
)
```
History
Date User Action Args
2022-04-11 14:59:27adminsetgithub: 84027
2021-10-25 23:43:48pdxjohnnysetnosy: + pdxjohnny
messages: + msg405008
2021-06-30 20:44:45domdfcodingsetnosy: + domdfcoding

messages: + msg396800
versions: + Python 3.11, - Python 3.8, Python 3.9
2020-03-04 10:24:15dchimenocreate