Tags¶
Wheels encode the Python interpreter, ABI, and platform that they support in their filenames using `platform compatibility tags`_. This module provides support for both parsing these tags as well as discovering what tags the running Python interpreter supports.
Usage¶
>>> from packaging.tags import Tag, sys_tags
>>> import sys
>>> looking_for = Tag("py{major}".format(major=sys.version_info.major), "none", "any")
>>> supported_tags = list(sys_tags())
>>> looking_for in supported_tags
True
>>> really_old = Tag("py1", "none", "any")
>>> wheels = {really_old, looking_for}
>>> best_wheel = None
>>> for supported_tag in supported_tags:
... for wheel_tag in wheels:
... if supported_tag == wheel_tag:
... best_wheel = wheel_tag
... break
>>> best_wheel == looking_for
True
Reference¶
A dictionary mapping interpreter names to their abbreviation codes (e.g.
"cpython"
is"cp"
). All interpreter names are lower-case.
A representation of the tag triple for a wheel. Instances are considered immutable and thus are hashable. Equality checking is also supported.
Parameters: - interpreter (str) – The interpreter name, e.g.
"py"
(seeINTERPRETER_SHORT_NAMES
for mapping well-known interpreter names to their short names). - abi (str) – The ABI that a wheel supports, e.g.
"cp37m"
. - platform (str) – The OS/platform the wheel supports,
e.g.
"win_amd64"
.
The interpreter name.
The supported ABI.
The OS/platform.
- interpreter (str) – The interpreter name, e.g.
Parse the provided tag into a set of
Tag
instances.The returning of a set is required due to the possibility that the tag is a compressed tag set, e.g.
"py2.py3-none-any"
.Parameters: tag (str) – The tag to parse, e.g. "py3-none-any"
.
Create an iterable of tags that the running interpreter supports.
The iterable is ordered so that the best-matching tag is first in the sequence. The exact preferential order to tags is interpreter-specific, but in general the tag importance is in the order of:
- Interpreter
- Platform
- ABI
This order is due to the fact that an ABI is inherently tied to the platform, but platform-specific code is not necessarily tied to the ABI. The interpreter is the most important tag as it dictates basic support for any wheel.
The function returns an iterable in order to allow for the possible short-circuiting of tag generation if the entire sequence is not necessary and calculating some tags happens to be expensive.