Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
555 views
in Technique[技术] by (71.8m points)

package - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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']

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...