Skip to content

Commit f526f13

Browse files
authored
Merge pull request #7562 from chrahunt/maint/use-packaging-tags-interpreter-functions
Use interpreter_name and interpreter_version from packaging.tags
2 parents 4f7146c + 893faa9 commit f526f13

File tree

3 files changed

+8
-36
lines changed

3 files changed

+8
-36
lines changed

src/pip/_internal/cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
import logging
1010
import os
1111

12+
from pip._vendor.packaging.tags import interpreter_name, interpreter_version
1213
from pip._vendor.packaging.utils import canonicalize_name
1314

1415
from pip._internal.exceptions import InvalidWheelFilename
1516
from pip._internal.models.link import Link
1617
from pip._internal.models.wheel import Wheel
17-
from pip._internal.pep425tags import interpreter_name, interpreter_version
1818
from pip._internal.utils.compat import expanduser
1919
from pip._internal.utils.temp_dir import TempDirectory
2020
from pip._internal.utils.typing import MYPY_CHECK_RUNNING

src/pip/_internal/pep425tags.py

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import sysconfig
1010
from collections import OrderedDict
1111

12+
from pip._vendor.packaging.tags import interpreter_name, interpreter_version
1213
from pip._vendor.six import PY2
1314

1415
import pip._internal.utils.glibc
@@ -40,46 +41,17 @@ def get_config_var(var):
4041
return sysconfig.get_config_var(var)
4142

4243

43-
def get_abbr_impl():
44-
# type: () -> str
45-
"""Return abbreviated implementation name."""
46-
if hasattr(sys, 'pypy_version_info'):
47-
pyimpl = 'pp'
48-
elif sys.platform.startswith('java'):
49-
pyimpl = 'jy'
50-
elif sys.platform == 'cli':
51-
pyimpl = 'ip'
52-
else:
53-
pyimpl = 'cp'
54-
return pyimpl
55-
56-
57-
interpreter_name = get_abbr_impl
58-
59-
6044
def version_info_to_nodot(version_info):
6145
# type: (Tuple[int, ...]) -> str
6246
# Only use up to the first two numbers.
6347
return ''.join(map(str, version_info[:2]))
6448

6549

66-
def get_impl_ver():
67-
# type: () -> str
68-
"""Return implementation version."""
69-
impl_ver = get_config_var("py_version_nodot")
70-
if not impl_ver or get_abbr_impl() == 'pp':
71-
impl_ver = ''.join(map(str, get_impl_version_info()))
72-
return impl_ver
73-
74-
75-
interpreter_version = get_impl_ver
76-
77-
7850
def get_impl_version_info():
7951
# type: () -> Tuple[int, ...]
8052
"""Return sys.version_info-like tuple for use in decrementing the minor
8153
version."""
82-
if get_abbr_impl() == 'pp':
54+
if interpreter_name() == 'pp':
8355
# as per https://github.com/pypa/pip/issues/2882
8456
# attrs exist only on pypy
8557
return (sys.version_info[0],
@@ -107,7 +79,7 @@ def get_abi_tag():
10779
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
10880
(CPython 2, PyPy)."""
10981
soabi = get_config_var('SOABI')
110-
impl = get_abbr_impl()
82+
impl = interpreter_name()
11183
abi = None # type: Optional[str]
11284

11385
if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):
@@ -126,7 +98,7 @@ def get_abi_tag():
12698
'Py_UNICODE_SIZE', lambda: sys.maxunicode == 0x10ffff,
12799
expected=4, warn=is_cpython):
128100
u = 'u'
129-
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
101+
abi = '%s%s%s%s%s' % (impl, interpreter_version(), d, m, u)
130102
elif soabi and soabi.startswith('cpython-'):
131103
abi = 'cp' + soabi.split('-')[1]
132104
elif soabi:
@@ -417,7 +389,7 @@ def get_supported(
417389
current_version = versions[0]
418390
other_versions = versions[1:]
419391

420-
impl = impl or get_abbr_impl()
392+
impl = impl or interpreter_name()
421393

422394
abis = [] # type: List[str]
423395

tests/unit/test_pep425tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import pytest
44
from mock import patch
5+
from pip._vendor.packaging.tags import interpreter_name, interpreter_version
56

67
from pip._internal import pep425tags
78

@@ -53,8 +54,7 @@ def abi_tag_unicode(self, flags, config_vars):
5354
import pip._internal.pep425tags
5455

5556
config_vars.update({'SOABI': None})
56-
base = pip._internal.pep425tags.get_abbr_impl() + \
57-
pip._internal.pep425tags.get_impl_ver()
57+
base = interpreter_name() + interpreter_version()
5858

5959
if sys.version_info >= (3, 8):
6060
# Python 3.8 removes the m flag, so don't look for it.

0 commit comments

Comments
 (0)