-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: do not rely on packaging module for generating wheel tags
The generated tags are tested checking against what the packaging module generates. This should ensure that the two implementations will not diverge.
- Loading branch information
Showing
6 changed files
with
172 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
# SPDX-License-Identifier: MIT | ||
|
||
import os | ||
import platform | ||
import subprocess | ||
import sys | ||
import sysconfig | ||
|
||
from typing import Optional, Union | ||
|
||
|
||
# https://peps.python.org/pep-0425/#python-tag | ||
INTERPRETERS = { | ||
'python': 'py', | ||
'cpython': 'cp', | ||
'pypy': 'pp', | ||
'ironpython': 'ip', | ||
'jython': 'jy', | ||
} | ||
|
||
|
||
def get_interpreter_tag() -> str: | ||
name = sys.implementation.name | ||
name = INTERPRETERS.get(name, name) | ||
if name in {'cp', 'pp'}: | ||
version = sys.version_info | ||
return f'{name}{version[0]}{version[1]}' | ||
return name | ||
|
||
|
||
def _get_config_var(name: str, default: Union[str, int, None] = None) -> Union[str, int, None]: | ||
value = sysconfig.get_config_var(name) | ||
if value is None: | ||
return default | ||
return value | ||
|
||
|
||
def _get_cpython_abi() -> str: | ||
version = sys.version_info | ||
debug = pymalloc = '' | ||
if _get_config_var('Py_DEBUG', hasattr(sys, 'gettotalrefcount')): | ||
debug = 'd' | ||
if sys.version_info < (3, 8) and _get_config_var('WITH_PYMALLOC', True): | ||
pymalloc = 'm' | ||
return f'cp{version[0]}{version[1]}{debug}{pymalloc}' | ||
|
||
|
||
def get_abi_tag() -> str: | ||
abi = sysconfig.get_config_var('SOABI') | ||
if not abi: | ||
# CPython on Windows does not have a SOABI sysconfig variable. | ||
assert sys.implementation.name == 'cpython' | ||
return _get_cpython_abi() | ||
if abi.startswith('cpython'): | ||
return 'cp' + abi.split('-')[1] | ||
if abi.startswith('pypy'): | ||
return '_'.join(abi.split('-')[:2]) | ||
return abi.replace('.', '_').replace('-', '_') | ||
|
||
|
||
def _get_macosx_platform_tag() -> str: | ||
ver, x, arch = platform.mac_ver() | ||
|
||
# Override the macOS version if one is provided via the | ||
# MACOS_DEPLOYMENT_TARGET environment variable. Return it | ||
# unchanged otherwise. | ||
try: | ||
version = tuple(map(int, os.environ.get('MACOS_DEPLOYMENT_TARGET', '').split('.')))[:2] | ||
except ValueError: | ||
version = None | ||
|
||
if version is None: | ||
version = tuple(map(int, ver.split('.')))[:2] | ||
if version == (10, 16): | ||
# When built against an older macOS SDK, Python will | ||
# report macOS 10.16 instead of the real version. | ||
ver = subprocess.check_output( | ||
[ | ||
sys.executable, | ||
'-sS', | ||
'-c', | ||
'import platform; print(platform.mac_ver()[0])' | ||
], | ||
env={'SYSTEM_VERSION_COMPAT': '0'}, | ||
universal_newlines=True) | ||
version = tuple(map(int, ver.split('.')[:2])) | ||
|
||
major, minor = version | ||
if major >= 11: | ||
minor = 0 | ||
|
||
if sys.maxsize <= 2**32: | ||
if arch.startswith('ppc'): | ||
arch = 'ppc' | ||
arch = 'i386' | ||
|
||
return f'macosx_{major}_{minor}_{arch}' | ||
|
||
|
||
def get_platform_tag() -> str: | ||
platform = sysconfig.get_platform() | ||
if platform.startswith('macosx'): | ||
return _get_macosx_platform_tag() | ||
if sys.maxsize <= 2**32: | ||
if platform == 'linux-x86_64': | ||
return 'linux_i686' | ||
if platform == 'linux-aarch64': | ||
return 'linux_armv7l' | ||
return platform.replace('-', '_') | ||
|
||
|
||
class Tag: | ||
def __init__(self, interpreter: Optional[str] = None, abi: Optional[str] = None, platform: Optional[str] = None): | ||
self.interpreter = interpreter or get_interpreter_tag() | ||
self.abi = abi or get_abi_tag() | ||
self.platform = platform or get_platform_tag() | ||
|
||
def __str__(self) -> str: | ||
return f'{self.interpreter}-{self.abi}-{self.platform}' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters