basstler-packaging 4.2.0__tar.gz
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.
- basstler_packaging-4.2.0/.gitignore +13 -0
- basstler_packaging-4.2.0/LICENSE +202 -0
- basstler_packaging-4.2.0/NOTICE +13 -0
- basstler_packaging-4.2.0/PKG-INFO +14 -0
- basstler_packaging-4.2.0/pyproject.toml +51 -0
- basstler_packaging-4.2.0/src/basstler/packaging/__init__.py +3 -0
- basstler_packaging-4.2.0/src/basstler/packaging/package_index.py +37 -0
- basstler_packaging-4.2.0/src/basstler/packaging/publish_workflow.py +279 -0
- basstler_packaging-4.2.0/src/basstler/packaging/release.py +190 -0
- basstler_packaging-4.2.0/tests/__init__.py +0 -0
- basstler_packaging-4.2.0/tests/test_release.py +89 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
__pycache__/
|
|
2
|
+
*.egg-info/
|
|
3
|
+
.venv/
|
|
4
|
+
.pytest_cache/
|
|
5
|
+
|
|
6
|
+
# What the plugin's own session start writes into the project it serves - this
|
|
7
|
+
# repository, when developing it with its own plugin enabled. Personal, never committed.
|
|
8
|
+
CLAUDE.local.md
|
|
9
|
+
.claude/settings.local.json
|
|
10
|
+
|
|
11
|
+
# Everything the last maintenance pass did, written by `python3 -m basstler.maintenance
|
|
12
|
+
# run-report` beside the board. Scratch state, never committed.
|
|
13
|
+
src/basstler/maintenance-report.json
|
|
@@ -0,0 +1,202 @@
|
|
|
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
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
basstler
|
|
2
|
+
Copyright 2026 Abdelrhman Bassiouny and the basstler contributors
|
|
3
|
+
|
|
4
|
+
basstler (https://github.com/KAOS-repositories/basstler) is licensed under the
|
|
5
|
+
Apache License, Version 2.0 (see LICENSE). Abdelrhman Bassiouny wrote it
|
|
6
|
+
independently of any employer or institution and maintains it in the
|
|
7
|
+
KAOS-repositories organization on GitHub; contributors keep the copyright on
|
|
8
|
+
their contributions.
|
|
9
|
+
|
|
10
|
+
packages/core/src/basstler/{exceptions,class_property}.py contain code adapted
|
|
11
|
+
from krrood (https://github.com/cram2/cognitive_robot_abstract_machine/tree/main/krrood),
|
|
12
|
+
copyright the krrood authors, which remains licensed under the GNU Lesser
|
|
13
|
+
General Public License, version 3 only (LGPL-3.0-only).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: basstler-packaging
|
|
3
|
+
Version: 4.2.0
|
|
4
|
+
Summary: The model of a Python release: the wheels and source distributions a build writes, the package indexes, and the workflow that publishes them.
|
|
5
|
+
Project-URL: Source, https://github.com/KAOS-repositories/basstler
|
|
6
|
+
Project-URL: Bug Tracker, https://github.com/KAOS-repositories/basstler/issues
|
|
7
|
+
Author-email: Abdelrhman Bassiouny <bido.bassuny@gmail.com>
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Requires-Dist: basstler-build==4.2.0
|
|
11
|
+
Requires-Dist: basstler-core==4.2.0
|
|
12
|
+
Requires-Dist: basstler-github==4.2.0
|
|
13
|
+
Requires-Dist: packaging>=24
|
|
14
|
+
Requires-Dist: pyyaml>=6
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.24", "hatch-vcs>=0.4", "basstler-build"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "basstler-packaging"
|
|
7
|
+
description = "The model of a Python release: the wheels and source distributions a build writes, the package indexes, and the workflow that publishes them."
|
|
8
|
+
requires-python = ">=3.12"
|
|
9
|
+
license = "Apache-2.0"
|
|
10
|
+
license-files = ["LICENSE", "NOTICE"]
|
|
11
|
+
authors = [{name = "Abdelrhman Bassiouny", email = "bido.bassuny@gmail.com"}]
|
|
12
|
+
dynamic = ["version", "dependencies"]
|
|
13
|
+
|
|
14
|
+
[project.urls]
|
|
15
|
+
"Source" = "https://github.com/KAOS-repositories/basstler"
|
|
16
|
+
"Bug Tracker" = "https://github.com/KAOS-repositories/basstler/issues"
|
|
17
|
+
|
|
18
|
+
[tool.hatch.version]
|
|
19
|
+
source = "vcs"
|
|
20
|
+
fallback-version = "0.0.0"
|
|
21
|
+
raw-options = {root = "../.."}
|
|
22
|
+
|
|
23
|
+
# Built with every basstler requirement pinned to this release.
|
|
24
|
+
[tool.hatch.metadata.hooks.basstler-sibling-pins]
|
|
25
|
+
family = "basstler"
|
|
26
|
+
dependencies = [
|
|
27
|
+
"packaging>=24",
|
|
28
|
+
"pyyaml>=6",
|
|
29
|
+
"basstler-build",
|
|
30
|
+
"basstler-core",
|
|
31
|
+
"basstler-github",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[tool.hatch.build.targets.wheel]
|
|
35
|
+
packages = ["src/basstler"]
|
|
36
|
+
|
|
37
|
+
# The repository's licence and notices, put at the root of the source distribution so
|
|
38
|
+
# the wheel built from it carries them.
|
|
39
|
+
[tool.hatch.build.targets.sdist.force-include]
|
|
40
|
+
"../../LICENSE" = "LICENSE"
|
|
41
|
+
"../../NOTICE" = "NOTICE"
|
|
42
|
+
|
|
43
|
+
# What this distribution's tests need besides itself.
|
|
44
|
+
[dependency-groups]
|
|
45
|
+
dev = [
|
|
46
|
+
"pytest",
|
|
47
|
+
"pytest-xdist",
|
|
48
|
+
"basstler-build",
|
|
49
|
+
"basstler-core",
|
|
50
|
+
"basstler-github",
|
|
51
|
+
]
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The package indexes a release is published to.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from enum import StrEnum
|
|
8
|
+
|
|
9
|
+
# %% indexes
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class PackageIndex(StrEnum):
|
|
13
|
+
"""
|
|
14
|
+
A package index; each value starts the names of the GitHub environments its trusted
|
|
15
|
+
publishers name.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
TESTPYPI = "testpypi"
|
|
19
|
+
PYPI = "pypi"
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def upload_url(self) -> str | None:
|
|
23
|
+
"""
|
|
24
|
+
Where the index takes uploads, unset where the publish action's default, PyPI
|
|
25
|
+
itself, is the address.
|
|
26
|
+
"""
|
|
27
|
+
return {
|
|
28
|
+
PackageIndex.TESTPYPI: "https://test.pypi.org/legacy/",
|
|
29
|
+
PackageIndex.PYPI: None,
|
|
30
|
+
}[self]
|
|
31
|
+
|
|
32
|
+
def publishing_environment(self, distribution_name: str) -> str:
|
|
33
|
+
"""
|
|
34
|
+
:param distribution_name: The distribution published, or an expression giving it.
|
|
35
|
+
:return: The GitHub environment the distribution is published to the index from.
|
|
36
|
+
"""
|
|
37
|
+
return f"{self}-{distribution_name}"
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""
|
|
2
|
+
A workflow file that publishes a release's distributions to a package index through
|
|
3
|
+
trusted publishing, parsed into the parts that decide how it publishes.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from __future__ import annotations
|
|
7
|
+
|
|
8
|
+
from enum import StrEnum
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from typing import Annotated, Any
|
|
11
|
+
|
|
12
|
+
import yaml
|
|
13
|
+
from basstler.github.workflows import TriggerEvent
|
|
14
|
+
from basstler.json_model import RawValueReader, ValidatedJSONModel
|
|
15
|
+
from basstler.text_file import TextFile
|
|
16
|
+
from pydantic import Field
|
|
17
|
+
|
|
18
|
+
# %% vocabulary
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class PublishAction(StrEnum):
|
|
22
|
+
"""
|
|
23
|
+
The actions a publishing workflow uses to hand files over and publish them.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
PUBLISH = "pypa/gh-action-pypi-publish"
|
|
27
|
+
UPLOAD = "actions/upload-artifact"
|
|
28
|
+
DOWNLOAD = "actions/download-artifact"
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class IdentityTokenPermission(StrEnum):
|
|
32
|
+
"""
|
|
33
|
+
The permission that lets a job request an identity token, and the level it needs.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
SCOPE = "id-token"
|
|
37
|
+
LEVEL = "write"
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class PublishActionInput(StrEnum):
|
|
41
|
+
"""
|
|
42
|
+
The inputs of the publish action a release depends on.
|
|
43
|
+
"""
|
|
44
|
+
|
|
45
|
+
REPOSITORY_URL = "repository-url"
|
|
46
|
+
PACKAGES_DIRECTORY = "packages-dir"
|
|
47
|
+
SKIP_EXISTING = "skip-existing"
|
|
48
|
+
PASSWORD = "password"
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ArtifactActionInput(StrEnum):
|
|
52
|
+
"""
|
|
53
|
+
The inputs of the actions that hand files between jobs a release depends on.
|
|
54
|
+
"""
|
|
55
|
+
|
|
56
|
+
PATH = "path"
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
# %% the parts of the file
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ListOfOne(RawValueReader):
|
|
63
|
+
"""
|
|
64
|
+
Reads a single value as the list holding it, as a workflow file may write either.
|
|
65
|
+
"""
|
|
66
|
+
|
|
67
|
+
def read(self, value: Any) -> Any:
|
|
68
|
+
"""
|
|
69
|
+
:param value: A value or a list of them.
|
|
70
|
+
:return: A list.
|
|
71
|
+
"""
|
|
72
|
+
return value if isinstance(value, list) else [value]
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class PublishStep(ValidatedJSONModel):
|
|
76
|
+
"""
|
|
77
|
+
One step of a job.
|
|
78
|
+
"""
|
|
79
|
+
|
|
80
|
+
step_id: str | None = Field(default=None, alias="id")
|
|
81
|
+
"""
|
|
82
|
+
The name other steps and jobs refer to it by; unset when none does.
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
uses: str | None = None
|
|
86
|
+
"""
|
|
87
|
+
The action it uses, with the version it pins; unset for a shell step.
|
|
88
|
+
"""
|
|
89
|
+
|
|
90
|
+
run: str | None = None
|
|
91
|
+
"""
|
|
92
|
+
The shell it runs; unset for an action step.
|
|
93
|
+
"""
|
|
94
|
+
|
|
95
|
+
action_inputs_by_name: dict[str, Any] = Field(default_factory=dict, alias="with")
|
|
96
|
+
"""
|
|
97
|
+
The inputs it passes to its action.
|
|
98
|
+
"""
|
|
99
|
+
|
|
100
|
+
environment_variables: dict[str, str] = Field(default_factory=dict, alias="env")
|
|
101
|
+
"""
|
|
102
|
+
The environment variables it sets, by name.
|
|
103
|
+
"""
|
|
104
|
+
|
|
105
|
+
@property
|
|
106
|
+
def action(self) -> str | None:
|
|
107
|
+
"""
|
|
108
|
+
The action it uses, without its version.
|
|
109
|
+
"""
|
|
110
|
+
return self.uses.partition("@")[0] if self.uses else None
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
class PublishStrategy(ValidatedJSONModel):
|
|
114
|
+
"""
|
|
115
|
+
How a job is run once for each combination of its matrix.
|
|
116
|
+
"""
|
|
117
|
+
|
|
118
|
+
matrix: dict[str, Any]
|
|
119
|
+
"""
|
|
120
|
+
The values each run takes, by the variable that holds them.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
fail_fast: bool = Field(default=True, alias="fail-fast")
|
|
124
|
+
"""
|
|
125
|
+
Whether one run failing cancels the others.
|
|
126
|
+
"""
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
class PublishJob(ValidatedJSONModel):
|
|
130
|
+
"""
|
|
131
|
+
One job of the workflow.
|
|
132
|
+
"""
|
|
133
|
+
|
|
134
|
+
steps: list[PublishStep]
|
|
135
|
+
"""
|
|
136
|
+
Its steps, in order.
|
|
137
|
+
"""
|
|
138
|
+
|
|
139
|
+
condition: str | None = Field(default=None, alias="if")
|
|
140
|
+
"""
|
|
141
|
+
The condition it runs under; unset when it always runs.
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
needs: Annotated[list[str], ListOfOne()] = Field(default_factory=list)
|
|
145
|
+
"""
|
|
146
|
+
The jobs that must succeed before it starts.
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
environment: str | None = None
|
|
150
|
+
"""
|
|
151
|
+
The GitHub environment it runs in.
|
|
152
|
+
"""
|
|
153
|
+
|
|
154
|
+
permissions: dict[str, str] = Field(default_factory=dict)
|
|
155
|
+
"""
|
|
156
|
+
The permissions it asks for, by scope.
|
|
157
|
+
"""
|
|
158
|
+
|
|
159
|
+
strategy: PublishStrategy | None = None
|
|
160
|
+
"""
|
|
161
|
+
The matrix it runs over; unset when it runs once.
|
|
162
|
+
"""
|
|
163
|
+
|
|
164
|
+
outputs: dict[str, str] = Field(default_factory=dict)
|
|
165
|
+
"""
|
|
166
|
+
The values it hands to the jobs that need it, by name.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
@property
|
|
170
|
+
def requests_identity_token(self) -> bool:
|
|
171
|
+
"""
|
|
172
|
+
Whether it may ask for the identity token an index's trusted publisher accepts.
|
|
173
|
+
"""
|
|
174
|
+
return (
|
|
175
|
+
self.permissions.get(IdentityTokenPermission.SCOPE)
|
|
176
|
+
== IdentityTokenPermission.LEVEL
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
def step_using(self, action: PublishAction) -> PublishStep:
|
|
180
|
+
"""
|
|
181
|
+
:param action: An action, without its version.
|
|
182
|
+
:return: The one step that uses it.
|
|
183
|
+
"""
|
|
184
|
+
(step,) = (step for step in self.steps if step.action == action)
|
|
185
|
+
return step
|
|
186
|
+
|
|
187
|
+
def identified_step(self, step_id: str) -> PublishStep:
|
|
188
|
+
"""
|
|
189
|
+
:param step_id: The name a step is referred to by.
|
|
190
|
+
:return: The step of that name.
|
|
191
|
+
"""
|
|
192
|
+
(step,) = (step for step in self.steps if step.step_id == step_id)
|
|
193
|
+
return step
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
class FollowedRunTrigger(ValidatedJSONModel):
|
|
197
|
+
"""
|
|
198
|
+
The trigger that starts the workflow when other workflows' runs reach a stage.
|
|
199
|
+
"""
|
|
200
|
+
|
|
201
|
+
workflow_names: list[str] = Field(alias="workflows")
|
|
202
|
+
"""
|
|
203
|
+
The workflows it follows.
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
trigger_types: list[str] = Field(alias="types")
|
|
207
|
+
"""
|
|
208
|
+
The stages of their runs it starts on.
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
class ManualTrigger(ValidatedJSONModel):
|
|
213
|
+
"""
|
|
214
|
+
The trigger that starts the workflow by hand.
|
|
215
|
+
"""
|
|
216
|
+
|
|
217
|
+
inputs_by_name: dict[str, Any] = Field(default_factory=dict, alias="inputs")
|
|
218
|
+
"""
|
|
219
|
+
What the person starting it may give.
|
|
220
|
+
"""
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
class PublishTriggers(ValidatedJSONModel):
|
|
224
|
+
"""
|
|
225
|
+
The events the workflow runs on.
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
followed_run: FollowedRunTrigger = Field(alias=TriggerEvent.WORKFLOW_RUN)
|
|
229
|
+
"""
|
|
230
|
+
The stage of another workflow's run that starts it.
|
|
231
|
+
"""
|
|
232
|
+
|
|
233
|
+
manual: ManualTrigger = Field(alias=TriggerEvent.WORKFLOW_DISPATCH)
|
|
234
|
+
"""
|
|
235
|
+
A run started by hand.
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
class TriggersKey(StrEnum):
|
|
240
|
+
"""
|
|
241
|
+
The key that holds a workflow's events, which YAML reads as ``True``.
|
|
242
|
+
"""
|
|
243
|
+
|
|
244
|
+
ON = "on"
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
class PublishWorkflow(ValidatedJSONModel):
|
|
248
|
+
"""
|
|
249
|
+
A workflow file that publishes a release.
|
|
250
|
+
"""
|
|
251
|
+
|
|
252
|
+
jobs: dict[str, PublishJob]
|
|
253
|
+
"""
|
|
254
|
+
Its jobs, by name.
|
|
255
|
+
"""
|
|
256
|
+
|
|
257
|
+
triggers: PublishTriggers = Field(alias=TriggersKey.ON)
|
|
258
|
+
"""
|
|
259
|
+
The events it runs on.
|
|
260
|
+
"""
|
|
261
|
+
|
|
262
|
+
permissions: dict[str, str] = Field(default_factory=dict)
|
|
263
|
+
"""
|
|
264
|
+
The permissions every job starts from.
|
|
265
|
+
"""
|
|
266
|
+
|
|
267
|
+
@classmethod
|
|
268
|
+
def read(cls, path: Path) -> PublishWorkflow:
|
|
269
|
+
"""
|
|
270
|
+
:param path: A workflow file.
|
|
271
|
+
:return: The parsed workflow.
|
|
272
|
+
"""
|
|
273
|
+
data = yaml.safe_load(TextFile(path).read())
|
|
274
|
+
return cls.from_json(
|
|
275
|
+
{
|
|
276
|
+
TriggersKey.ON if key is True else key: value
|
|
277
|
+
for key, value in data.items()
|
|
278
|
+
}
|
|
279
|
+
)
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"""
|
|
2
|
+
The distributions one release builds, read back from the files ``uv build`` wrote.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import tarfile
|
|
8
|
+
import zipfile
|
|
9
|
+
from dataclasses import dataclass
|
|
10
|
+
from enum import StrEnum
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from packaging.requirements import Requirement
|
|
14
|
+
from packaging.utils import canonicalize_name
|
|
15
|
+
|
|
16
|
+
# %% vocabulary
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class ReleaseFile(StrEnum):
|
|
20
|
+
"""
|
|
21
|
+
The files every distribution ships beside its code, named as in the repository root.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
LICENSE = "LICENSE"
|
|
25
|
+
NOTICE = "NOTICE"
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class DistributionSuffix(StrEnum):
|
|
29
|
+
"""
|
|
30
|
+
The endings of the files a build writes.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
WHEEL = ".whl"
|
|
34
|
+
SOURCE = ".tar.gz"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
class DistributionMember(StrEnum):
|
|
38
|
+
"""
|
|
39
|
+
The parts of a wheel's ``dist-info`` folder a release is read from.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
METADATA = ".dist-info/METADATA"
|
|
43
|
+
LICENSES = ".dist-info/licenses/"
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class RequirementField(StrEnum):
|
|
47
|
+
"""
|
|
48
|
+
The metadata field naming one requirement of a distribution.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
REQUIRES_DIST = "Requires-Dist: "
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# %% the built files
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
@dataclass(frozen=True)
|
|
58
|
+
class PythonWheel:
|
|
59
|
+
"""
|
|
60
|
+
A built Python wheel: the file a distribution is installed from.
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
path: Path
|
|
64
|
+
"""
|
|
65
|
+
The wheel file.
|
|
66
|
+
"""
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def distribution_name(self) -> str:
|
|
70
|
+
"""
|
|
71
|
+
The canonical name of the distribution it is of.
|
|
72
|
+
"""
|
|
73
|
+
return canonicalize_name(self.path.name.split("-")[0])
|
|
74
|
+
|
|
75
|
+
@property
|
|
76
|
+
def version(self) -> str:
|
|
77
|
+
"""
|
|
78
|
+
The version it carries.
|
|
79
|
+
"""
|
|
80
|
+
return self.path.name.split("-")[1]
|
|
81
|
+
|
|
82
|
+
@property
|
|
83
|
+
def requirements(self) -> list[Requirement]:
|
|
84
|
+
"""
|
|
85
|
+
The requirements its metadata declares.
|
|
86
|
+
"""
|
|
87
|
+
with zipfile.ZipFile(self.path) as archive:
|
|
88
|
+
(metadata,) = (
|
|
89
|
+
name
|
|
90
|
+
for name in archive.namelist()
|
|
91
|
+
if name.endswith(DistributionMember.METADATA)
|
|
92
|
+
)
|
|
93
|
+
lines = archive.read(metadata).decode("utf-8").splitlines()
|
|
94
|
+
return [
|
|
95
|
+
Requirement(line.removeprefix(RequirementField.REQUIRES_DIST))
|
|
96
|
+
for line in lines
|
|
97
|
+
if line.startswith(RequirementField.REQUIRES_DIST)
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
@property
|
|
101
|
+
def licence(self) -> bytes:
|
|
102
|
+
"""
|
|
103
|
+
What the wheel carries of the :attr:`ReleaseFile.LICENSE` file.
|
|
104
|
+
"""
|
|
105
|
+
return self.carried_file(ReleaseFile.LICENSE)
|
|
106
|
+
|
|
107
|
+
@property
|
|
108
|
+
def notice(self) -> bytes:
|
|
109
|
+
"""
|
|
110
|
+
What the wheel carries of the :attr:`ReleaseFile.NOTICE` file.
|
|
111
|
+
"""
|
|
112
|
+
return self.carried_file(ReleaseFile.NOTICE)
|
|
113
|
+
|
|
114
|
+
def carried_file(self, release_file: ReleaseFile) -> bytes:
|
|
115
|
+
"""
|
|
116
|
+
:param release_file: One of the files every distribution carries.
|
|
117
|
+
:return: What the wheel carries of it, under its ``dist-info`` licences.
|
|
118
|
+
"""
|
|
119
|
+
with zipfile.ZipFile(self.path) as archive:
|
|
120
|
+
(entry,) = (
|
|
121
|
+
name
|
|
122
|
+
for name in archive.namelist()
|
|
123
|
+
if DistributionMember.LICENSES in name
|
|
124
|
+
and Path(name).name == release_file
|
|
125
|
+
)
|
|
126
|
+
return archive.read(entry)
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
@dataclass(frozen=True)
|
|
130
|
+
class SourceDistribution:
|
|
131
|
+
"""
|
|
132
|
+
A built source distribution.
|
|
133
|
+
"""
|
|
134
|
+
|
|
135
|
+
path: Path
|
|
136
|
+
"""
|
|
137
|
+
The archive.
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def distribution_name(self) -> str:
|
|
142
|
+
"""
|
|
143
|
+
The canonical name of the distribution it is of.
|
|
144
|
+
"""
|
|
145
|
+
return canonicalize_name(self.path.name.rsplit("-", 1)[0])
|
|
146
|
+
|
|
147
|
+
def carries_file_at_root(self, release_file: ReleaseFile) -> bool:
|
|
148
|
+
"""
|
|
149
|
+
:param release_file: One of the files every distribution carries.
|
|
150
|
+
:return: Whether it sits at the root of the archive.
|
|
151
|
+
"""
|
|
152
|
+
root = self.path.name.removesuffix(DistributionSuffix.SOURCE)
|
|
153
|
+
with tarfile.open(self.path) as archive:
|
|
154
|
+
return f"{root}/{release_file}" in archive.getnames()
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
@dataclass(frozen=True)
|
|
158
|
+
class BuiltRelease:
|
|
159
|
+
"""
|
|
160
|
+
The files ``uv build --all-packages`` wrote.
|
|
161
|
+
"""
|
|
162
|
+
|
|
163
|
+
directory: Path
|
|
164
|
+
"""
|
|
165
|
+
Where the wheels and source distributions are.
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
@property
|
|
169
|
+
def wheels_by_distribution_name(self) -> dict[str, PythonWheel]:
|
|
170
|
+
"""
|
|
171
|
+
The wheels, by the canonical name of the distribution each is of.
|
|
172
|
+
"""
|
|
173
|
+
found = (
|
|
174
|
+
PythonWheel(path)
|
|
175
|
+
for path in self.directory.glob(f"*{DistributionSuffix.WHEEL}")
|
|
176
|
+
)
|
|
177
|
+
return {wheel.distribution_name: wheel for wheel in found}
|
|
178
|
+
|
|
179
|
+
@property
|
|
180
|
+
def source_distributions_by_distribution_name(
|
|
181
|
+
self,
|
|
182
|
+
) -> dict[str, SourceDistribution]:
|
|
183
|
+
"""
|
|
184
|
+
The source distributions, by the canonical name of the distribution each is of.
|
|
185
|
+
"""
|
|
186
|
+
found = (
|
|
187
|
+
SourceDistribution(path)
|
|
188
|
+
for path in self.directory.glob(f"*{DistributionSuffix.SOURCE}")
|
|
189
|
+
)
|
|
190
|
+
return {source.distribution_name: source for source in found}
|
|
File without changes
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Tests for :mod:`basstler.packaging.release`: reading the files a build wrote.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import tarfile
|
|
8
|
+
import zipfile
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
from basstler.packaging.release import (
|
|
12
|
+
BuiltRelease,
|
|
13
|
+
ReleaseFile,
|
|
14
|
+
SourceDistribution,
|
|
15
|
+
PythonWheel,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
# %% the built files
|
|
19
|
+
|
|
20
|
+
WHEEL_METADATA = (
|
|
21
|
+
"Name: sample\nRequires-Dist: basstler-core==1.2.3\nRequires-Dist: pyyaml>=6\n"
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def write_wheel(directory: Path) -> Path:
|
|
26
|
+
"""
|
|
27
|
+
:param directory: Where to write.
|
|
28
|
+
:return: A wheel of ``basstler-sample`` 1.2.3 carrying a licence and its metadata.
|
|
29
|
+
"""
|
|
30
|
+
path = directory / "basstler_sample-1.2.3-py3-none-any.whl"
|
|
31
|
+
with zipfile.ZipFile(path, "w") as archive:
|
|
32
|
+
archive.writestr("basstler_sample-1.2.3.dist-info/METADATA", WHEEL_METADATA)
|
|
33
|
+
archive.writestr("basstler_sample-1.2.3.dist-info/licenses/LICENSE", "licence")
|
|
34
|
+
return path
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def test_a_wheel_reads_its_name_version_and_requirements(tmp_path: Path):
|
|
38
|
+
"""
|
|
39
|
+
The wheel's own name gives distribution and version; its metadata the requirements.
|
|
40
|
+
"""
|
|
41
|
+
wheel = PythonWheel(write_wheel(tmp_path))
|
|
42
|
+
|
|
43
|
+
assert wheel.distribution_name == "basstler-sample"
|
|
44
|
+
assert wheel.version == "1.2.3"
|
|
45
|
+
assert [str(requirement) for requirement in wheel.requirements] == [
|
|
46
|
+
"basstler-core==1.2.3",
|
|
47
|
+
"pyyaml>=6",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def test_a_wheel_returns_the_licence_file_it_carries(tmp_path: Path):
|
|
52
|
+
"""
|
|
53
|
+
The bytes under ``dist-info/licenses`` come back.
|
|
54
|
+
"""
|
|
55
|
+
wheel = PythonWheel(write_wheel(tmp_path))
|
|
56
|
+
|
|
57
|
+
assert wheel.licence == b"licence"
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def test_a_source_distribution_carries_a_file_only_at_its_root(tmp_path: Path):
|
|
61
|
+
"""
|
|
62
|
+
A file inside the archive but not at its root does not count.
|
|
63
|
+
"""
|
|
64
|
+
root = "basstler_sample-1.2.3"
|
|
65
|
+
path = tmp_path / f"{root}.tar.gz"
|
|
66
|
+
carried = tmp_path / "LICENSE"
|
|
67
|
+
carried.write_text("licence", encoding="utf-8")
|
|
68
|
+
with tarfile.open(path, "w:gz") as archive:
|
|
69
|
+
archive.add(carried, arcname=f"{root}/{ReleaseFile.LICENSE}")
|
|
70
|
+
archive.add(carried, arcname=f"{root}/inner/{ReleaseFile.NOTICE}")
|
|
71
|
+
|
|
72
|
+
source = SourceDistribution(path)
|
|
73
|
+
|
|
74
|
+
assert source.distribution_name == "basstler-sample"
|
|
75
|
+
assert source.carries_file_at_root(ReleaseFile.LICENSE)
|
|
76
|
+
assert not source.carries_file_at_root(ReleaseFile.NOTICE)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def test_a_built_release_lists_both_kinds_by_distribution(tmp_path: Path):
|
|
80
|
+
"""
|
|
81
|
+
Wheels and source distributions are each found by the distribution they are of.
|
|
82
|
+
"""
|
|
83
|
+
write_wheel(tmp_path)
|
|
84
|
+
(tmp_path / "basstler_sample-1.2.3.tar.gz").write_bytes(b"")
|
|
85
|
+
|
|
86
|
+
release = BuiltRelease(tmp_path)
|
|
87
|
+
|
|
88
|
+
assert set(release.wheels_by_distribution_name) == {"basstler-sample"}
|
|
89
|
+
assert set(release.source_distributions_by_distribution_name) == {"basstler-sample"}
|