Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I list the files inside a python wheel?

I'm poking around the various options to setup.py for including non-python files, and they're somewhat less than intuitive. I'd like to be able to check the package generated by bdist_wheel to see what's actually in it--not so much to make sure that it will work (that's what tests are for) but to see the effects of the options I've set.

How do I list the files contained in a .whl?

like image 654
Andrew Avatar asked Oct 03 '15 14:10

Andrew


People also ask

What is inside a Python wheel?

A Python . whl file is essentially a ZIP ( . zip ) archive with a specially crafted filename that tells installers what Python versions and platforms the wheel will support. A wheel is a type of built distribution.

How do I check wheel dependencies in Python?

Pip Check Command – Check Python Dependencies After Installation. Because pip doesn't currently address dependency issues on installation, the pip check command option can be used to verify that dependencies have been installed properly in your project. For example: $ pip check No broken requirements found.

How do I edit WHL files?

you can open the whl file using 7zip or something alike, track the file you wish to change, open in edit mode, save it, next 7zip will popup a message saying something was modified and if you want the change to be saved, press yes and youre good to go. remember to backup your original whl before doing it..


2 Answers

You can take the wheel file change the extension to .zip and then extract the contents like any other zip file.

from PEP 427

A wheel is a ZIP-format archive with a specially formatted file name and the .whl extension.

Example

the Django python package has a wheel file. Try Django-1.8.4-py2.py3-none-any.whl as an example. Their package contains non-python files if you wanted to see where they end up being stored in the archive.

Code

The following code works correctly using python2 and python3. It will list the files in any wheel package. I use the pep8 wheel package as an example, whose wheel can be downloaded with pip download --no-deps pep8==1.7.0.

import pprint from zipfile import ZipFile  path = 'pep8-1.7.0-py2.py3-none-any.whl' names = ZipFile(path).namelist() pprint.pprint(names) 

Output

['pep8.py',  'pep8-1.7.0.dist-info/DESCRIPTION.rst',  'pep8-1.7.0.dist-info/entry_points.txt',  'pep8-1.7.0.dist-info/metadata.json',  'pep8-1.7.0.dist-info/namespace_packages.txt',  'pep8-1.7.0.dist-info/top_level.txt',  'pep8-1.7.0.dist-info/WHEEL',  'pep8-1.7.0.dist-info/METADATA',  'pep8-1.7.0.dist-info/RECORD'] 
like image 172
Marwan Alsabbagh Avatar answered Sep 21 '22 13:09

Marwan Alsabbagh


unzip -l dist/*.whl 

(credit)

Since a wheel is a ZIP file, unzip works. Tab completion for the file name won't work, unless the extension is renamed to zip. The from zipfile import ZipFile approach assumes only the presence of Python in the system, but a one-liner in the shell is more practical.


Another option is to view the contents of the wheel file using vim. This can be done by first adding to the file ~/.vimrc the line:

au BufReadCmd *.whl call zip#Browse(expand("<amatch>")) 

(vimrc and BufReadCmd documentation) and then using:

vim filename.whl 

within vim, files can be entered by pressing the key ENTER, and exited by typing :q. vim can be exited by typing :q when viewing the directory listing within the wheel file.

like image 43
Ioannis Filippidis Avatar answered Sep 23 '22 13:09

Ioannis Filippidis