如何列出 python 轮中的文件? [英] How do I list the files inside a python wheel?

查看:50
本文介绍了如何列出 python 轮中的文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索 setup.py 的各种选项以包含非 Python 文件,但它们有点不够直观.我希望能够检查由 bdist_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.

如何列出 .whl 中包含的文件?

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

推荐答案

您可以将wheel文件的扩展名更改为.zip,然后像任何其他zip文件一样提取内容.

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

来自 PEP 427

轮子是 ZIP 格式的存档文件,具有特殊格式的文件名和 .whl 扩展名.

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

示例

Django python 包有一个wheel文件.试试 Django-1.8.4-py2.py3-none-any.whl 为例.如果您想查看它们最终存储在存档中的位置,他们的包包含非 Python 文件.

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.

代码

以下代码在 python2 和 python3 中正常工作.它将列出任何车轮包中的文件.我以pep8轮包为例.

The following code works correctly in python2 and python3. It will list the files in any wheel package. I use the pep8 wheel package as an example.

from zipfile import ZipFile
path = '/tmp/pep8-1.7.0-py2.py3-none-any.whl'
print(ZipFile(path).namelist())

输出

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

这篇关于如何列出 python 轮中的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆