nab-python 0.0.1__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 (71) hide show
  1. nab_python/__init__.py +1 -0
  2. nab_python/_build/__init__.py +1 -0
  3. nab_python/_build/env.py +364 -0
  4. nab_python/_build/errors.py +17 -0
  5. nab_python/_build/runner.py +254 -0
  6. nab_python/_lockfile/__init__.py +1 -0
  7. nab_python/_lockfile/builder.py +339 -0
  8. nab_python/_lockfile/disjointness.py +207 -0
  9. nab_python/_lockfile/pylock.py +323 -0
  10. nab_python/_lockfile/requirements.py +121 -0
  11. nab_python/_packaging_provider.py +98 -0
  12. nab_python/_provider/__init__.py +1 -0
  13. nab_python/_provider/build_remote.py +95 -0
  14. nab_python/_provider/extras.py +231 -0
  15. nab_python/_provider/listing.py +442 -0
  16. nab_python/_provider/lookahead.py +156 -0
  17. nab_python/_provider/metadata_resolver.py +450 -0
  18. nab_python/_provider/priority.py +174 -0
  19. nab_python/_provider/sources.py +215 -0
  20. nab_python/_testing/__init__.py +1 -0
  21. nab_python/_testing/coordinator_fake.py +240 -0
  22. nab_python/_vcs_admission.py +209 -0
  23. nab_python/_vendor/__init__.py +6 -0
  24. nab_python/_vendor/packaging/LICENSE +3 -0
  25. nab_python/_vendor/packaging/LICENSE.APACHE +177 -0
  26. nab_python/_vendor/packaging/LICENSE.BSD +23 -0
  27. nab_python/_vendor/packaging/PROVENANCE.md +73 -0
  28. nab_python/_vendor/packaging/__init__.py +15 -0
  29. nab_python/_vendor/packaging/_elffile.py +108 -0
  30. nab_python/_vendor/packaging/_manylinux.py +265 -0
  31. nab_python/_vendor/packaging/_musllinux.py +88 -0
  32. nab_python/_vendor/packaging/_parser.py +394 -0
  33. nab_python/_vendor/packaging/_structures.py +33 -0
  34. nab_python/_vendor/packaging/_tokenizer.py +196 -0
  35. nab_python/_vendor/packaging/dependency_groups.py +302 -0
  36. nab_python/_vendor/packaging/direct_url.py +325 -0
  37. nab_python/_vendor/packaging/errors.py +94 -0
  38. nab_python/_vendor/packaging/licenses/__init__.py +186 -0
  39. nab_python/_vendor/packaging/licenses/_spdx.py +799 -0
  40. nab_python/_vendor/packaging/markers.py +506 -0
  41. nab_python/_vendor/packaging/metadata.py +964 -0
  42. nab_python/_vendor/packaging/py.typed +0 -0
  43. nab_python/_vendor/packaging/pylock.py +910 -0
  44. nab_python/_vendor/packaging/ranges.py +1803 -0
  45. nab_python/_vendor/packaging/requirements.py +132 -0
  46. nab_python/_vendor/packaging/specifiers.py +1141 -0
  47. nab_python/_vendor/packaging/tags.py +929 -0
  48. nab_python/_vendor/packaging/utils.py +296 -0
  49. nab_python/_vendor/packaging/version.py +1230 -0
  50. nab_python/build_backend.py +184 -0
  51. nab_python/config.py +805 -0
  52. nab_python/download.py +170 -0
  53. nab_python/fetch.py +827 -0
  54. nab_python/lockfile.py +238 -0
  55. nab_python/metadata.py +145 -0
  56. nab_python/provider.py +1235 -0
  57. nab_python/py.typed +0 -0
  58. nab_python/requirements_file.py +180 -0
  59. nab_python/resolve.py +497 -0
  60. nab_python/universal/__init__.py +1 -0
  61. nab_python/universal/matrix.py +235 -0
  62. nab_python/universal/provider.py +214 -0
  63. nab_python/universal/reresolve.py +310 -0
  64. nab_python/universal/resolve.py +508 -0
  65. nab_python/universal/validate.py +439 -0
  66. nab_python/universal/wheel_selection.py +327 -0
  67. nab_python/workspace.py +214 -0
  68. nab_python-0.0.1.dist-info/METADATA +49 -0
  69. nab_python-0.0.1.dist-info/RECORD +71 -0
  70. nab_python-0.0.1.dist-info/WHEEL +4 -0
  71. nab_python-0.0.1.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,265 @@
1
+ from __future__ import annotations
2
+
3
+ import collections
4
+ import contextlib
5
+ import functools
6
+ import os
7
+ import re
8
+ import sys
9
+ import warnings
10
+ from typing import TYPE_CHECKING, NamedTuple
11
+
12
+ from ._elffile import EIClass, EIData, ELFFile, EMachine
13
+
14
+ if TYPE_CHECKING:
15
+ from collections.abc import Generator, Iterator, Sequence
16
+
17
+ EF_ARM_ABIMASK = 0xFF000000
18
+ EF_ARM_ABI_VER5 = 0x05000000
19
+ EF_ARM_ABI_FLOAT_HARD = 0x00000400
20
+
21
+ _ALLOWED_ARCHS = {
22
+ "x86_64",
23
+ "aarch64",
24
+ "ppc64",
25
+ "ppc64le",
26
+ "s390x",
27
+ "loongarch64",
28
+ "riscv64",
29
+ }
30
+
31
+
32
+ # `os.PathLike` not a generic type until Python 3.9, so sticking with `str`
33
+ # as the type for `path` until then.
34
+ @contextlib.contextmanager
35
+ def _parse_elf(path: str) -> Generator[ELFFile | None, None, None]:
36
+ try:
37
+ with open(path, "rb") as f:
38
+ yield ELFFile(f)
39
+ except (OSError, TypeError, ValueError):
40
+ yield None
41
+
42
+
43
+ def _is_linux_armhf(executable: str) -> bool:
44
+ # hard-float ABI can be detected from the ELF header of the running
45
+ # process
46
+ # https://static.docs.arm.com/ihi0044/g/aaelf32.pdf
47
+ with _parse_elf(executable) as f:
48
+ return (
49
+ f is not None
50
+ and f.capacity == EIClass.C32
51
+ and f.encoding == EIData.Lsb
52
+ and f.machine == EMachine.Arm
53
+ and f.flags & EF_ARM_ABIMASK == EF_ARM_ABI_VER5
54
+ and f.flags & EF_ARM_ABI_FLOAT_HARD == EF_ARM_ABI_FLOAT_HARD
55
+ )
56
+
57
+
58
+ def _is_linux_i686(executable: str) -> bool:
59
+ with _parse_elf(executable) as f:
60
+ return (
61
+ f is not None
62
+ and f.capacity == EIClass.C32
63
+ and f.encoding == EIData.Lsb
64
+ and f.machine == EMachine.I386
65
+ )
66
+
67
+
68
+ def _have_compatible_abi(executable: str, archs: Sequence[str]) -> bool:
69
+ if "armv7l" in archs:
70
+ return _is_linux_armhf(executable)
71
+ if "i686" in archs:
72
+ return _is_linux_i686(executable)
73
+ return any(arch in _ALLOWED_ARCHS for arch in archs)
74
+
75
+
76
+ # If glibc ever changes its major version, we need to know what the last
77
+ # minor version was, so we can build the complete list of all versions.
78
+ # For now, guess what the highest minor version might be, assume it will
79
+ # be 50 for testing. Once this actually happens, update the dictionary
80
+ # with the actual value.
81
+ _LAST_GLIBC_MINOR: dict[int, int] = collections.defaultdict(lambda: 50)
82
+
83
+
84
+ class _GLibCVersion(NamedTuple):
85
+ major: int
86
+ minor: int
87
+
88
+
89
+ def _glibc_version_string_confstr() -> str | None:
90
+ """
91
+ Primary implementation of glibc_version_string using os.confstr.
92
+ """
93
+ # os.confstr is quite a bit faster than ctypes.DLL. It's also less likely
94
+ # to be broken or missing. This strategy is used in the standard library
95
+ # platform module.
96
+ # https://github.com/python/cpython/blob/fcf1d003bf4f0100c/Lib/platform.py#L175-L183
97
+ try:
98
+ # Should be a string like "glibc 2.17".
99
+ version_string: str | None = os.confstr("CS_GNU_LIBC_VERSION")
100
+ assert version_string is not None
101
+ _, version = version_string.rsplit()
102
+ except (AssertionError, AttributeError, OSError, ValueError):
103
+ # os.confstr() or CS_GNU_LIBC_VERSION not available (or a bad value)...
104
+ return None
105
+ return version
106
+
107
+
108
+ def _glibc_version_string_ctypes() -> str | None:
109
+ """
110
+ Fallback implementation of glibc_version_string using ctypes.
111
+ """
112
+ try:
113
+ import ctypes # noqa: PLC0415
114
+ except ImportError:
115
+ return None
116
+
117
+ # ctypes.CDLL(None) internally calls dlopen(NULL), and as the dlopen
118
+ # manpage says, "If filename is NULL, then the returned handle is for the
119
+ # main program". This way we can let the linker do the work to figure out
120
+ # which libc our process is actually using.
121
+ #
122
+ # We must also handle the special case where the executable is not a
123
+ # dynamically linked executable. This can occur when using musl libc,
124
+ # for example. In this situation, dlopen() will error, leading to an
125
+ # OSError. Interestingly, at least in the case of musl, there is no
126
+ # errno set on the OSError. The single string argument used to construct
127
+ # OSError comes from libc itself and is therefore not portable to
128
+ # hard code here. In any case, failure to call dlopen() means we
129
+ # can proceed, so we bail on our attempt.
130
+ try:
131
+ process_namespace = ctypes.CDLL(None)
132
+ except OSError:
133
+ return None
134
+
135
+ try:
136
+ gnu_get_libc_version = process_namespace.gnu_get_libc_version
137
+ except AttributeError:
138
+ # Symbol doesn't exist -> therefore, we are not linked to
139
+ # glibc.
140
+ return None
141
+
142
+ # Call gnu_get_libc_version, which returns a string like "2.5"
143
+ gnu_get_libc_version.restype = ctypes.c_char_p
144
+ version_str: str = gnu_get_libc_version()
145
+ # py2 / py3 compatibility:
146
+ if not isinstance(version_str, str):
147
+ version_str = version_str.decode("ascii")
148
+
149
+ return version_str
150
+
151
+
152
+ def _glibc_version_string() -> str | None:
153
+ """Returns glibc version string, or None if not using glibc."""
154
+ return _glibc_version_string_confstr() or _glibc_version_string_ctypes()
155
+
156
+
157
+ def _parse_glibc_version(version_str: str) -> _GLibCVersion:
158
+ """Parse glibc version.
159
+
160
+ We use a regexp instead of str.split because we want to discard any
161
+ random junk that might come after the minor version -- this might happen
162
+ in patched/forked versions of glibc (e.g. Linaro's version of glibc
163
+ uses version strings like "2.20-2014.11"). See gh-3588.
164
+ """
165
+ m = re.match(r"(?P<major>[0-9]+)\.(?P<minor>[0-9]+)", version_str)
166
+ if not m:
167
+ warnings.warn(
168
+ f"Expected glibc version with 2 components major.minor, got: {version_str}",
169
+ RuntimeWarning,
170
+ stacklevel=2,
171
+ )
172
+ return _GLibCVersion(-1, -1)
173
+ return _GLibCVersion(int(m.group("major")), int(m.group("minor")))
174
+
175
+
176
+ @functools.lru_cache
177
+ def _get_glibc_version() -> _GLibCVersion:
178
+ version_str = _glibc_version_string()
179
+ if version_str is None:
180
+ return _GLibCVersion(-1, -1)
181
+ return _parse_glibc_version(version_str)
182
+
183
+
184
+ # From PEP 513, PEP 600
185
+ def _is_compatible(arch: str, version: _GLibCVersion) -> bool:
186
+ sys_glibc = _get_glibc_version()
187
+ if sys_glibc < version:
188
+ return False
189
+ # Check for presence of _manylinux module.
190
+ try:
191
+ import _manylinux # noqa: PLC0415
192
+ except ImportError:
193
+ return True
194
+ if hasattr(_manylinux, "manylinux_compatible"):
195
+ result = _manylinux.manylinux_compatible(version[0], version[1], arch)
196
+ if result is not None:
197
+ return bool(result)
198
+ return True
199
+ if version == _GLibCVersion(2, 5) and hasattr(_manylinux, "manylinux1_compatible"):
200
+ return bool(_manylinux.manylinux1_compatible)
201
+ if version == _GLibCVersion(2, 12) and hasattr(
202
+ _manylinux, "manylinux2010_compatible"
203
+ ):
204
+ return bool(_manylinux.manylinux2010_compatible)
205
+ if version == _GLibCVersion(2, 17) and hasattr(
206
+ _manylinux, "manylinux2014_compatible"
207
+ ):
208
+ return bool(_manylinux.manylinux2014_compatible)
209
+ return True
210
+
211
+
212
+ _LEGACY_MANYLINUX_MAP: dict[_GLibCVersion, str] = {
213
+ # CentOS 7 w/ glibc 2.17 (PEP 599)
214
+ _GLibCVersion(2, 17): "manylinux2014",
215
+ # CentOS 6 w/ glibc 2.12 (PEP 571)
216
+ _GLibCVersion(2, 12): "manylinux2010",
217
+ # CentOS 5 w/ glibc 2.5 (PEP 513)
218
+ _GLibCVersion(2, 5): "manylinux1",
219
+ }
220
+
221
+
222
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
223
+ """Generate manylinux tags compatible to the current platform.
224
+
225
+ :param archs: Sequence of compatible architectures.
226
+ The first one shall be the closest to the actual architecture and be the part of
227
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
228
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
229
+ be manylinux-compatible.
230
+
231
+ :returns: An iterator of compatible manylinux tags.
232
+ """
233
+ if not _have_compatible_abi(sys.executable, archs):
234
+ return
235
+ # Oldest glibc to be supported regardless of architecture is (2, 17).
236
+ too_old_glibc2 = _GLibCVersion(2, 16)
237
+ if set(archs) & {"x86_64", "i686"}:
238
+ # On x86/i686 also oldest glibc to be supported is (2, 5).
239
+ too_old_glibc2 = _GLibCVersion(2, 4)
240
+ current_glibc = _GLibCVersion(*_get_glibc_version())
241
+ glibc_max_list = [current_glibc]
242
+ # We can assume compatibility across glibc major versions.
243
+ # https://sourceware.org/bugzilla/show_bug.cgi?id=24636
244
+ #
245
+ # Build a list of maximum glibc versions so that we can
246
+ # output the canonical list of all glibc from current_glibc
247
+ # down to too_old_glibc2, including all intermediary versions.
248
+ for glibc_major in range(current_glibc.major - 1, 1, -1):
249
+ glibc_minor = _LAST_GLIBC_MINOR[glibc_major]
250
+ glibc_max_list.append(_GLibCVersion(glibc_major, glibc_minor))
251
+ for arch in archs:
252
+ for glibc_max in glibc_max_list:
253
+ if glibc_max.major == too_old_glibc2.major:
254
+ min_minor = too_old_glibc2.minor
255
+ else:
256
+ # For other glibc major versions oldest supported is (x, 0).
257
+ min_minor = -1
258
+ for glibc_minor in range(glibc_max.minor, min_minor, -1):
259
+ glibc_version = _GLibCVersion(glibc_max.major, glibc_minor)
260
+ if _is_compatible(arch, glibc_version):
261
+ yield "manylinux_{}_{}_{}".format(*glibc_version, arch)
262
+
263
+ # Handle the legacy manylinux1, manylinux2010, manylinux2014 tags.
264
+ if legacy_tag := _LEGACY_MANYLINUX_MAP.get(glibc_version):
265
+ yield f"{legacy_tag}_{arch}"
@@ -0,0 +1,88 @@
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
+ from __future__ import annotations
8
+
9
+ import functools
10
+ import re
11
+ import subprocess
12
+ import sys
13
+ from typing import TYPE_CHECKING, NamedTuple
14
+
15
+ from ._elffile import ELFFile
16
+
17
+ if TYPE_CHECKING:
18
+ from collections.abc import Iterator, Sequence
19
+
20
+
21
+ class _MuslVersion(NamedTuple):
22
+ major: int
23
+ minor: int
24
+
25
+
26
+ def _parse_musl_version(output: str) -> _MuslVersion | None:
27
+ lines = [n for n in (n.strip() for n in output.splitlines()) if n]
28
+ if len(lines) < 2 or lines[0][:4] != "musl":
29
+ return None
30
+ m = re.match(r"Version (\d+)\.(\d+)", lines[1])
31
+ if not m:
32
+ return None
33
+ return _MuslVersion(major=int(m.group(1)), minor=int(m.group(2)))
34
+
35
+
36
+ @functools.lru_cache
37
+ def _get_musl_version(executable: str) -> _MuslVersion | None:
38
+ """Detect currently-running musl runtime version.
39
+
40
+ This is done by checking the specified executable's dynamic linking
41
+ information, and invoking the loader to parse its output for a version
42
+ string. If the loader is musl, the output would be something like::
43
+
44
+ musl libc (x86_64)
45
+ Version 1.2.2
46
+ Dynamic Program Loader
47
+ """
48
+ try:
49
+ with open(executable, "rb") as f:
50
+ ld = ELFFile(f).interpreter
51
+ except (OSError, TypeError, ValueError):
52
+ return None
53
+ if ld is None or "musl" not in ld:
54
+ return None
55
+ proc = subprocess.run([ld], check=False, stderr=subprocess.PIPE, text=True)
56
+ return _parse_musl_version(proc.stderr)
57
+
58
+
59
+ def platform_tags(archs: Sequence[str]) -> Iterator[str]:
60
+ """Generate musllinux tags compatible to the current platform.
61
+
62
+ :param archs: Sequence of compatible architectures.
63
+ The first one shall be the closest to the actual architecture and be the part of
64
+ platform tag after the ``linux_`` prefix, e.g. ``x86_64``.
65
+ The ``linux_`` prefix is assumed as a prerequisite for the current platform to
66
+ be musllinux-compatible.
67
+
68
+ :returns: An iterator of compatible musllinux tags.
69
+ """
70
+ sys_musl = _get_musl_version(sys.executable)
71
+ if sys_musl is None: # Python not dynamically linked against musl.
72
+ return
73
+ for arch in archs:
74
+ for minor in range(sys_musl.minor, -1, -1):
75
+ yield f"musllinux_{sys_musl.major}_{minor}_{arch}"
76
+
77
+
78
+ if __name__ == "__main__": # pragma: no cover
79
+ import sysconfig
80
+
81
+ plat = sysconfig.get_platform()
82
+ assert plat.startswith("linux-"), "not linux"
83
+
84
+ print("plat:", plat)
85
+ print("musl:", _get_musl_version(sys.executable))
86
+ print("tags:", end=" ")
87
+ for t in platform_tags(re.sub(r"[.-]", "_", plat.split("-", 1)[-1])):
88
+ print(t, end="\n ")