def test_warn(self, monkeypatch): class MockConfigVar(object): def __init__(self, return_): self.warn = None self._return = return_ def __call__(self, name, warn): self.warn = warn return self._return mock_config_var = MockConfigVar("38") monkeypatch.setattr(tags, "_get_config_var", mock_config_var) tags.interpreter_version(warn=True) assert mock_config_var.warn
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 = tags.interpreter_name() if not soabi and impl in ('cp', 'pp') and hasattr(sys, 'maxunicode'): d = '' m = '' u = '' if get_flag('Py_DEBUG', hasattr(sys, 'gettotalrefcount'), warn=(impl == 'cp')): d = 'd' if get_flag('WITH_PYMALLOC', impl == 'cp', warn=(impl == 'cp' and sys.version_info < (3, 8))) \ and sys.version_info < (3, 8): m = 'm' if get_flag('Py_UNICODE_SIZE', sys.maxunicode == 0x10ffff, expected=4, warn=(impl == 'cp' and sys.version_info < (3, 3))) \ and sys.version_info < (3, 3): u = 'u' abi = '%s%s%s%s%s' % (impl, tags.interpreter_version(), d, m, u) elif soabi and soabi.startswith('cpython-'): abi = 'cp' + soabi.split('-')[1] elif soabi: abi = soabi.replace('.', '_').replace('-', '_') else: abi = None return abi
def get_marker_env(self): # type: () -> Dict[str, Any] if hasattr(sys, "implementation"): info = sys.implementation.version iver = "{0.major}.{0.minor}.{0.micro}".format(info) kind = info.releaselevel if kind != "final": iver += kind[0] + str(info.serial) implementation_name = sys.implementation.name else: iver = "0" implementation_name = "" return { "implementation_name": implementation_name, "implementation_version": iver, "os_name": os.name, "platform_machine": platform.machine(), "platform_release": platform.release(), "platform_system": platform.system(), "platform_version": platform.version(), "python_full_version": platform.python_version(), "platform_python_implementation": platform.python_implementation(), "python_version": ".".join( v for v in platform.python_version().split(".")[:2] ), "sys_platform": sys.platform, "version_info": sys.version_info, # Extra information "interpreter_name": interpreter_name(), "interpreter_version": interpreter_version(), }
def _get_custom_interpreter(implementation=None, version=None): # type: (Optional[str], Optional[str]) -> str if implementation is None: implementation = interpreter_name() if version is None: version = interpreter_version() return "{}{}".format(implementation, version)
def get_tag(self): # bdist sets self.plat_name if unset, we should only use it for purepy # wheels if the user supplied it. if self.plat_name_supplied: plat_name = self.plat_name elif self.root_is_pure: plat_name = 'any' else: # macosx contains system version in platform name so need special handle if self.plat_name and not self.plat_name.startswith("macosx"): plat_name = self.plat_name else: # on macosx always limit the platform name to comply with any # c-extension modules in bdist_dir, since the user can specify # a higher MACOSX_DEPLOYMENT_TARGET via tools like CMake # on other platforms, and on macosx if there are no c-extension # modules, use the default platform name. plat_name = get_platform(self.bdist_dir) if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' plat_name = plat_name.lower().replace('-', '_').replace('.', '_') if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag tag = (impl, 'none', plat_name) else: impl_name = tags.interpreter_name() impl_ver = tags.interpreter_version() impl = impl_name + impl_ver # We don't work on CPython 3.1, 3.0. if self.py_limited_api and (impl_name + impl_ver).startswith('cp3'): impl = self.py_limited_api abi_tag = 'abi3' else: abi_tag = str(get_abi_tag()).lower() tag = (impl, abi_tag, plat_name) supported_tags = [(t.interpreter, t.abi, t.platform) for t in tags.sys_tags()] assert tag in supported_tags, "would build wheel with unsupported tag {}".format( tag) return tag
def get_tag(self): # bdist sets self.plat_name if unset, we should only use it for purepy # wheels if the user supplied it. if self.plat_name_supplied: plat_name = self.plat_name elif self.root_is_pure: plat_name = 'any' else: # macosx contains system version in platform name so need special handle if self.plat_name and not self.plat_name.startswith("macosx"): plat_name = self.plat_name else: plat_name = get_platform(self.bdist_dir) if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' plat_name = plat_name.replace('-', '_').replace('.', '_') if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag tag = (impl, 'none', plat_name) else: impl_name = tags.interpreter_name() impl_ver = tags.interpreter_version() impl = impl_name + impl_ver # We don't work on CPython 3.1, 3.0. if self.py_limited_api and (impl_name + impl_ver).startswith('cp3'): impl = self.py_limited_api abi_tag = 'abi3' else: abi_tag = str(get_abi_tag()).lower() abi_tag = self.abi_tag tag = (impl, abi_tag, plat_name) supported_tags = [(t.interpreter, t.abi, t.platform) for t in tags.sys_tags()] # XXX switch to this alternate implementation for non-pure: if not self.py_limited_api: assert tag == supported_tags[0], "%s != %s" % ( tag, supported_tags[0]) # assert tag in supported_tags, "would build wheel with unsupported tag {}".format(tag) return tag
def test_sys_version_info(self, monkeypatch): monkeypatch.setattr(tags, "_get_config_var", lambda *args, **kwargs: None) monkeypatch.setattr(sys, "version_info", ("L", "M", "N")) assert tags.interpreter_version() == "LM"
def test_python_version_nodot(self, monkeypatch): monkeypatch.setattr(tags, "_get_config_var", lambda var, warn: "NN") assert tags.interpreter_version() == "NN"
def test_sys_version_info(self, version_info, version_str, monkeypatch): monkeypatch.setattr(tags, "_get_config_var", lambda *args, **kwargs: None) monkeypatch.setattr(sys, "version_info", version_info) assert tags.interpreter_version() == version_str
import os, sys, shutil, unittest, tempfile, tarfile, virtualenv, warnings from wheel.bdist_wheel import get_abi_tag, get_platform from packaging.tags import interpreter_name, interpreter_version sys.path.insert(0, "src") from from_file import versions_from_file import common pyver_major = "py%d" % sys.version_info[0] pyver = "py%d.%d" % sys.version_info[:2] # For binary wheels with native code impl, impl_ver = interpreter_name(), interpreter_version() abi = get_abi_tag() try: plat = get_platform(None) except TypeError: # wheel < 0.34 plat = get_platform() class _Invocations(common.Common): def setUp(self): if False: # when debugging, put the generated files in a predictable place self.testdir = os.path.abspath("t") if os.path.exists(self.testdir): return os.mkdir(self.testdir) else: self.testdir = tempfile.mkdtemp() os.mkdir(self.subpath("cache"))
def get_tag(self): # bdist sets self.plat_name if unset, we should only use it for purepy # wheels if the user supplied it. if self.plat_name_supplied: plat_name = self.plat_name elif self.root_is_pure: plat_name = 'any' else: # macosx contains system version in platform name so need special handle if self.plat_name and not self.plat_name.startswith("macosx"): plat_name = self.plat_name else: # on macosx always limit the platform name to comply with any # c-extension modules in bdist_dir, since the user can specify # a higher MACOSX_DEPLOYMENT_TARGET via tools like CMake # on other platforms, and on macosx if there are no c-extension # modules, use the default platform name. plat_name = get_platform(self.bdist_dir) if plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize == 2147483647: plat_name = 'linux_i686' # To allow uploading to pypi, we need the wheel name # to contain 'manylinux1'. # The wheel which will be uploaded to pypi will be # built on RHEL7, so it doesn't completely qualify for # manylinux1 support, but it's the minimum requirement # for building Qt. We only enable this for x64 limited # api builds (which are the only ones uploaded to # pypi). # TODO: Add actual distro detection, instead of # relying on limited_api option. if (plat_name in ('linux-x86_64', 'linux_x86_64') and sys.maxsize > 2147483647 and (self.py_limited_api or sys.version_info[0] == 2)): plat_name = 'manylinux1_x86_64' plat_name = plat_name.replace('-', '_').replace('.', '_') if self.root_is_pure: if self.universal: impl = 'py2.py3' else: impl = self.python_tag tag = (impl, 'none', plat_name) else: impl_name = tags.interpreter_name() impl_ver = tags.interpreter_version() impl = impl_name + impl_ver # We don't work on CPython 3.1, 3.0. if self.py_limited_api and (impl_name + impl_ver).startswith('cp3'): impl = self.py_limited_api abi_tag = "abi3" if sys.platform != "win32" else "none" else: abi_tag = str(get_abi_tag()).lower() tag = (impl, abi_tag, plat_name) supported_tags = [(t.interpreter, t.abi, t.platform) for t in tags.sys_tags()] # XXX switch to this alternate implementation for non-pure: if (self.py_limited_api) or (plat_name in ('manylinux1_x86_64') and sys.version_info[0] == 2): return tag assert tag in supported_tags, ( "would build wheel with unsupported tag {}".format(tag)) return tag