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,209 @@
1
+ """Direct-URL / VCS requirement admission for the provider.
2
+
3
+ Cloning a remote repo is one short step from arbitrary code
4
+ execution because modern Python projects build via PEP 517
5
+ backends, which run user code. This module owns the policy types
6
+ (:class:`VcsPolicy`, :class:`VcsConfig`), the URL classifier
7
+ (:func:`split_vcs_scheme`, :func:`has_full_commit_sha`), and the
8
+ admit-or-refuse decision (:func:`admit_vcs_url`) called eagerly
9
+ during requirement ingestion.
10
+
11
+ The actual clone path lives in :mod:`nab_index.vcs` and runs only
12
+ after admission lets the URL through.
13
+ """
14
+
15
+ from __future__ import annotations
16
+
17
+ import enum
18
+ from dataclasses import dataclass
19
+
20
+ from nab_index.vcs import FULL_GIT_SHA_RE
21
+
22
+ __all__ = [
23
+ "UnsupportedVcsError",
24
+ "VcsConfig",
25
+ "VcsPolicy",
26
+ ]
27
+
28
+
29
+ class VcsPolicy(enum.Enum):
30
+ """Whether to honor VCS direct-URL requirements (``pkg @ git+https://...``).
31
+
32
+ Cloning a remote repo is one short step from arbitrary code execution
33
+ (modern Python projects build via PEP 517 backends, which run user
34
+ code). Default posture is :attr:`BLOCK`; opt-in is per-protocol via
35
+ ``vcs_allowed_schemes`` and per-repo via ``vcs_allowed_repos``.
36
+ """
37
+
38
+ BLOCK = "block"
39
+ """Refuse any requirement whose URL is non-empty."""
40
+
41
+ ALLOW = "allow"
42
+ """Honor VCS subject to scheme + repo allowlists.
43
+
44
+ Cloning a repo is staged in two phases: admission (this enum gates
45
+ whether a URL is even considered) and materialisation (the clone
46
+ happens lazily through :class:`VcsSource` when the resolver asks
47
+ for the package's metadata).
48
+ """
49
+
50
+
51
+ class UnsupportedVcsError(Exception):
52
+ """A VCS / direct-URL requirement was refused by policy.
53
+
54
+ Raised eagerly during requirement ingestion; not surfaced as a
55
+ "no candidates" backtrack so the user sees a clear diagnostic.
56
+ """
57
+
58
+
59
+ @dataclass(frozen=True)
60
+ class VcsConfig:
61
+ """Bundle of VCS opt-in knobs passed through the resolver stack.
62
+
63
+ Default is fully restrictive (``BLOCK`` policy, empty allowlists,
64
+ pin required).
65
+ """
66
+
67
+ policy: VcsPolicy = VcsPolicy.BLOCK
68
+ allowed_schemes: frozenset[str] = frozenset()
69
+ allowed_repos: tuple[str, ...] = ()
70
+ require_pin: bool = True
71
+
72
+
73
+ _VCS_SCHEMES: frozenset[str] = frozenset(
74
+ {
75
+ "git+https",
76
+ "git+ssh",
77
+ "git+http",
78
+ "git+file",
79
+ "git+git",
80
+ "git",
81
+ "hg+https",
82
+ "hg+ssh",
83
+ "hg+http",
84
+ "hg+file",
85
+ "hg+static-http",
86
+ "bzr+https",
87
+ "bzr+ssh",
88
+ "bzr+sftp",
89
+ "bzr+ftp",
90
+ "bzr+lp",
91
+ "bzr+file",
92
+ "svn",
93
+ "svn+https",
94
+ "svn+ssh",
95
+ "svn+http",
96
+ "svn+file",
97
+ }
98
+ )
99
+
100
+ _VCS_INSECURE_SCHEMES: frozenset[str] = frozenset(
101
+ {"git", "git+git", "git+http", "hg+http", "bzr+http", "svn", "svn+http"}
102
+ )
103
+
104
+
105
+ def split_vcs_scheme(url: str) -> tuple[str | None, str]:
106
+ """Strip a recognized VCS scheme prefix.
107
+
108
+ ``"git+https://example.com/r.git@v1"`` -> ``("git+https", "https://example.com/r.git@v1")``.
109
+ ``"svn://example.com/r"`` -> ``("svn", "svn://example.com/r")``.
110
+ ``"https://example.com/file.whl"`` -> ``(None, "https://example.com/file.whl")``.
111
+
112
+ Returns ``(None, url)`` for non-VCS URLs (e.g. plain ``https://``
113
+ archives or ``file://`` paths) so the caller can refuse them
114
+ separately. Pip-compatible scheme list; not standardized by any PEP.
115
+ """
116
+ for vcs_scheme in _VCS_SCHEMES:
117
+ if not url.startswith(f"{vcs_scheme}://"):
118
+ continue
119
+ inner_scheme, plus, _ = vcs_scheme.partition("+")
120
+ if not plus:
121
+ return (vcs_scheme, url)
122
+ return (vcs_scheme, url[len(inner_scheme) + 1 :])
123
+ return (None, url)
124
+
125
+
126
+ def has_full_commit_sha(url: str) -> bool:
127
+ """Return True if the URL pins to a 40-char hex commit hash.
128
+
129
+ Looks for ``@<sha>`` after the scheme://host portion; ignores any
130
+ ``#`` fragment. Tolerates ``user@host`` syntax by taking the last
131
+ ``@`` in the path/ref portion. Mercurial uses 40-char SHA1 too, so
132
+ the same regex covers git+hg. Bzr/svn revisions are not hashes;
133
+ ``vcs_require_pin = False`` is the way to allow those.
134
+ """
135
+ fragmentless = url.split("#", 1)[0]
136
+ after_authority = fragmentless.split("://", 1)[-1]
137
+ if "@" not in after_authority:
138
+ return False
139
+ ref = after_authority.rsplit("@", 1)[1]
140
+ return bool(FULL_GIT_SHA_RE.match(ref))
141
+
142
+
143
+ def admit_vcs_url(url: str, config: VcsConfig) -> str:
144
+ """Admit a direct-URL requirement, or raise :class:`UnsupportedVcsError`.
145
+
146
+ Returns the recognized VCS scheme on success. Called eagerly when
147
+ ingesting root requirements with a non-empty
148
+ :attr:`Requirement.url <packaging.requirements.Requirement.url>`.
149
+ """
150
+ scheme, inner_url = split_vcs_scheme(url)
151
+ if scheme is None:
152
+ msg = (
153
+ "refusing direct-URL requirement (not a recognized VCS scheme)\n"
154
+ f" {url}\n"
155
+ " note: nab supports git+/hg+/bzr+/svn+ schemes only;"
156
+ " plain http(s)/file archive URLs are not supported."
157
+ )
158
+ raise UnsupportedVcsError(msg)
159
+
160
+ if config.policy is VcsPolicy.BLOCK:
161
+ msg = (
162
+ "refusing VCS requirement\n"
163
+ f" {url}\n"
164
+ " reason: VcsPolicy is BLOCK (default).\n"
165
+ " to allow: set vcs_policy=VcsPolicy.ALLOW with appropriate\n"
166
+ " vcs_allowed_schemes (and optionally vcs_allowed_repos)."
167
+ )
168
+ raise UnsupportedVcsError(msg)
169
+
170
+ if scheme not in config.allowed_schemes:
171
+ allowed_str = ", ".join(sorted(config.allowed_schemes)) or "<empty>"
172
+ msg = (
173
+ "refusing VCS scheme\n"
174
+ f" {url}\n"
175
+ f' reason: scheme "{scheme}" not in vcs_allowed_schemes='
176
+ f"{{{allowed_str}}}."
177
+ )
178
+ if scheme in _VCS_INSECURE_SCHEMES:
179
+ msg += (
180
+ f'\n note: "{scheme}" is unauthenticated;'
181
+ " consider an https/ssh variant."
182
+ )
183
+ raise UnsupportedVcsError(msg)
184
+
185
+ if config.allowed_repos and not any(
186
+ inner_url.startswith(prefix) for prefix in config.allowed_repos
187
+ ):
188
+ allowed_str = ", ".join(sorted(config.allowed_repos))
189
+ msg = (
190
+ "refusing VCS repo\n"
191
+ f" {url}\n"
192
+ " reason: repo URL prefix not in vcs_allowed_repos.\n"
193
+ f" allowed prefixes: {allowed_str}"
194
+ )
195
+ raise UnsupportedVcsError(msg)
196
+
197
+ if config.require_pin and not has_full_commit_sha(url):
198
+ msg = (
199
+ "refusing unpinned VCS ref\n"
200
+ f" {url}\n"
201
+ " reason: vcs_require_pin is True and no 40-char commit hash"
202
+ " present.\n"
203
+ " to allow: pin the requirement to a 40-char commit hash, or set\n"
204
+ " vcs_require_pin=False (not recommended for"
205
+ " reproducible installs)."
206
+ )
207
+ raise UnsupportedVcsError(msg)
208
+
209
+ return scheme
@@ -0,0 +1,6 @@
1
+ """Vendored third-party libraries used by nab-python.
2
+
3
+ See ``packaging/PROVENANCE.md`` for the source of the vendored
4
+ ``packaging`` snapshot and the conditions under which it should be
5
+ removed.
6
+ """
@@ -0,0 +1,3 @@
1
+ This software is made available under the terms of *either* of the licenses
2
+ found in LICENSE.APACHE or LICENSE.BSD. Contributions to this software is made
3
+ under the terms of *both* these licenses.
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,23 @@
1
+ Copyright (c) Donald Stufft and individual contributors.
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ 2. Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
15
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
16
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
17
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
18
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,73 @@
1
+ # Vendored `packaging` snapshot
2
+
3
+ This directory holds an unmodified copy of the `packaging` library taken
4
+ from an in-flight pull request, vendored so nab can use the public
5
+ `VersionRange` API before the PR is merged and released.
6
+
7
+ ## Source
8
+
9
+ - Upstream repository: https://github.com/pypa/packaging
10
+ - Pull request: https://github.com/pypa/packaging/pull/1182
11
+ - Source branch: `notatallshaw/packaging:public-pep440-version-range`
12
+ - Pinned commit: `536a8a7ba0c552b4573522292d1ea63ccb4ad34c`
13
+ - Snapshot date: 2026-05-03
14
+
15
+ The snapshot is the full `src/packaging/` tree at that commit, plus
16
+ `LICENSE`, `LICENSE.APACHE`, and `LICENSE.BSD` from the repository
17
+ root. No code changes were made; relative imports inside `packaging`
18
+ (`from .version import Version`, etc.) keep working when the package
19
+ is loaded as `nab_python._vendor.packaging`.
20
+
21
+ ## License
22
+
23
+ `packaging` is dual-licensed under the Apache License 2.0 and the
24
+ 2-Clause BSD License. The LICENSE files in this directory are the
25
+ upstream texts; nothing here is relicensed.
26
+
27
+ ## Why vendor instead of depending on it
28
+
29
+ `packaging` PR 1182 promotes the internal range helpers to a public
30
+ `VersionRange` class with set algebra (intersection, union,
31
+ complement) and `to_range()` / `from_specifier_set()` factories that
32
+ nab's PubGrub solver depends on. The PR is open and has not yet been
33
+ released on PyPI, so there is no version we can pin in
34
+ `pyproject.toml`. Vendoring is a temporary measure.
35
+
36
+ ## Removal plan
37
+
38
+ Delete this entire directory and reinstate `packaging` as a normal
39
+ dependency once **both** are true:
40
+
41
+ 1. PR 1182 has merged into `pypa/packaging:main`.
42
+ 2. A `packaging` release containing the merged commit has been
43
+ published to PyPI.
44
+
45
+ Once those hold:
46
+
47
+ - Add `packaging>=<release>` back to `nab-python/pyproject.toml`
48
+ `[project].dependencies`.
49
+ - Search-replace `from nab_python._vendor.packaging` ->
50
+ `from packaging` and `import nab_python._vendor.packaging` ->
51
+ `import packaging` across the workspace.
52
+ - Remove this `_vendor/` tree.
53
+
54
+ ## Updating the snapshot
55
+
56
+ If PR 1182 is updated and nab needs the newer code:
57
+
58
+ ```
59
+ cd packaging # the upstream fork checkout
60
+ git fetch origin public-pep440-version-range
61
+ NEW_SHA=$(git rev-parse origin/public-pep440-version-range)
62
+ DEST=/path/to/nab/nab-python/src/nab_python/_vendor/packaging
63
+ for f in $(git ls-tree -r --name-only origin/public-pep440-version-range -- src/packaging); do
64
+ rel=${f#src/packaging/}
65
+ mkdir -p "$(dirname "$DEST/$rel")"
66
+ git show "origin/public-pep440-version-range:$f" > "$DEST/$rel"
67
+ done
68
+ for f in LICENSE LICENSE.APACHE LICENSE.BSD; do
69
+ git show "origin/public-pep440-version-range:$f" > "$DEST/$f"
70
+ done
71
+ ```
72
+
73
+ Then update the **Pinned commit** and **Snapshot date** lines above.
@@ -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__ = "26.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__ = f"2014 {__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
+ ELF header: https://refspecs.linuxfoundation.org/elf/gabi4+/ch4.eheader.html
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ import enum
13
+ import os
14
+ import struct
15
+ from typing import IO
16
+
17
+
18
+ class ELFInvalid(ValueError):
19
+ pass
20
+
21
+
22
+ class EIClass(enum.IntEnum):
23
+ C32 = 1
24
+ C64 = 2
25
+
26
+
27
+ class EIData(enum.IntEnum):
28
+ Lsb = 1
29
+ Msb = 2
30
+
31
+
32
+ class EMachine(enum.IntEnum):
33
+ I386 = 3
34
+ S390 = 22
35
+ Arm = 40
36
+ X8664 = 62
37
+ AArc64 = 183
38
+
39
+
40
+ class ELFFile:
41
+ """
42
+ Representation of an ELF executable.
43
+ """
44
+
45
+ def __init__(self, f: IO[bytes]) -> None:
46
+ self._f = f
47
+
48
+ try:
49
+ ident = self._read("16B")
50
+ except struct.error as e:
51
+ raise ELFInvalid("unable to parse identification") from e
52
+ magic = bytes(ident[:4])
53
+ if magic != b"\x7fELF":
54
+ raise ELFInvalid(f"invalid magic: {magic!r}")
55
+
56
+ self.capacity = ident[4] # Format for program header (bitness).
57
+ self.encoding = ident[5] # Data structure encoding (endianness).
58
+
59
+ try:
60
+ # e_fmt: Format for program header.
61
+ # p_fmt: Format for section header.
62
+ # p_idx: Indexes to find p_type, p_offset, and p_filesz.
63
+ e_fmt, self._p_fmt, self._p_idx = {
64
+ (1, 1): ("<HHIIIIIHHH", "<IIIIIIII", (0, 1, 4)), # 32-bit LSB.
65
+ (1, 2): (">HHIIIIIHHH", ">IIIIIIII", (0, 1, 4)), # 32-bit MSB.
66
+ (2, 1): ("<HHIQQQIHHH", "<IIQQQQQQ", (0, 2, 5)), # 64-bit LSB.
67
+ (2, 2): (">HHIQQQIHHH", ">IIQQQQQQ", (0, 2, 5)), # 64-bit MSB.
68
+ }[(self.capacity, self.encoding)]
69
+ except KeyError as e:
70
+ raise ELFInvalid(
71
+ f"unrecognized capacity ({self.capacity}) or encoding ({self.encoding})"
72
+ ) from e
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) -> str | None:
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