Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce packaging.tags #156

Merged
merged 50 commits into from
May 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
df91acb
Ignore virtual environments
brettcannon Dec 8, 2018
c98b040
Update instructions for running pytest
brettcannon Dec 8, 2018
36120ba
Move docs over to `python -m`
brettcannon Dec 8, 2018
b9c43ce
Add pretend to dev requirements
brettcannon Dec 8, 2018
d18d9c5
Initial tags code
brettcannon Dec 8, 2018
f2f95e5
Mention the tags module in the changelog
brettcannon Dec 8, 2018
f2d4da6
Simplify code
brettcannon Dec 8, 2018
a2c1f2e
Skeleton of tags module's docs
brettcannon Dec 8, 2018
68ba7da
Rename parse_wheel_tag() to parse_wheel_filename()
brettcannon Dec 14, 2018
2b1119a
Support __fspath__() in older Python versions
brettcannon Dec 14, 2018
6231bb5
Note where the fspath() implementation came from
brettcannon Dec 15, 2018
0ccd41b
Document packaging.tags
brettcannon Dec 15, 2018
4aeaa1e
Merge branch 'master' of https://github.com/pypa/packaging into tags
brettcannon Dec 21, 2018
fc61bbb
Update link to tag spec
brettcannon Dec 21, 2018
fcade6d
Add a TODO about knowing if CPython's ABI code is too simplified
brettcannon Dec 21, 2018
759bbf3
Move to pip's glibc detection code
brettcannon Dec 21, 2018
734735b
Don't worry about coverage of fspath() taken from PEP 519
brettcannon Dec 21, 2018
741643b
test _pypy_interpreter()
brettcannon Dec 21, 2018
4edabfc
Test a branch of _generic_abi()
brettcannon Dec 21, 2018
1e526ee
Test glibc checks with mocks
brettcannon Dec 21, 2018
19cffa3
Fix test logic
brettcannon Dec 21, 2018
6f5387b
Test _generic_interpreter() with mocks
brettcannon Dec 21, 2018
859af6c
Test generic sys_tags()
brettcannon Dec 21, 2018
582c32f
Test _generic_tags() w/ no ABI
brettcannon Dec 21, 2018
741c5de
Test macOS CPU architecture detection fallback
brettcannon Dec 21, 2018
21552df
Fix test to call appropriate function
brettcannon Jan 4, 2019
7c90cec
Have a test run on all platforms
brettcannon Jan 4, 2019
207e8c3
Mark code taken from PEP 519 as not needing tests
brettcannon Jan 4, 2019
331b4d0
Add linting tools as dev dependencies
brettcannon Jan 4, 2019
d806a7b
Make pep8-naming happy
brettcannon Jan 4, 2019
daee460
Drop reST directive from the changelog
brettcannon Jan 4, 2019
0df74c5
Be more tolerant of odd SOABI values
brettcannon Jan 4, 2019
cacd2bf
Ignore all venvs
brettcannon Jan 4, 2019
9f9238e
Don't try to install black on older Python versions
brettcannon Jan 4, 2019
f2866d1
Add coverage as a dev requirement
brettcannon Jan 4, 2019
b44da16
Reach 100% coverage under Python 2.7
brettcannon Jan 4, 2019
2eefe36
Remove an extraneous blank line
brettcannon Jan 4, 2019
62269f4
Fix a comment
brettcannon Jan 4, 2019
b5ebfc8
Fix a test to not accidentally skip on Python 3
brettcannon Jan 4, 2019
e172db7
Run the code through Black
brettcannon Jan 4, 2019
8414635
Format with black
brettcannon Jan 4, 2019
91f2816
Become compatible w/ Python 3.4
brettcannon Jan 4, 2019
fbc47e8
Merge branch 'master' of https://github.com/pypa/packaging into tags
brettcannon May 8, 2019
2c7dd80
Add attrs as a dependency
brettcannon May 8, 2019
2367cb7
Address review comments
brettcannon May 8, 2019
f19c6f8
Steve Dower answered Windows questions
brettcannon May 8, 2019
073de91
Delete remnants of parse_wheel_filename()
brettcannon May 8, 2019
80e987a
Remove dead imports
brettcannon May 8, 2019
2ae6331
Remove type info
brettcannon May 8, 2019
a47a916
Fix doctest
brettcannon May 8, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ omit = packaging/_compat.py

[report]
exclude_lines =
pragma: no cover
@abc.abstractmethod
@abc.abstractproperty
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
.cache/
.coverage
.idea
.venv
.venv*

__pycache__/
_build/
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Changelog
~~~~~~~~~~~~~~~~~

* Fix string representation of PEP 508 direct URL requirements with markers.
* Add the `packaging.tags` module.

* Better handling of file URLs

Expand Down
4 changes: 4 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Install our development requirements
black; python_version >= '3.6'
coverage
flake8
pep8-naming
pretend
pytest
tox
Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ API
specifiers
markers
requirements
tags
utils


Expand Down
101 changes: 101 additions & 0 deletions docs/tags.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
Tags
====

.. currentmodule:: packaging.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
-----

.. doctest::

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

.. attribute:: INTERPRETER_SHORT_NAMES

A dictionary mapping interpreter names to their `abbreviation codes`_
(e.g. ``"cpython"`` is ``"cp"``). All interpreter names are lower-case.

.. class:: Tag(interpreter, abi, platform)

A representation of the tag triple for a wheel. Instances are considered
immutable and thus are hashable. Equality checking is also supported.

:param str interpreter: The interpreter name, e.g. ``"py"``
(see :attr:`INTERPRETER_SHORT_NAMES` for mapping
well-known interpreter names to their short names).
:param str abi: The ABI that a wheel supports, e.g. ``"cp37m"``.
:param str platform: The OS/platform the wheel supports,
e.g. ``"win_amd64"``.

.. attribute:: interpreter

The interpreter name.

.. attribute:: abi

The supported ABI.

.. attribute:: platform

The OS/platform.


.. function:: parse_tag(tag)

Parse the provided *tag* into a set of :class:`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"``.

:param str tag: The tag to parse, e.g. ``"py3-none-any"``.


.. function:: sys_tags()

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:

1. Interpreter
2. Platform
3. 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.


.. _abbreviation codes: https://www.python.org/dev/peps/pep-0425/#python-tag
.. _compressed tag set: https://www.python.org/dev/peps/pep-0425/#compressed-tag-sets
.. _platform compatibility tags: https://packaging.python.org/specifications/platform-compatibility-tags/
.. _PEP 425: https://www.python.org/dev/peps/pep-0425/
Loading