casbin-async-django-orm-adapter 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. async_casbin_adapter/__init__.py +0 -0
  2. async_casbin_adapter/adapter.py +100 -0
  3. async_casbin_adapter/apps.py +24 -0
  4. async_casbin_adapter/enforcer.py +81 -0
  5. async_casbin_adapter/migrations/0001_initial.py +37 -0
  6. async_casbin_adapter/migrations/__init__.py +0 -0
  7. async_casbin_adapter/models.py +48 -0
  8. async_casbin_adapter/utils.py +25 -0
  9. casbin_async_django_orm_adapter-1.0.0.dist-info/METADATA +116 -0
  10. casbin_async_django_orm_adapter-1.0.0.dist-info/RECORD +74 -0
  11. casbin_async_django_orm_adapter-1.0.0.dist-info/WHEEL +5 -0
  12. casbin_async_django_orm_adapter-1.0.0.dist-info/licenses/LICENSE +201 -0
  13. casbin_async_django_orm_adapter-1.0.0.dist-info/top_level.txt +3 -0
  14. node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py +45 -0
  15. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSNew.py +365 -0
  16. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSProject.py +206 -0
  17. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings.py +1272 -0
  18. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSSettings_test.py +1547 -0
  19. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSToolFile.py +59 -0
  20. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUserFile.py +152 -0
  21. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSUtil.py +270 -0
  22. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/MSVSVersion.py +574 -0
  23. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/__init__.py +704 -0
  24. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common.py +709 -0
  25. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/common_test.py +173 -0
  26. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml.py +169 -0
  27. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/easy_xml_test.py +113 -0
  28. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/flock_tool.py +55 -0
  29. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/__init__.py +0 -0
  30. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/analyzer.py +805 -0
  31. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/android.py +1172 -0
  32. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/cmake.py +1319 -0
  33. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/compile_commands_json.py +128 -0
  34. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/dump_dependency_json.py +104 -0
  35. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/eclipse.py +462 -0
  36. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypd.py +89 -0
  37. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/gypsh.py +56 -0
  38. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py +2745 -0
  39. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs.py +3976 -0
  40. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/msvs_test.py +44 -0
  41. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja.py +2965 -0
  42. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/ninja_test.py +67 -0
  43. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode.py +1391 -0
  44. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/generator/xcode_test.py +26 -0
  45. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input.py +3112 -0
  46. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/input_test.py +99 -0
  47. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/mac_tool.py +767 -0
  48. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/msvs_emulation.py +1260 -0
  49. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/ninja_syntax.py +174 -0
  50. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/simple_copy.py +61 -0
  51. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/win_tool.py +373 -0
  52. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation.py +1939 -0
  53. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_emulation_test.py +54 -0
  54. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcode_ninja.py +303 -0
  55. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xcodeproj_file.py +3196 -0
  56. node_modules/npm/node_modules/node-gyp/gyp/pylib/gyp/xml_fix.py +65 -0
  57. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/__init__.py +15 -0
  58. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_elffile.py +108 -0
  59. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_manylinux.py +252 -0
  60. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_musllinux.py +83 -0
  61. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_parser.py +359 -0
  62. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_structures.py +61 -0
  63. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/_tokenizer.py +192 -0
  64. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/markers.py +252 -0
  65. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/metadata.py +825 -0
  66. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/py.typed +0 -0
  67. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/requirements.py +90 -0
  68. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/specifiers.py +1030 -0
  69. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/tags.py +553 -0
  70. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/utils.py +172 -0
  71. node_modules/npm/node_modules/node-gyp/gyp/pylib/packaging/version.py +563 -0
  72. node_modules/npm/node_modules/node-gyp/gyp/test_gyp.py +261 -0
  73. node_modules/semantic-release-pypi/dist/py/set_version.py +32 -0
  74. node_modules/semantic-release-pypi/dist/py/verify_setup.py +24 -0
@@ -0,0 +1,65 @@
1
+ # Copyright (c) 2011 Google Inc. All rights reserved.
2
+ # Use of this source code is governed by a BSD-style license that can be
3
+ # found in the LICENSE file.
4
+
5
+ """Applies a fix to CR LF TAB handling in xml.dom.
6
+
7
+ Fixes this: http://code.google.com/p/chromium/issues/detail?id=76293
8
+ Working around this: http://bugs.python.org/issue5752
9
+ TODO(bradnelson): Consider dropping this when we drop XP support.
10
+ """
11
+
12
+
13
+ import xml.dom.minidom
14
+
15
+
16
+ def _Replacement_write_data(writer, data, is_attrib=False):
17
+ """Writes datachars to writer."""
18
+ data = data.replace("&", "&amp;").replace("<", "&lt;")
19
+ data = data.replace('"', "&quot;").replace(">", "&gt;")
20
+ if is_attrib:
21
+ data = data.replace("\r", "&#xD;").replace("\n", "&#xA;").replace("\t", "&#x9;")
22
+ writer.write(data)
23
+
24
+
25
+ def _Replacement_writexml(self, writer, indent="", addindent="", newl=""):
26
+ # indent = current indentation
27
+ # addindent = indentation to add to higher levels
28
+ # newl = newline string
29
+ writer.write(indent + "<" + self.tagName)
30
+
31
+ attrs = self._get_attributes()
32
+ a_names = sorted(attrs.keys())
33
+
34
+ for a_name in a_names:
35
+ writer.write(' %s="' % a_name)
36
+ _Replacement_write_data(writer, attrs[a_name].value, is_attrib=True)
37
+ writer.write('"')
38
+ if self.childNodes:
39
+ writer.write(">%s" % newl)
40
+ for node in self.childNodes:
41
+ node.writexml(writer, indent + addindent, addindent, newl)
42
+ writer.write(f"{indent}</{self.tagName}>{newl}")
43
+ else:
44
+ writer.write("/>%s" % newl)
45
+
46
+
47
+ class XmlFix:
48
+ """Object to manage temporary patching of xml.dom.minidom."""
49
+
50
+ def __init__(self):
51
+ # Preserve current xml.dom.minidom functions.
52
+ self.write_data = xml.dom.minidom._write_data
53
+ self.writexml = xml.dom.minidom.Element.writexml
54
+ # Inject replacement versions of a function and a method.
55
+ xml.dom.minidom._write_data = _Replacement_write_data
56
+ xml.dom.minidom.Element.writexml = _Replacement_writexml
57
+
58
+ def Cleanup(self):
59
+ if self.write_data:
60
+ xml.dom.minidom._write_data = self.write_data
61
+ xml.dom.minidom.Element.writexml = self.writexml
62
+ self.write_data = None
63
+
64
+ def __del__(self):
65
+ self.Cleanup()
@@ -0,0 +1,15 @@
1
+ # This file is dual licensed under the terms of the Apache License, Version
2
+ # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3
+ # for complete details.
4
+
5
+ __title__ = "packaging"
6
+ __summary__ = "Core utilities for Python packages"
7
+ __uri__ = "https://github.com/pypa/packaging"
8
+
9
+ __version__ = "23.3.dev0"
10
+
11
+ __author__ = "Donald Stufft and individual contributors"
12
+ __email__ = "donald@stufft.io"
13
+
14
+ __license__ = "BSD-2-Clause or Apache-2.0"
15
+ __copyright__ = "2014 %s" % __author__
@@ -0,0 +1,108 @@
1
+ """
2
+ ELF file parser.
3
+
4
+ This provides a class ``ELFFile`` that parses an ELF executable in a similar
5
+ interface to ``ZipFile``. Only the read interface is implemented.
6
+
7
+ Based on: https://gist.github.com/lyssdod/f51579ae8d93c8657a5564aefc2ffbca
8
+ ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
9
+ """
10
+
11
+ import enum
12
+ import os
13
+ import struct
14
+ from typing import IO, Optional, Tuple
15
+
16
+
17
+ class ELFInvalid(ValueError):
18
+ pass
19
+
20
+
21
+ class EIClass(enum.IntEnum):
22
+ C32 = 1
23
+ C64 = 2
24
+
25
+
26
+ class EIData(enum.IntEnum):
27
+ Lsb = 1
28
+ Msb = 2
29
+
30
+
31
+ class EMachine(enum.IntEnum):
32
+ I386 = 3
33
+ S390 = 22
34
+ Arm = 40
35
+ X8664 = 62
36
+ AArc64 = 183
37
+
38
+
39
+ class ELFFile:
40
+ """
41
+ Representation of an ELF executable.
42
+ """
43
+
44
+ def __init__(self, f: IO[bytes]) -> None:
45
+ self._f = f
46
+
47
+ try:
48
+ ident = self._read("16B")
49
+ except struct.error:
50
+ raise ELFInvalid("unable to parse identification")
51
+ magic = bytes(ident[:4])
52
+ if magic != b"\x7fELF":
53
+ raise ELFInvalid(f"invalid magic: {magic!r}")
54
+
55
+ self.capacity = ident[4] # Format for program header (bitness).
56
+ self.encoding = ident[5] # Data structure encoding (endianness).
57
+
58
+ try:
59
+ # e_fmt: Format for program header.
60
+ # p_fmt: Format for section header.
61
+ # p_idx: Indexes to find p_type, p_offset, and p_filesz.
62
+ e_fmt, self._p_fmt, self._p_idx = {
63
+ (1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
64
+ (1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
65
+ (2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
66
+ (2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
67
+ }[(self.capacity, self.encoding)]
68
+ except KeyError:
69
+ raise ELFInvalid(
70
+ f"unrecognized capacity ({self.capacity}) or "
71
+ f"encoding ({self.encoding})"
72
+ )
73
+
74
+ try:
75
+ (
76
+ _,
77
+ self.machine, # Architecture type.
78
+ _,
79
+ _,
80
+ self._e_phoff, # Offset of program header.
81
+ _,
82
+ self.flags, # Processor-specific flags.
83
+ _,
84
+ self._e_phentsize, # Size of section.
85
+ self._e_phnum, # Number of sections.
86
+ ) = self._read(e_fmt)
87
+ except struct.error as e:
88
+ raise ELFInvalid("unable to parse machine and section information") from e
89
+
90
+ def _read(self, fmt: str) -> Tuple[int, ...]:
91
+ return struct.unpack(fmt, self._f.read(struct.calcsize(fmt)))
92
+
93
+ @property
94
+ def interpreter(self) -> Optional[str]:
95
+ """
96
+ The path recorded in the ``PT_INTERP`` section header.
97
+ """
98
+ for index in range(self._e_phnum):
99
+ self._f.seek(self._e_phoff + self._e_phentsize * index)
100
+ try:
101
+ data = self._read(self._p_fmt)
102
+ except struct.error:
103
+ continue
104
+ if data[self._p_idx[0]] != 3: # Not PT_INTERP.
105
+ continue
106
+ self._f.seek(data[self._p_idx[1]])
107
+ return os.fsdecode(self._f.read(data[self._p_idx[2]])).strip("\0")
108
+ return None
@@ -0,0 +1,252 @@
1
+ import collections
2
+ import contextlib
3
+ import functools
4
+ import os
5
+ import re
6
+ import sys
7
+ import warnings
8
+ from typing import Dict, Generator, Iterator, NamedTuple, Optional, Sequence, Tuple
9
+
10
+ from ._elffile import EIClass, EIData, ELFFile, EMachine
11
+
12
+ EF_ARM_ABIMASK = 0xFF000000
13
+ EF_ARM_ABI_VER5 = 0x05000000
14
+ EF_ARM_ABI_FLOAT_HARD = 0x00000400
15
+
16
+
17
+ # `os.PathLike` not a generic type until Python 3.9, so sticking with `str`
18
+ # as the type for `path` until then.
19
+ @contextlib.contextmanager
20
+ def _parse_elf(path: str) -> Generator[Optional[ELFFile], None, None]:
21
+ try:
22
+ with open(path, "rb") as f:
23
+ yield ELFFile(f)
24
+ except (OSError, TypeError, ValueError):
25
+ yield None
26
+
27
+
28
+ def _is_linux_armhf(executable: str) -> bool:
29
+ # hard-float ABI can be detected from the ELF header of the running
30
+ # process
31
+ # https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
32
+ with _parse_elf(executable) as f:
33
+ return (
34
+ f is not None
35
+ and f.capacity == EIClass.C32
36
+ and f.encoding == EIData.Lsb
37
+ and f.machine == EMachine.Arm
38
+ and f.flags & EF_ARM_ABIMASK == EF_ARM_ABI_VER5
39
+ and f.flags & EF_ARM_ABI_FLOAT_HARD == EF_ARM_ABI_FLOAT_HARD
40
+ )
41
+
42
+
43
+ def _is_linux_i686(executable: str) -> bool:
44
+ with _parse_elf(executable) as f:
45
+ return (
46
+ f is not None
47
+ and f.capacity == EIClass.C32
48
+ and f.encoding == EIData.Lsb
49
+ and f.machine == EMachine.I386
50
+ )
51
+
52
+
53
+ def _have_compatible_abi(executable: str, archs: Sequence[str]) -> bool:
54
+ if "armv7l" in archs:
55
+ return _is_linux_armhf(executable)
56
+ if "i686" in archs:
57
+ return _is_linux_i686(executable)
58
+ allowed_archs = {"x86_64", "aarch64", "ppc64", "ppc64le", "s390x", "loongarch64"}
59
+ return any(arch in allowed_archs for arch in archs)
60
+
61
+
62
+ # If glibc ever changes its major version, we need to know what the last
63
+ # minor version was, so we can build the complete list of all versions.
64
+ # For now, guess what the highest minor version might be, assume it will
65
+ # be 50 for testing. Once this actually happens, update the dictionary
66
+ # with the actual value.
67
+ _LAST_GLIBC_MINOR: Dict[int, int] = collections.defaultdict(lambda: 50)
68
+
69
+
70
+ class _GLibCVersion(NamedTuple):
71
+ major: int
72
+ minor: int
73
+
74
+
75
+ def _glibc_version_string_confstr() -> Optional[str]:
76
+ """
77
+ Primary implementation of glibc_version_string using os.confstr.
78
+ """
79
+ # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
80
+ # to be broken or missing. This strategy is used in the standard library
81
+ # platform module.
82
+ # https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183
83
+ try:
84
+ # Should be a string like "glibc 2.17".
85
+ version_string: str = getattr(os, "confstr")("CS_GNU_LIBC_VERSION")
86
+ assert version_string is not None
87
+ _, version = version_string.rsplit()
88
+ except (AssertionError, AttributeError, OSError, ValueError):
89
+ # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
90
+ return None
91
+ return version
92
+
93
+
94
+ def _glibc_version_string_ctypes() -> Optional[str]:
95
+ """
96
+ Fallback implementation of glibc_version_string using ctypes.
97
+ """
98
+ try:
99
+ import ctypes
100
+ except ImportError:
101
+ return None
102
+
103
+ # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
104
+ # manpage says, "If filename is NULL, then the returned handle is for the
105
+ # main program". This way we can let the linker do the work to figure out
106
+ # which libc our process is actually using.
107
+ #
108
+ # We must also handle the special case where the executable is not a
109
+ # dynamically linked executable. This can occur when using musl libc,
110
+ # for example. In this situation, dlopen() will error, leading to an
111
+ # OSError. Interestingly, at least in the case of musl, there is no
112
+ # errno set on the OSError. The single string argument used to construct
113
+ # OSError comes from libc itself and is therefore not portable to
114
+ # hard code here. In any case, failure to call dlopen() means we
115
+ # can proceed, so we bail on our attempt.
116
+ try:
117
+ process_namespace = ctypes.CDLL(None)
118
+ except OSError:
119
+ return None
120
+
121
+ try:
122
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
123
+ except AttributeError:
124
+ # Symbol doesn't exist -> therefore, we are not linked to
125
+ # glibc.
126
+ return None
127
+
128
+ # Call gnu_get_libc_version, which returns a string like "2.5"
129
+ gnu_get_libc_version.restype = ctypes.c_char_p
130
+ version_str: str = gnu_get_libc_version()
131
+ # py2 / py3 compatibility:
132
+ if not isinstance(version_str, str):
133
+ version_str = version_str.decode("ascii")
134
+
135
+ return version_str
136
+
137
+
138
+ def _glibc_version_string() -> Optional[str]:
139
+ """Returns glibc version string, or None if not using glibc."""
140
+ return _glibc_version_string_confstr() or _glibc_version_string_ctypes()
141
+
142
+
143
+ def _parse_glibc_version(version_str: str) -> Tuple[int, int]:
144
+ """Parse glibc version.
145
+
146
+ We use a regexp instead of str.split because we want to discard any
147
+ random junk that might come after the minor version -- this might happen
148
+ in patched/forked versions of glibc (e.g. Linaro's version of glibc
149
+ uses version strings like "2.20-2014.11"). See gh-3588.
150
+ """
151
+ m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
152
+ if not m:
153
+ warnings.warn(
154
+ f"Expected glibc version with 2 components major.minor,"
155
+ f" got: {version_str}",
156
+ RuntimeWarning,
157
+ )
158
+ return -1, -1
159
+ return int(m.group("major")), int(m.group("minor"))
160
+
161
+
162
+ @functools.lru_cache()
163
+ def _get_glibc_version() -> Tuple[int, int]:
164
+ version_str = _glibc_version_string()
165
+ if version_str is None:
166
+ return (-1, -1)
167
+ return _parse_glibc_version(version_str)
168
+
169
+
170
+ # From PEP 513, PEP 600
171
+ def _is_compatible(arch: str, version: _GLibCVersion) -> bool:
172
+ sys_glibc = _get_glibc_version()
173
+ if sys_glibc < version:
174
+ return False
175
+ # Check for presence of _manylinux module.
176
+ try:
177
+ import _manylinux # noqa
178
+ except ImportError:
179
+ return True
180
+ if hasattr(_manylinux, "manylinux_compatible"):
181
+ result = _manylinux.manylinux_compatible(version[0], version[1], arch)
182
+ if result is not None:
183
+ return bool(result)
184
+ return True
185
+ if version == _GLibCVersion(2, 5):
186
+ if hasattr(_manylinux, "manylinux1_compatible"):
187
+ return bool(_manylinux.manylinux1_compatible)
188
+ if version == _GLibCVersion(2, 12):
189
+ if hasattr(_manylinux, "manylinux2010_compatible"):
190
+ return bool(_manylinux.manylinux2010_compatible)
191
+ if version == _GLibCVersion(2, 17):
192
+ if hasattr(_manylinux, "manylinux2014_compatible"):
193
+ return bool(_manylinux.manylinux2014_compatible)
194
+ return True
195
+
196
+
197
+ _LEGACY_MANYLINUX_MAP = {
198
+ # CentOS 7 w/ glibc 2.17 (PEP 599)
199
+ (2, 17): "manylinux2014",
200
+ # CentOS 6 w/ glibc 2.12 (PEP 571)
201
+ (2, 12): "manylinux2010",
202
+ # CentOS 5 w/ glibc 2.5 (PEP 513)
203
+ (2, 5): "manylinux1",
204
+ }
205
+
206
+
207
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
208
+ """Generate manylinux tags compatible to the current platform.
209
+
210
+ :param archs: Sequence of compatible architectures.
211
+ The first one shall be the closest to the actual architecture and be the part of
212
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
213
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
214
+ be manylinux-compatible.
215
+
216
+ :returns: An iterator of compatible manylinux tags.
217
+ """
218
+ if not _have_compatible_abi(sys.executable, archs):
219
+ return
220
+ # Oldest glibc to be supported regardless of architecture is (2, 17).
221
+ too_old_glibc2 = _GLibCVersion(2, 16)
222
+ if set(archs) & {"x86_64", "i686"}:
223
+ # On x86/i686 also oldest glibc to be supported is (2, 5).
224
+ too_old_glibc2 = _GLibCVersion(2, 4)
225
+ current_glibc = _GLibCVersion(*_get_glibc_version())
226
+ glibc_max_list = [current_glibc]
227
+ # We can assume compatibility across glibc major versions.
228
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=24636
229
+ #
230
+ # Build a list of maximum glibc versions so that we can
231
+ # output the canonical list of all glibc from current_glibc
232
+ # down to too_old_glibc2, including all intermediary versions.
233
+ for glibc_major in range(current_glibc.major - 1, 1, -1):
234
+ glibc_minor = _LAST_GLIBC_MINOR[glibc_major]
235
+ glibc_max_list.append(_GLibCVersion(glibc_major, glibc_minor))
236
+ for arch in archs:
237
+ for glibc_max in glibc_max_list:
238
+ if glibc_max.major == too_old_glibc2.major:
239
+ min_minor = too_old_glibc2.minor
240
+ else:
241
+ # For other glibc major versions oldest supported is (x, 0).
242
+ min_minor = -1
243
+ for glibc_minor in range(glibc_max.minor, min_minor, -1):
244
+ glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
245
+ tag = "manylinux_{}_{}".format(*glibc_version)
246
+ if _is_compatible(arch, glibc_version):
247
+ yield f"{tag}_{arch}"
248
+ # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
249
+ if glibc_version in _LEGACY_MANYLINUX_MAP:
250
+ legacy_tag = _LEGACY_MANYLINUX_MAP[glibc_version]
251
+ if _is_compatible(arch, glibc_version):
252
+ yield f"{legacy_tag}_{arch}"
@@ -0,0 +1,83 @@
1
+ """PEP 656 support.
2
+
3
+ This module implements logic to detect if the currently running Python is
4
+ linked against musl, and what musl version is used.
5
+ """
6
+
7
+ import functools
8
+ import re
9
+ import subprocess
10
+ import sys
11
+ from typing import Iterator, NamedTuple, Optional, Sequence
12
+
13
+ from ._elffile import ELFFile
14
+
15
+
16
+ class _MuslVersion(NamedTuple):
17
+ major: int
18
+ minor: int
19
+
20
+
21
+ def _parse_musl_version(output: str) -> Optional[_MuslVersion]:
22
+ lines = [n for n in (n.strip() for n in output.splitlines()) if n]
23
+ if len(lines) < 2 or lines[0][:4] != "musl":
24
+ return None
25
+ m = re.match(r"Version (\d+)\.(\d+)", lines[1])
26
+ if not m:
27
+ return None
28
+ return _MuslVersion(major=int(m.group(1)), minor=int(m.group(2)))
29
+
30
+
31
+ @functools.lru_cache()
32
+ def _get_musl_version(executable: str) -> Optional[_MuslVersion]:
33
+ """Detect currently-running musl runtime version.
34
+
35
+ This is done by checking the specified executable's dynamic linking
36
+ information, and invoking the loader to parse its output for a version
37
+ string. If the loader is musl, the output would be something like::
38
+
39
+ musl libc (x86_64)
40
+ Version 1.2.2
41
+ Dynamic Program Loader
42
+ """
43
+ try:
44
+ with open(executable, "rb") as f:
45
+ ld = ELFFile(f).interpreter
46
+ except (OSError, TypeError, ValueError):
47
+ return None
48
+ if ld is None or "musl" not in ld:
49
+ return None
50
+ proc = subprocess.run([ld], stderr=subprocess.PIPE, text=True)
51
+ return _parse_musl_version(proc.stderr)
52
+
53
+
54
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
55
+ """Generate musllinux tags compatible to the current platform.
56
+
57
+ :param archs: Sequence of compatible architectures.
58
+ The first one shall be the closest to the actual architecture and be the part of
59
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
60
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
61
+ be musllinux-compatible.
62
+
63
+ :returns: An iterator of compatible musllinux tags.
64
+ """
65
+ sys_musl = _get_musl_version(sys.executable)
66
+ if sys_musl is None: # Python not dynamically linked against musl.
67
+ return
68
+ for arch in archs:
69
+ for minor in range(sys_musl.minor, -1, -1):
70
+ yield f"musllinux_{sys_musl.major}_{minor}_{arch}"
71
+
72
+
73
+ if __name__ == "__main__": # pragma: no cover
74
+ import sysconfig
75
+
76
+ plat = sysconfig.get_platform()
77
+ assert plat.startswith("linux-"), "not linux"
78
+
79
+ print("plat:", plat)
80
+ print("musl:", _get_musl_version(sys.executable))
81
+ print("tags:", end=" ")
82
+ for t in platform_tags(re.sub(r"[.-]", "_", plat.split("-", 1)[-1])):
83
+ print(t, end="\n ")