mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Remove unused abi functions
Previously, these were used when the user did not provide an explicit ABI. Now this is handled internally in `packaging.tags` (by `_cpython_abi` and `_generic_abi`).
This commit is contained in:
parent
7aaa705c15
commit
896317d13d
|
@ -6,7 +6,6 @@ import logging
|
|||
import platform
|
||||
import re
|
||||
import sys
|
||||
import sysconfig
|
||||
|
||||
from pip._vendor.packaging.tags import (
|
||||
Tag,
|
||||
|
@ -21,9 +20,7 @@ from pip._vendor.packaging.tags import (
|
|||
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
|
||||
|
||||
if MYPY_CHECK_RUNNING:
|
||||
from typing import (
|
||||
Callable, List, Optional, Tuple, Union
|
||||
)
|
||||
from typing import List, Optional, Tuple
|
||||
|
||||
from pip._vendor.packaging.tags import PythonVersion
|
||||
|
||||
|
@ -32,11 +29,6 @@ logger = logging.getLogger(__name__)
|
|||
_osx_arch_pat = re.compile(r'(.+)_(\d+)_(\d+)_(.+)')
|
||||
|
||||
|
||||
def get_config_var(var):
|
||||
# type: (str) -> Optional[str]
|
||||
return sysconfig.get_config_var(var)
|
||||
|
||||
|
||||
def version_info_to_nodot(version_info):
|
||||
# type: (Tuple[int, ...]) -> str
|
||||
# Only use up to the first two numbers.
|
||||
|
@ -57,52 +49,6 @@ def get_impl_version_info():
|
|||
return sys.version_info[0], sys.version_info[1]
|
||||
|
||||
|
||||
def get_flag(var, fallback, expected=True, warn=True):
|
||||
# type: (str, Callable[..., bool], Union[bool, int], bool) -> bool
|
||||
"""Use a fallback method for determining SOABI flags if the needed config
|
||||
var is unset or unavailable."""
|
||||
val = get_config_var(var)
|
||||
if val is None:
|
||||
if warn:
|
||||
logger.debug("Config variable '%s' is unset, Python ABI tag may "
|
||||
"be incorrect", var)
|
||||
return fallback()
|
||||
return val == expected
|
||||
|
||||
|
||||
def get_abi_tag():
|
||||
# type: () -> Optional[str]
|
||||
"""Return the ABI tag based on SOABI (if available) or emulate SOABI
|
||||
(CPython 2, PyPy)."""
|
||||
soabi = get_config_var('SOABI')
|
||||
impl = interpreter_name()
|
||||
abi = None # type: Optional[str]
|
||||
|
||||
if not soabi and impl in {'cp', 'pp'} and hasattr(sys, 'maxunicode'):
|
||||
d = ''
|
||||
m = ''
|
||||
u = ''
|
||||
is_cpython = (impl == 'cp')
|
||||
if get_flag(
|
||||
'Py_DEBUG', lambda: hasattr(sys, 'gettotalrefcount'),
|
||||
warn=is_cpython):
|
||||
d = 'd'
|
||||
if sys.version_info < (3, 8) and get_flag(
|
||||
'WITH_PYMALLOC', lambda: is_cpython, warn=is_cpython):
|
||||
m = 'm'
|
||||
if sys.version_info < (3, 3) and get_flag(
|
||||
'Py_UNICODE_SIZE', lambda: sys.maxunicode == 0x10ffff,
|
||||
expected=4, warn=is_cpython):
|
||||
u = '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:
|
||||
abi = soabi.replace('.', '_').replace('-', '_')
|
||||
|
||||
return abi
|
||||
|
||||
|
||||
def _is_running_32bit():
|
||||
# type: () -> bool
|
||||
return sys.maxsize == 2147483647
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
import sys
|
||||
import sysconfig
|
||||
|
||||
import pytest
|
||||
from mock import patch
|
||||
from pip._vendor.packaging.tags import interpreter_name, interpreter_version
|
||||
|
||||
from pip._internal import pep425tags
|
||||
|
||||
|
@ -28,9 +27,7 @@ class TestPEP425Tags(object):
|
|||
"""
|
||||
Patch sysconfig.get_config_var for arbitrary keys.
|
||||
"""
|
||||
import pip._internal.pep425tags
|
||||
|
||||
get_config_var = pip._internal.pep425tags.sysconfig.get_config_var
|
||||
get_config_var = sysconfig.get_config_var
|
||||
|
||||
def _mock_get_config_var(var):
|
||||
if var in kwd:
|
||||
|
@ -38,45 +35,6 @@ class TestPEP425Tags(object):
|
|||
return get_config_var(var)
|
||||
return _mock_get_config_var
|
||||
|
||||
def abi_tag_unicode(self, flags, config_vars):
|
||||
"""
|
||||
Used to test ABI tags, verify correct use of the `u` flag
|
||||
"""
|
||||
import pip._internal.pep425tags
|
||||
|
||||
config_vars.update({'SOABI': None})
|
||||
base = interpreter_name() + interpreter_version()
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
# Python 3.8 removes the m flag, so don't look for it.
|
||||
flags = flags.replace('m', '')
|
||||
|
||||
if sys.version_info < (3, 3):
|
||||
config_vars.update({'Py_UNICODE_SIZE': 2})
|
||||
mock_gcf = self.mock_get_config_var(**config_vars)
|
||||
with patch('pip._internal.pep425tags.sysconfig.get_config_var',
|
||||
mock_gcf):
|
||||
abi_tag = pip._internal.pep425tags.get_abi_tag()
|
||||
assert abi_tag == base + flags
|
||||
|
||||
config_vars.update({'Py_UNICODE_SIZE': 4})
|
||||
mock_gcf = self.mock_get_config_var(**config_vars)
|
||||
with patch('pip._internal.pep425tags.sysconfig.get_config_var',
|
||||
mock_gcf):
|
||||
abi_tag = pip._internal.pep425tags.get_abi_tag()
|
||||
assert abi_tag == base + flags + 'u'
|
||||
|
||||
else:
|
||||
# On Python >= 3.3, UCS-4 is essentially permanently enabled, and
|
||||
# Py_UNICODE_SIZE is None. SOABI on these builds does not include
|
||||
# the 'u' so manual SOABI detection should not do so either.
|
||||
config_vars.update({'Py_UNICODE_SIZE': None})
|
||||
mock_gcf = self.mock_get_config_var(**config_vars)
|
||||
with patch('pip._internal.pep425tags.sysconfig.get_config_var',
|
||||
mock_gcf):
|
||||
abi_tag = pip._internal.pep425tags.get_abi_tag()
|
||||
assert abi_tag == base + flags
|
||||
|
||||
def test_no_hyphen_tag(self):
|
||||
"""
|
||||
Test that no tag contains a hyphen.
|
||||
|
@ -85,8 +43,7 @@ class TestPEP425Tags(object):
|
|||
|
||||
mock_gcf = self.mock_get_config_var(SOABI='cpython-35m-darwin')
|
||||
|
||||
with patch('pip._internal.pep425tags.sysconfig.get_config_var',
|
||||
mock_gcf):
|
||||
with patch('sysconfig.get_config_var', mock_gcf):
|
||||
supported = pip._internal.pep425tags.get_supported()
|
||||
|
||||
for tag in supported:
|
||||
|
@ -94,30 +51,6 @@ class TestPEP425Tags(object):
|
|||
assert '-' not in tag.abi
|
||||
assert '-' not in tag.platform
|
||||
|
||||
def test_manual_abi_noflags(self):
|
||||
"""
|
||||
Test that no flags are set on a non-PyDebug, non-Pymalloc ABI tag.
|
||||
"""
|
||||
self.abi_tag_unicode('', {'Py_DEBUG': False, 'WITH_PYMALLOC': False})
|
||||
|
||||
def test_manual_abi_d_flag(self):
|
||||
"""
|
||||
Test that the `d` flag is set on a PyDebug, non-Pymalloc ABI tag.
|
||||
"""
|
||||
self.abi_tag_unicode('d', {'Py_DEBUG': True, 'WITH_PYMALLOC': False})
|
||||
|
||||
def test_manual_abi_m_flag(self):
|
||||
"""
|
||||
Test that the `m` flag is set on a non-PyDebug, Pymalloc ABI tag.
|
||||
"""
|
||||
self.abi_tag_unicode('m', {'Py_DEBUG': False, 'WITH_PYMALLOC': True})
|
||||
|
||||
def test_manual_abi_dm_flags(self):
|
||||
"""
|
||||
Test that the `dm` flags are set on a PyDebug, Pymalloc ABI tag.
|
||||
"""
|
||||
self.abi_tag_unicode('dm', {'Py_DEBUG': True, 'WITH_PYMALLOC': True})
|
||||
|
||||
|
||||
class TestManylinux2010Tags(object):
|
||||
|
||||
|
|
Loading…
Reference in a new issue