Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
3ada01f
Convert return values in pep425tags.get_supported
chrahunt Nov 23, 2019
d386bb2
Copy get_supported into packaging.tags-like functions
chrahunt Nov 23, 2019
54db17c
Use _cpython_tags, _generic_tags, and _compatible_tags
chrahunt Nov 23, 2019
1c8c481
Only calculate py-compatible tags in one place
chrahunt Nov 23, 2019
480911b
Remove unused abi arg from _compatible_tags
chrahunt Nov 23, 2019
4659a78
Use packaging.tags.compatible_tags
chrahunt Nov 23, 2019
750abca
Customize python_version for packaging.tags.compatible_tags
chrahunt Nov 23, 2019
72d00dd
Customize interpreter for packaging.tags.compatible_tags
chrahunt Nov 23, 2019
2de0b7c
Customize platforms for packaging.tags.compatible_tags
chrahunt Nov 23, 2019
c514c6b
Make packaging.tags.compatible_tags unconditional
chrahunt Nov 23, 2019
b91286c
Inline packaging.tags.compatible_tags
chrahunt Nov 23, 2019
8f1c60e
Only use _cpython_tags for CPython
chrahunt Nov 23, 2019
e388df6
Remove impl from _cpython_tags
chrahunt Nov 23, 2019
5dbef5d
Use packaging.tags.cpython_tags
chrahunt Nov 23, 2019
147680a
Customize python_version for packaging.tags.cpython_tags
chrahunt Nov 23, 2019
05045e7
Customize abis for packaging.tags.cpython_tags
chrahunt Nov 23, 2019
fecfadb
Customize platforms for packaging.tags.cpython_tags
chrahunt Nov 23, 2019
56840c3
Make packaging.tags.cpython_tags unconditional
chrahunt Nov 23, 2019
1574872
Inline packaging.tags.cpython_tags
chrahunt Nov 23, 2019
fa1ec40
Remove unused abi3 branch in _generic_tags
chrahunt Nov 23, 2019
281273d
Use packaging.tags.generic_tags
chrahunt Nov 23, 2019
77dbd27
Customize interpreter for packaging.tags.generic_tags
chrahunt Nov 23, 2019
0bebeb6
Customize abis for packaging.tags.generic_tags
chrahunt Nov 23, 2019
293b778
Customize platforms for packaging.tags.generic_tags
chrahunt Nov 23, 2019
72dcd34
Make packaging.tags.generic_tags unconditional
chrahunt Nov 23, 2019
3e66ab0
Inline packaging.tags.generic_tags
chrahunt Nov 23, 2019
ad546b5
Remove unnecessary conversion in get_supported
chrahunt Nov 23, 2019
9b34435
Simplify _get_custom_platforms
chrahunt Nov 23, 2019
2455977
Remove unused manylinux auto-deduction functions
chrahunt Nov 23, 2019
7aaa705
Remove unused glibc functions
chrahunt Nov 23, 2019
896317d
Remove unused abi functions
chrahunt Nov 23, 2019
2b1b60f
Remove unused get_platform function
chrahunt Nov 23, 2019
ae21af7
Remove unused version functions
chrahunt Nov 23, 2019
d7fda71
Add news
chrahunt Nov 23, 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
Prev Previous commit
Next Next commit
Copy get_supported into packaging.tags-like functions
packaging.tags provides a simple `sys_tags` function for getting
applicable tags for the running interpreter, but it does not allow
customization of arguments.

packaging.tags provides three functions for getting custom tags:

1. `cpython_tags` - for CPython only
2. `generic_tags` - for any non-CPython Python implementation
3. `compatible_tags` - tags that are not specific to an interpreter
   implementation

Since pip allows users to provide explicit impl, platform, abi, and
version, we have to use these functions.

`cpython_tags` and `generic_tags` are mutually exclusive, and return tags
that are the highest priority. These capture the most specific tags.

`compatible_tags` are always applicable, and a lower priority since they
may just be compatible with e.g. the Python language version, but lack
any optimizations available in the interpreter-specific tags.

To be able to do a meaningful comparison between our current
implementation and the above functions, we need to segment the pip code
into pieces that look like them.

To that end, we now have copies of the current `get_supported` function,
one for each of the functions provided by packaging.tags, and will walk
through converting them to rely on packaging.tags. For each
simplification step, if desired, we can compare the implementation in
the packaging.tags function with what we're replacing in pip.

Specifically, for each function in turn, we will:

1. Refactor it locally, taking into account its new, more limited,
   responsibilities
2. Introduce the packaging.tags function for the case where there are no
   custom arguments provided
3. Customize arguments one-by-one and delegate to the packaging.tags
   function
4. When there is no pip-specific logic left, remove the intermediate
   function and use the packaging.tags function directly in
   `get_supported`

In the end all these functions will be gone again and we'll be left with
an implementation that relies solely on the tag generation in
packaging.tags.
  • Loading branch information
chrahunt committed Jan 7, 2020
commit d386bb2fffd1af7d164da44556190cbde83e8146
195 changes: 195 additions & 0 deletions src/pip/_internal/pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,201 @@ def _get_custom_platforms(arch, platform):
return arches


def _cpython_tags(
version=None, # type: Optional[str]
platform=None, # type: Optional[str]
impl=None, # type: Optional[str]
abi=None, # type: Optional[str]
):
# type: (...) -> List[Tuple[str, str, str]]
supported = [] # type: List[Tuple[str, str, str]]

# Versions must be given with respect to the preference
if version is None:
version_info = get_impl_version_info()
versions = get_all_minor_versions_as_strings(version_info)
else:
versions = [version]
current_version = versions[0]
other_versions = versions[1:]

impl = impl or interpreter_name()

abis = [] # type: List[str]

abi = abi or get_abi_tag()
if abi:
abis[0:0] = [abi]

supports_abi3 = not PY2 and impl == "cp"

if supports_abi3:
abis.append("abi3")

abis.append('none')

arches = _get_custom_platforms(platform or get_platform(), platform)

# Current version, current API (built specifically for our Python):
for abi in abis:
for arch in arches:
supported.append(('%s%s' % (impl, current_version), abi, arch))

# abi3 modules compatible with older version of Python
if supports_abi3:
for version in other_versions:
# abi3 was introduced in Python 3.2
if version in {'31', '30'}:
break
for arch in arches:
supported.append(("%s%s" % (impl, version), "abi3", arch))

# Has binaries, does not use the Python API:
for arch in arches:
supported.append(('py%s' % (current_version[0]), 'none', arch))

# No abi / arch, but requires our implementation:
supported.append(('%s%s' % (impl, current_version), 'none', 'any'))

# No abi / arch, generic Python
supported.append(('py%s' % (current_version,), 'none', 'any'))
supported.append(('py%s' % (current_version[0]), 'none', 'any'))
for version in other_versions:
supported.append(('py%s' % (version,), 'none', 'any'))

return supported


def _generic_tags(
version=None, # type: Optional[str]
platform=None, # type: Optional[str]
impl=None, # type: Optional[str]
abi=None, # type: Optional[str]
):
# type: (...) -> List[Tuple[str, str, str]]
supported = [] # type: List[Tuple[str, str, str]]

# Versions must be given with respect to the preference
if version is None:
version_info = get_impl_version_info()
versions = get_all_minor_versions_as_strings(version_info)
else:
versions = [version]
current_version = versions[0]
other_versions = versions[1:]

impl = impl or interpreter_name()

abis = [] # type: List[str]

abi = abi or get_abi_tag()
if abi:
abis[0:0] = [abi]

supports_abi3 = not PY2 and impl == "cp"

if supports_abi3:
abis.append("abi3")

abis.append('none')

arches = _get_custom_platforms(platform or get_platform(), platform)

# Current version, current API (built specifically for our Python):
for abi in abis:
for arch in arches:
supported.append(('%s%s' % (impl, current_version), abi, arch))

# abi3 modules compatible with older version of Python
if supports_abi3:
for version in other_versions:
# abi3 was introduced in Python 3.2
if version in {'31', '30'}:
break
for arch in arches:
supported.append(("%s%s" % (impl, version), "abi3", arch))

# Has binaries, does not use the Python API:
for arch in arches:
supported.append(('py%s' % (current_version[0]), 'none', arch))

# No abi / arch, but requires our implementation:
supported.append(('%s%s' % (impl, current_version), 'none', 'any'))

# No abi / arch, generic Python
supported.append(('py%s' % (current_version,), 'none', 'any'))
supported.append(('py%s' % (current_version[0]), 'none', 'any'))
for version in other_versions:
supported.append(('py%s' % (version,), 'none', 'any'))

return supported


def _compatible_tags(
version=None, # type: Optional[str]
platform=None, # type: Optional[str]
impl=None, # type: Optional[str]
abi=None, # type: Optional[str]
):
# type: (...) -> List[Tuple[str, str, str]]
supported = [] # type: List[Tuple[str, str, str]]

# Versions must be given with respect to the preference
if version is None:
version_info = get_impl_version_info()
versions = get_all_minor_versions_as_strings(version_info)
else:
versions = [version]
current_version = versions[0]
other_versions = versions[1:]

impl = impl or interpreter_name()

abis = [] # type: List[str]

abi = abi or get_abi_tag()
if abi:
abis[0:0] = [abi]

supports_abi3 = not PY2 and impl == "cp"

if supports_abi3:
abis.append("abi3")

abis.append('none')

arches = _get_custom_platforms(platform or get_platform(), platform)

# Current version, current API (built specifically for our Python):
for abi in abis:
for arch in arches:
supported.append(('%s%s' % (impl, current_version), abi, arch))

# abi3 modules compatible with older version of Python
if supports_abi3:
for version in other_versions:
# abi3 was introduced in Python 3.2
if version in {'31', '30'}:
break
for arch in arches:
supported.append(("%s%s" % (impl, version), "abi3", arch))

# Has binaries, does not use the Python API:
for arch in arches:
supported.append(('py%s' % (current_version[0]), 'none', arch))

# No abi / arch, but requires our implementation:
supported.append(('%s%s' % (impl, current_version), 'none', 'any'))

# No abi / arch, generic Python
supported.append(('py%s' % (current_version,), 'none', 'any'))
supported.append(('py%s' % (current_version[0]), 'none', 'any'))
for version in other_versions:
supported.append(('py%s' % (version,), 'none', 'any'))

return supported


def get_supported(
version=None, # type: Optional[str]
platform=None, # type: Optional[str]
Expand Down