Skip to content

Use interpreter_name and interpreter_version from packaging.tags #7562

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import logging
import os

from pip._vendor.packaging.tags import interpreter_name, interpreter_version
from pip._vendor.packaging.utils import canonicalize_name

from pip._internal.exceptions import InvalidWheelFilename
from pip._internal.models.link import Link
from pip._internal.models.wheel import Wheel
from pip._internal.pep425tags import interpreter_name, interpreter_version
from pip._internal.utils.compat import expanduser
from pip._internal.utils.temp_dir import TempDirectory
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
Expand Down
38 changes: 5 additions & 33 deletions src/pip/_internal/pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sysconfig
from collections import OrderedDict

from pip._vendor.packaging.tags import interpreter_name, interpreter_version
from pip._vendor.six import PY2

import pip._internal.utils.glibc
Expand Down Expand Up @@ -40,46 +41,17 @@ def get_config_var(var):
return sysconfig.get_config_var(var)


def get_abbr_impl():
# type: () -> str
"""Return abbreviated implementation name."""
if hasattr(sys, 'pypy_version_info'):
pyimpl = 'pp'
elif sys.platform.startswith('java'):
pyimpl = 'jy'
elif sys.platform == 'cli':
pyimpl = 'ip'
else:
pyimpl = 'cp'
return pyimpl


interpreter_name = get_abbr_impl


def version_info_to_nodot(version_info):
# type: (Tuple[int, ...]) -> str
# Only use up to the first two numbers.
return ''.join(map(str, version_info[:2]))


def get_impl_ver():
# type: () -> str
"""Return implementation version."""
impl_ver = get_config_var("py_version_nodot")
if not impl_ver or get_abbr_impl() == 'pp':
impl_ver = ''.join(map(str, get_impl_version_info()))
return impl_ver


interpreter_version = get_impl_ver


def get_impl_version_info():
# type: () -> Tuple[int, ...]
"""Return sys.version_info-like tuple for use in decrementing the minor
version."""
if get_abbr_impl() == 'pp':
if interpreter_name() == 'pp':
# as per https://github.com/pypa/pip/issues/2882
# attrs exist only on pypy
return (sys.version_info[0],
Expand Down Expand Up @@ -107,7 +79,7 @@ def get_abi_tag():
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
(CPython 2, PyPy)."""
soabi = get_config_var('SOABI')
impl = get_abbr_impl()
impl = interpreter_name()
abi = None # type: Optional[str]

if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):
Expand All @@ -126,7 +98,7 @@ def get_abi_tag():
'Py_UNICODE_SIZE', lambda: sys.maxunicode == 0x10ffff,
expected=4, warn=is_cpython):
u = 'u'
abi = '%s%s%s%s%s' % (impl, get_impl_ver(), d, m, u)
abi = '%s%s%s%s%s' % (impl, interpreter_version(), d, m, u)
elif soabi and soabi.startswith('cpython-'):
abi = 'cp' + soabi.split('-')[1]
elif soabi:
Expand Down Expand Up @@ -396,7 +368,7 @@ def get_supported(
current_version = versions[0]
other_versions = versions[1:]

impl = impl or get_abbr_impl()
impl = impl or interpreter_name()

abis = [] # type: List[str]

Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import pytest
from mock import patch
from pip._vendor.packaging.tags import interpreter_name, interpreter_version

from pip._internal import pep425tags

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

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

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