Consider the following pyproject.toml
:
[build-system]
requires = ["setuptools>=40.8.0", "wheel"]
[project]
name = "foo"
version = "0.0.0"
requires-python = "~=3.9"
If I run pip wheel.
in the directory containing this file, then I generate a wheel named foo-0.0.0-py3-none-any.whl
. However, this wheel filename indicates that any python3 interpreter is fine, yet my requires-python
metadata in my pyproject.toml
indicates that only python3.9 is acceptable.
How can I get the requires-python
metadata to be reflected in the wheel? I would expect the wheel filename to be foo-0.0.0-cp39-cp39-any.whl
in this case. . .
That is not quite what the platform tag in the wheel filename is used for - cp39 would indicate that you're only compatible with CPython 3.9 or higher, and this wheel should not be selected by PyPy or some other implementations. You would usually only use a compatibility tag like that if you had some compiled C extensions inside the wheel that are CPython-specific.
The Requires-Python metadata is still located inside your built wheel, which you'll see if you try to install it on an incompatible Python version:
$ python3.8 -m pip install ./foo-0.0.0-py3-none-any.whl
Processing ./foo-0.0.0-py3-none-any.whl
ERROR: Package 'foo' requires a different Python: 3.8.13 not in '~=3.9'
The location of the metadata is here:
$ unzip foo-0.0.0-py3-none-any.whl
Archive: foo-0.0.0-py3-none-any.whl
inflating: foo-0.0.0.dist-info/METADATA
inflating: foo-0.0.0.dist-info/WHEEL
inflating: foo-0.0.0.dist-info/top_level.txt
inflating: foo-0.0.0.dist-info/RECORD
$ grep Requires foo-0.0.0.dist-info/METADATA
Requires-Python: ~=3.9
As for how this works with PyPI - the index may return this metadata in the json API ( example ) and in the simple API ( example ) † . That allows pip to avoid downloading and unpacking incompatible wheels.
† It's in a data-requires-python
attribute of the href - you might have to "view-source" in your browser to see it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.