The documentation says that Python Wheel is a binary distribution format. To understand the difference between the source code and binaries distributed within a Python wheel, I am manually inspecting a .whl
file from the package django
. The specific .whl
I am looking at is this. I decompressed the wheel file and the top-level directory of the file looks like this:
.
├── Django-3.2.9.data
├── Django-3.2.9.dist-info
└── django
The Django-3.2.9.data
file contains a script called admin.py
. The directory structure for Django-3.2.9.dist-info
looks like this:
.
├── AUTHORS
├── LICENSE
├── LICENSE.python
├── METADATA
├── RECORD
├── WHEEL
├── entry_points.txt
└── top_level.txt
The WHEEL
file in this directory seems to contain information of the WHEEL version that was used to build this .whl
.
The top-level directory structure for the django
file looks like this:
.
├── __init__.py
├── __main__.py
├── apps
├── bin
├── conf
├── contrib
├── core
├── db
├── dispatch
├── forms
├── http
├── middleware
├── shortcuts.py
├── template
├── templatetags
├── test
├── urls
├── utils
└── views
Here, except the bin
folder, all the other files are source code files that are present on the django repository. Therefore, my guess was that the bin
folder would contain binaries of the package. However, the folder only contains another python file named django-admin.py
.
Therefore, my question is:
(1) Does python wheel actually contain a binary? If yes, then how to locate the binary within the .whl
file?
(2) If the python wheel distributes a binary, then how does wheel distribution ensure that the binary is built from the same source code present in the .whl
file? For this question, my guess is the source-to-binary integrity is ensured through checksums for each file stored in the Django-3.2.9.dist-info/RECORD
file. Is that correct?
CodePudding user response:
Therefore, my guess was that the bin folder would contain binaries of the package.
That's incorrect. Django just happens to have a bin
directory, since it houses the django-admin
command line tool.
Does python wheel actually contain a binary? If yes, then how to locate the binary within the .whl file?
Yes, if there is something that needs to be a compiled binary. For instance, a NumPy wheel would have multiple .so
(Linux/macOS) or .pyd
(Windows) files (Python extension modules). Their location within the .whl depends on the package.
You can tell whether a .whl contains binary Pyt .whl does not contain binary modules from the name: Django-3.2.9-py3-none-any.whl
. Compare to e.g. Numpy's numpy-1.21.4-cp310-cp310-win_amd64.whl
(containing binary modules for CPython 3.10 on Windows, AMD64 architecture).
If there's other binary package data, such as an image that the package requires, that would be in the .whl too. For Django, you will likely find Gettext .mo
files.
If the python wheel distributes a binary, then how does wheel distribution ensure that the binary is built from the same source code present in the .whl file?
Source code for binary modules is just generally not included in .whls.