Skip to content
Merged
Show file tree
Hide file tree
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
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`).
  • Loading branch information
chrahunt committed Jan 8, 2020
commit 896317d13d9bccf75b9cb35a37a83d93d3d2e55b
56 changes: 1 addition & 55 deletions src/pip/_internal/pep425tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import platform
import re
import sys
import sysconfig

from pip._vendor.packaging.tags import (
Tag,
Expand All @@ -21,9 +20,7 @@
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

Expand All @@ -32,11 +29,6 @@
_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):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

follow up: I suggest moving the call to be changed -- changing get_supported to allow for version to be None (and use this value in that case).

# type: (Tuple[int, ...]) -> str
# Only use up to the first two numbers.
Expand All @@ -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
Expand Down
73 changes: 3 additions & 70 deletions tests/unit/test_pep425tags.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -28,55 +27,14 @@ def mock_get_config_var(self, **kwd):
"""
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:
return kwd[var]
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.
Expand All @@ -85,39 +43,14 @@ def test_no_hyphen_tag(self):

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:
assert '-' not in tag.interpreter
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):

Expand Down