Q" format_p = format_i if self.e_ident_class == self.ELFCLASS32 else format_q self.e_type = unpack(format_h) self.e_machine = unpack(format_h) self.e_version = unpack(format_i) self.e_entry = unpack(format_p) self.e_phoff = unpack(format_p) self.e_shoff = unpack(format_p) self.e_flags = unpack(format_i) self.e_ehsize = unpack(format_h) self.e_phentsize = unpack(format_h) self.e_phnum = unpack(format_h) self.e_shentsize = unpack(format_h) self.e_shnum = unpack(format_h) self.e_shstrndx = unpack(format_h) def _get_elf_header(): # type: () -> Optional[_ELFFileHeader] try: with open(sys.executable, "rb") as f: elf_header = _ELFFileHeader(f) except (IOError, OSError, TypeError, _ELFFileHeader._InvalidELFFileHeader): return None return elf_header def _is_linux_armhf(): # type: () -> bool # hard-float ABI can be detected from the ELF header of the running # process # https://static.docs.arm.com/ihi0044/g/aaelf32.pdf elf_header = _get_elf_header() if elf_header is None: return False result = elf_header.e_ident_class == elf_header.ELFCLASS32 result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB result &= elf_header.e_machine == elf_header.EM_ARM result &= ( elf_header.e_flags & elf_header.EF_ARM_ABIMASK ) == elf_header.EF_ARM_ABI_VER5 result &= ( elf_header.e_flags & elf_header.EF_ARM_ABI_FLOAT_HARD ) == elf_header.EF_ARM_ABI_FLOAT_HARD return result def _is_linux_i686(): # type: () -> bool elf_header = _get_elf_header() if elf_header is None: return False result = elf_header.e_ident_class == elf_header.ELFCLASS32 result &= elf_header.e_ident_data == elf_header.ELFDATA2LSB result &= elf_header.e_machine == elf_header.EM_386 return result def _have_compatible_manylinux_abi(arch): # type: (str) -> bool if arch == "armv7l": return _is_linux_armhf() if arch == "i686": return _is_linux_i686() return arch in {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x"} def _manylinux_tags(linux, arch): # type: (str, str) -> Iterator[str] # Oldest glibc to be supported regardless of architecture is (2, 17). too_old_glibc2 = glibcVersion(2, 16) if arch in {"x86_64", "i686"}: # On x86/i686 also oldest glibc to be supported is (2, 5). too_old_glibc2 = glibcVersion(2, 4) current_glibc = glibcVersion(*_get_glibc_version()) glibc_max_list = [current_glibc] # We can assume compatibility across glibc major versions. # https://sourceware.org/bugzilla/show_bug.cgi?id=24636 # # Build a list of maximum glibc versions so that we can # output the canonical list of all glibc from current_glibc # down to too_old_glibc2, including all intermediary versions. for glibc_major in range(current_glibc.major - 1, 1, -1): glibc_max_list.append(glibcVersion(glibc_major, _LAST_GLIBC_MINOR[glibc_major])) for glibc_max in glibc_max_list: if glibc_max.major == too_old_glibc2.major: min_minor = too_old_glibc2.minor else: # For other glibc major versions oldest supported is (x, 0). min_minor = -1 for glibc_minor in range(glibc_max.minor, min_minor, -1): glibc_version = (glibc_max.major, glibc_minor) tag = "manylinux_{}_{}".format(*glibc_version) if _is_manylinux_compatible(tag, arch, glibc_version): yield linux.replace("linux", tag) # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags. if glibc_version in _LEGACY_MANYLINUX_MAP: legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version] if _is_manylinux_compatible(legacy_tag, arch, glibc_version): yield linux.replace("linux", legacy_tag) def _linux_platforms(is_32bit=_32_BIT_INTERPRETER): # type: (bool) -> Iterator[str] linux = _normalize_string(distutils.util.get_platform()) if is_32bit: if linux == "linux_x86_64": linux = "linux_i686" elif linux == "linux_aarch64": linux = "linux_armv7l" _, arch = linux.split("_", 1) if _have_compatible_manylinux_abi(arch): for tag in _manylinux_tags(linux, arch): yield tag yield linux def _generic_platforms(): # type: () -> Iterator[str] yield _normalize_string(distutils.util.get_platform()) def _platform_tags(): # type: () -> Iterator[str] """ Provides the platform tags for this installation. """ if platform.system() == "Darwin": return mac_platforms() elif platform.system() == "Linux": return _linux_platforms() else: return _generic_platforms() def interpreter_name(): # type: () -> str """ Returns the name of the running interpreter. """ try: name = sys.implementation.name # type: ignore except AttributeError: # pragma: no cover # Python 2.7 compatibility. name = platform.python_implementation().lower() return INTERPRETER_SHORT_NAMES.get(name) or name def interpreter_version(**kwargs): # type: (bool) -> str """ Returns the version of the running interpreter. """ warn = _warn_keyword_parameter("interpreter_version", kwargs) version = _get_config_var("py_version_nodot", warn=warn) if version: version = str(version) else: version = _version_nodot(sys.version_info[:2]) return version def _version_nodot(version): # type: (PythonVersion) -> str return "".join(map(str, version)) def sys_tags(**kwargs): # type: (bool) -> Iterator[Tag] """ Returns the sequence of tag triples for the running interpreter. The order of the sequence corresponds to priority order for the interpreter, from most to least important. """ warn = _warn_keyword_parameter("sys_tags", kwargs) interp_name = interpreter_name() if interp_name == "cp": for tag in cpython_tags(warn=warn): yield tag else: for tag in generic_tags(): yield tag for tag in compatible_tags(): yield tag