umf-access 0.1.0.dev8__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.
- umf_access/__init__.py +109 -0
- umf_access/adoption.py +41 -0
- umf_access/build/__init__.py +2 -0
- umf_access/build/approximate.py +34 -0
- umf_access/build/catalog.py +1626 -0
- umf_access/build/commands.py +394 -0
- umf_access/build/pg_privileges.py +1544 -0
- umf_access/build/privileges.py +134 -0
- umf_access/build/search.py +365 -0
- umf_access/build/unity_search.py +104 -0
- umf_access/bulk.py +227 -0
- umf_access/canonical.py +23 -0
- umf_access/capture.py +410 -0
- umf_access/catalog.py +325 -0
- umf_access/codec_support.py +427 -0
- umf_access/commands.py +93 -0
- umf_access/delta_read.py +758 -0
- umf_access/dsl/__init__.py +148 -0
- umf_access/dsl/_context.py +36 -0
- umf_access/dsl/_expressions.py +625 -0
- umf_access/dsl/_joined.py +4 -0
- umf_access/dsl/_nodes.py +207 -0
- umf_access/dsl/_query.py +5559 -0
- umf_access/dsl/_selection.py +143 -0
- umf_access/dsl/navigation.py +302 -0
- umf_access/dsl/render.py +516 -0
- umf_access/dsl/search.py +343 -0
- umf_access/engine_catalog.py +563 -0
- umf_access/generated_core.py +5 -0
- umf_access/lifecycle/__init__.py +46 -0
- umf_access/lifecycle/_darwin_process_observer.c +306 -0
- umf_access/lifecycle/approval.py +366 -0
- umf_access/lifecycle/backfills.py +79 -0
- umf_access/lifecycle/catalog.py +289 -0
- umf_access/lifecycle/cli.py +231 -0
- umf_access/lifecycle/concurrent.py +196 -0
- umf_access/lifecycle/conversion_policy.py +188 -0
- umf_access/lifecycle/correspondence.py +203 -0
- umf_access/lifecycle/generation_authority_bootstrap.py +1491 -0
- umf_access/lifecycle/generation_authority_session.py +125 -0
- umf_access/lifecycle/generation_enrollment_authority.py +1108 -0
- umf_access/lifecycle/generation_enrollment_ledger.py +698 -0
- umf_access/lifecycle/generation_ingress.py +185 -0
- umf_access/lifecycle/generation_root_registry.py +138 -0
- umf_access/lifecycle/head.py +250 -0
- umf_access/lifecycle/head_view.py +81 -0
- umf_access/lifecycle/host.py +1183 -0
- umf_access/lifecycle/ingress_custody.py +750 -0
- umf_access/lifecycle/ingress_local_postgres.py +7990 -0
- umf_access/lifecycle/ingress_store.py +1488 -0
- umf_access/lifecycle/ledger.py +276 -0
- umf_access/lifecycle/ledger_schema.py +116 -0
- umf_access/lifecycle/mixed.py +593 -0
- umf_access/lifecycle/outcome_schema.py +136 -0
- umf_access/lifecycle/owner_approval_core.py +1810 -0
- umf_access/lifecycle/owner_authority.py +472 -0
- umf_access/lifecycle/owner_bootstrap.py +2077 -0
- umf_access/lifecycle/owner_wire.py +161 -0
- umf_access/lifecycle/phase_fence.py +52 -0
- umf_access/lifecycle/phase_policy.py +422 -0
- umf_access/lifecycle/privileges.py +145 -0
- umf_access/lifecycle/probe.py +39 -0
- umf_access/lifecycle/progress.py +497 -0
- umf_access/lifecycle/roles.py +96 -0
- umf_access/lifecycle/row_originals.py +1712 -0
- umf_access/lifecycle/row_originals_creation.py +759 -0
- umf_access/lifecycle/row_originals_receipt.py +413 -0
- umf_access/lifecycle/seeds.py +99 -0
- umf_access/lifecycle/sql_containment.py +358 -0
- umf_access/lifecycle/sql_containment_cli.py +33 -0
- umf_access/lifecycle/sql_containment_parser.py +20 -0
- umf_access/lifecycle/supervisor_journal_codec.py +1251 -0
- umf_access/lifecycle/table_boundary.py +22 -0
- umf_access/lifecycle/target_custody_codec.py +788 -0
- umf_access/lifecycle/witness.py +72 -0
- umf_access/managed_actions.py +271 -0
- umf_access/managed_bulk.py +353 -0
- umf_access/managed_delta.py +150 -0
- umf_access/managed_support.py +166 -0
- umf_access/manifest_commands.py +278 -0
- umf_access/native_actions.py +1007 -0
- umf_access/native_program.py +570 -0
- umf_access/pages.py +125 -0
- umf_access/postgres_bulk.py +509 -0
- umf_access/postgres_read.py +1230 -0
- umf_access/postgres_search.py +639 -0
- umf_access/protocols.py +665 -0
- umf_access/py.typed +0 -0
- umf_access/related_keys.py +233 -0
- umf_access/reviewed.py +706 -0
- umf_access/search_catalog.py +122 -0
- umf_access/targets.py +312 -0
- umf_access/types.py +220 -0
- umf_access/unified/__init__.py +187 -0
- umf_access/unified/_binding.py +654 -0
- umf_access/unified/head_session.py +144 -0
- umf_access/unified/native_binding.py +143 -0
- umf_access/unified/operation_values.py +173 -0
- umf_access/unified/outcome_values.py +76 -0
- umf_access/unified/session_async.py +161 -0
- umf_access/unified/session_binding.py +108 -0
- umf_access/unified/session_policy.py +152 -0
- umf_access/unified/session_psycopg2.py +70 -0
- umf_access/unified/session_sqlalchemy.py +161 -0
- umf_access/unified/session_sync.py +148 -0
- umf_access/unified/table_reads.py +314 -0
- umf_access/unified/table_writes.py +193 -0
- umf_access/unity_search.py +312 -0
- umf_access/values.py +280 -0
- umf_access/verification.py +64 -0
- umf_access-0.1.0.dev8.dist-info/METADATA +15 -0
- umf_access-0.1.0.dev8.dist-info/RECORD +117 -0
- umf_access-0.1.0.dev8.dist-info/WHEEL +4 -0
- umf_access-0.1.0.dev8.dist-info/entry_points.txt +4 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-APACHE +201 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE-MIT +21 -0
- umf_access-0.1.0.dev8.dist-info/licenses/LICENSE.md +239 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
# SPDX-License-Identifier: MIT OR Apache-2.0
|
|
2
|
+
"""Captured command -> original Weft native-bulk request, build only."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
from dataclasses import replace
|
|
7
|
+
from decimal import Decimal
|
|
8
|
+
from types import UnionType
|
|
9
|
+
from typing import Any, Union, cast, get_args, get_origin
|
|
10
|
+
|
|
11
|
+
from ..capture import CapturedDeclaration, CapturedVariant, ProjectionRef
|
|
12
|
+
from ..dsl import FieldRef, Node, Ordering, render_logical
|
|
13
|
+
from ..manifest_commands import ManifestCompilationError, ManifestProgram
|
|
14
|
+
from ..native_program import NativeProgram
|
|
15
|
+
from ..reviewed import ReadBuildError, parameter_signature
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class CommandBuildError(ValueError):
|
|
19
|
+
pass
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _carrier(annotation: Any) -> tuple[str, bool]:
|
|
23
|
+
args = (
|
|
24
|
+
get_args(annotation)
|
|
25
|
+
if get_origin(annotation) in (Union, UnionType)
|
|
26
|
+
else (annotation,)
|
|
27
|
+
)
|
|
28
|
+
nullable = type(None) in args
|
|
29
|
+
scalar = [v for v in args if v is not type(None)]
|
|
30
|
+
if len(scalar) != 1 or scalar[0] not in (str, bool, int, Decimal):
|
|
31
|
+
raise CommandBuildError("unsupported native bulk parameter carrier")
|
|
32
|
+
return {str: "string", bool: "boolean", int: "integer", Decimal: "decimal"}[
|
|
33
|
+
scalar[0]
|
|
34
|
+
], nullable
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def _literal(node: Node) -> Any:
|
|
38
|
+
if node.op == "null":
|
|
39
|
+
return None
|
|
40
|
+
key = {
|
|
41
|
+
"str": "string",
|
|
42
|
+
"bool": "boolean",
|
|
43
|
+
"int": "integerToken",
|
|
44
|
+
"decimal": "decimalToken",
|
|
45
|
+
}.get(node.op)
|
|
46
|
+
if key is None:
|
|
47
|
+
raise CommandBuildError(
|
|
48
|
+
"native command assignment needs an exact literal or parameter"
|
|
49
|
+
)
|
|
50
|
+
value = node.args[0]
|
|
51
|
+
return {key: str(value) if node.op in ("int", "decimal") else value}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def compile_command(
|
|
55
|
+
compiler: Any,
|
|
56
|
+
declaration: CapturedDeclaration,
|
|
57
|
+
variant: CapturedVariant,
|
|
58
|
+
record: Any,
|
|
59
|
+
target: dict[str, Any],
|
|
60
|
+
action_request: dict[str, Any],
|
|
61
|
+
input_digest: str,
|
|
62
|
+
parameters: dict[str, Any],
|
|
63
|
+
) -> NativeProgram:
|
|
64
|
+
filters = cast(tuple[Node, ...], variant.node.args[1])
|
|
65
|
+
if variant.node.op != "update" or any(step.op != "filter" for step in filters):
|
|
66
|
+
raise CommandBuildError("native bulk requires a filtered base-table UPDATE")
|
|
67
|
+
import json
|
|
68
|
+
|
|
69
|
+
original = json.loads(action_request["binding"]["modelJson"])
|
|
70
|
+
action = original
|
|
71
|
+
for component in action_request["source"]["actionPointer"].strip("/").split("/"):
|
|
72
|
+
action = (
|
|
73
|
+
action[int(component)] if isinstance(action, list) else action[component]
|
|
74
|
+
)
|
|
75
|
+
effects = action["binding"].get("effects", [])
|
|
76
|
+
if len(effects) != 1 or effects[0]["kind"] != "set":
|
|
77
|
+
raise CommandBuildError(
|
|
78
|
+
"WEFT_BLOCKED: selected command requires one original SET effect"
|
|
79
|
+
)
|
|
80
|
+
assignments = cast(tuple[tuple[FieldRef, Node], ...], variant.node.args[2])
|
|
81
|
+
captured = {
|
|
82
|
+
(field.field_module or field.module, field.field): node
|
|
83
|
+
for field, node in assignments
|
|
84
|
+
}
|
|
85
|
+
expected = {
|
|
86
|
+
(v["field"]["module"], v["field"]["element"]): v["value"]
|
|
87
|
+
for v in effects[0]["values"]
|
|
88
|
+
}
|
|
89
|
+
if set(captured) != set(expected):
|
|
90
|
+
raise CommandBuildError(
|
|
91
|
+
"command assignment inventory differs from original action"
|
|
92
|
+
)
|
|
93
|
+
action_inputs = {}
|
|
94
|
+
for identity, node in captured.items():
|
|
95
|
+
source = expected[identity]
|
|
96
|
+
if "literal" in source:
|
|
97
|
+
if _literal(node) != source["literal"]:
|
|
98
|
+
raise CommandBuildError(
|
|
99
|
+
"command literal differs from original action recipe"
|
|
100
|
+
)
|
|
101
|
+
elif "parameter" in source:
|
|
102
|
+
if node.op != "param":
|
|
103
|
+
raise CommandBuildError(
|
|
104
|
+
"action input assignment requires a declared command parameter"
|
|
105
|
+
)
|
|
106
|
+
action_inputs[source["parameter"]] = node.args[0]
|
|
107
|
+
else:
|
|
108
|
+
raise CommandBuildError("unknown action assignment meaning")
|
|
109
|
+
key_fields = tuple(record.objects.ref.key)
|
|
110
|
+
assigned_fields = tuple(field for field, _ in assignments)
|
|
111
|
+
fields = key_fields + tuple(f for f in assigned_fields if f not in key_fields)
|
|
112
|
+
names = tuple(f.logical_name for f in fields)
|
|
113
|
+
if any(name is None for name in names):
|
|
114
|
+
raise CommandBuildError("bulk source Field logical names required")
|
|
115
|
+
steps = filters + (
|
|
116
|
+
Node("order", tuple(Ordering(f, "ASC") for f in key_fields)),
|
|
117
|
+
Node("into", (ProjectionRef("", "", fields, names),)),
|
|
118
|
+
)
|
|
119
|
+
selected = replace(variant, node=Node("all", (variant.node.args[0], steps)))
|
|
120
|
+
sql = render_logical(selected, binding=target["binding"], owner_bound=True)
|
|
121
|
+
used = set()
|
|
122
|
+
|
|
123
|
+
def visit(value: Any) -> None:
|
|
124
|
+
if isinstance(value, Node):
|
|
125
|
+
if value.op == "param":
|
|
126
|
+
used.add(value.args[0])
|
|
127
|
+
elif value.op == "key_param":
|
|
128
|
+
used.update(
|
|
129
|
+
cast(str, value.args[0]) + "__" + c
|
|
130
|
+
for c in cast(tuple[str, ...], value.args[1])
|
|
131
|
+
)
|
|
132
|
+
for child in value.args:
|
|
133
|
+
visit(child)
|
|
134
|
+
elif isinstance(value, tuple):
|
|
135
|
+
for child in value:
|
|
136
|
+
visit(child)
|
|
137
|
+
|
|
138
|
+
for step in filters:
|
|
139
|
+
visit(step)
|
|
140
|
+
params = []
|
|
141
|
+
for name, (annotation, _) in parameters.items():
|
|
142
|
+
# Selection membership may use the original bounded-list descriptor.
|
|
143
|
+
# Assignment inputs retain the scalar action/Field contract.
|
|
144
|
+
if name in action_inputs.values():
|
|
145
|
+
_carrier(annotation)
|
|
146
|
+
try:
|
|
147
|
+
signature = parameter_signature(annotation)
|
|
148
|
+
except ReadBuildError as error:
|
|
149
|
+
raise CommandBuildError(str(error)) from error
|
|
150
|
+
params.append({"name": name, **signature})
|
|
151
|
+
bound = target.get("maxItems")
|
|
152
|
+
if type(bound) is not int or not 1 <= bound <= 999:
|
|
153
|
+
raise CommandBuildError("explicit native maxItems in 1..999 required")
|
|
154
|
+
request = {
|
|
155
|
+
"version": "weft.native-bulk/0.1",
|
|
156
|
+
"action": action_request,
|
|
157
|
+
"selection": {
|
|
158
|
+
"version": "weft.raw-read/0.1",
|
|
159
|
+
"target": action_request["target"],
|
|
160
|
+
"sql": sql,
|
|
161
|
+
"binding": target["binding"],
|
|
162
|
+
"parameters": [p for p in params if p["name"] in used],
|
|
163
|
+
"rowCap": bound + 1,
|
|
164
|
+
},
|
|
165
|
+
"maxItems": bound,
|
|
166
|
+
"actionInputs": action_inputs,
|
|
167
|
+
"parameters": params,
|
|
168
|
+
}
|
|
169
|
+
return NativeProgram.build(compiler, request, bundle_input_digest=input_digest)
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def compile_manifest_command(compiler: Any, variant: CapturedVariant, target: dict[str, Any], reference: Any, configuration: Any, input_digest: str, parameters: dict[str, Any]) -> ManifestProgram:
|
|
173
|
+
"""Forward exact captured source to the original portable mutation compiler."""
|
|
174
|
+
from ..manifest_commands import ManifestBuildError
|
|
175
|
+
|
|
176
|
+
if type(configuration) is not dict or set(configuration) != {"configuration", "request"}:
|
|
177
|
+
raise CommandBuildError("MANIFEST_ORIGINAL_CONFIGURATION_REQUIRED")
|
|
178
|
+
registry, request = configuration["configuration"], configuration["request"]
|
|
179
|
+
if type(registry) is not str or type(request) is not dict:
|
|
180
|
+
raise CommandBuildError("MANIFEST_ORIGINAL_CONFIGURATION_REQUIRED")
|
|
181
|
+
source = reference.source
|
|
182
|
+
record = variant.node.args[0]
|
|
183
|
+
action = {"identity": {"module": source.module, "action": source.action},
|
|
184
|
+
"documentSha256": source.document_sha256,
|
|
185
|
+
"invocation": {"id": source.invocation_id, "version": source.invocation_version}}
|
|
186
|
+
model = request.get("model")
|
|
187
|
+
if (request.get("action") != action
|
|
188
|
+
or request.get("target") != {"module": record.module, "element": record.element, "key": record.key_id}
|
|
189
|
+
or request.get("sql") != render_logical(variant, binding=target["binding"], owner_bound=True)
|
|
190
|
+
or type(model) is not dict or model.get("utf8") != target["binding"].get("modelJson")
|
|
191
|
+
or model.get("sha256") != source.document_sha256):
|
|
192
|
+
raise CommandBuildError("MANIFEST_CAPTURED_SOURCE_DIFFERS")
|
|
193
|
+
witnesses = request.get("parameters")
|
|
194
|
+
if type(witnesses) is not dict or set(witnesses) != set(parameters):
|
|
195
|
+
raise CommandBuildError("MANIFEST_PARAMETER_INVENTORY_DIFFERS")
|
|
196
|
+
for name, (annotation, _) in parameters.items():
|
|
197
|
+
carrier, nullable = _carrier(annotation)
|
|
198
|
+
tag = {"string": "string", "boolean": "boolean", "integer": "integerToken"}.get(carrier)
|
|
199
|
+
value = witnesses[name]
|
|
200
|
+
if nullable or tag is None or type(value) is not dict or set(value) != {tag}:
|
|
201
|
+
raise CommandBuildError("MANIFEST_PARAMETER_PROFILE_UNSUPPORTED")
|
|
202
|
+
# Only original compiler input data enters this configuration. The original
|
|
203
|
+
# registry closes every action registration and refuses executable backends.
|
|
204
|
+
try:
|
|
205
|
+
program = ManifestProgram.build(compiler, registry, request, bundle_input_digest=input_digest)
|
|
206
|
+
program.bind(reference)
|
|
207
|
+
return program
|
|
208
|
+
except ManifestCompilationError:
|
|
209
|
+
raise
|
|
210
|
+
except (ManifestBuildError, ValueError) as error:
|
|
211
|
+
raise CommandBuildError(str(error)) from error
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
def emit_command(
|
|
215
|
+
compiler: Any,
|
|
216
|
+
declaration: CapturedDeclaration,
|
|
217
|
+
record: Any,
|
|
218
|
+
targets: list[dict[str, Any]],
|
|
219
|
+
action_requests: dict[Any, Any],
|
|
220
|
+
action_refs: list[Any],
|
|
221
|
+
manifest: dict[str, Any],
|
|
222
|
+
number: int,
|
|
223
|
+
name: str,
|
|
224
|
+
package: str,
|
|
225
|
+
type_name: Any,
|
|
226
|
+
) -> tuple[list[str], list[dict[str, Any]]]:
|
|
227
|
+
from umf_access.types import MISSING
|
|
228
|
+
|
|
229
|
+
from ..types import ActionSource, StrictModel
|
|
230
|
+
references=[a for a in action_refs if isinstance(declaration.action,ActionSource) and a.source==declaration.action]
|
|
231
|
+
if len(references)!=1:raise CommandBuildError('command action source was not uniquely selected at stage one')
|
|
232
|
+
reference=references[0]
|
|
233
|
+
symbol=next(s['symbol'] for s in manifest['symbols'] if s['role']=='action-ref' and s['pointer']==reference.source.action_pointer)
|
|
234
|
+
manifest_target = any(t["kind"] == "truss" for t in targets)
|
|
235
|
+
mixed_target = manifest_target and any(t["kind"] != "truss" for t in targets)
|
|
236
|
+
signature=[];arguments=[];names=[];lines=[];entries=[];variants=[]
|
|
237
|
+
if manifest_target:
|
|
238
|
+
lines.append("from umf_access.manifest_commands import ManifestProgram, ManifestCommandVariant, ManifestCommandPlan, MixedManifestCommandPlan, ManifestBulkTarget, AsyncManifestBulkTarget")
|
|
239
|
+
lines.append("from .actions import *")
|
|
240
|
+
for parameter in declaration.parameters:
|
|
241
|
+
names.append(parameter.name)
|
|
242
|
+
signature.append(
|
|
243
|
+
parameter.name
|
|
244
|
+
+ ": "
|
|
245
|
+
+ type_name(parameter.carrier, package)
|
|
246
|
+
+ (" = MISSING" if parameter.optional else "")
|
|
247
|
+
)
|
|
248
|
+
members = (
|
|
249
|
+
get_args(parameter.carrier)
|
|
250
|
+
if get_origin(parameter.carrier) in (Union, UnionType)
|
|
251
|
+
else (parameter.carrier,)
|
|
252
|
+
)
|
|
253
|
+
remaining = [m for m in members if m is not MISSING]
|
|
254
|
+
annotation = remaining[0]
|
|
255
|
+
for member in remaining[1:]:
|
|
256
|
+
annotation = annotation | member
|
|
257
|
+
key = next(
|
|
258
|
+
(m for m in members if isinstance(m, type) and issubclass(m, StrictModel)),
|
|
259
|
+
None,
|
|
260
|
+
)
|
|
261
|
+
arguments.append(
|
|
262
|
+
"Argument("
|
|
263
|
+
+ repr(parameter.name)
|
|
264
|
+
+ ", "
|
|
265
|
+
+ type_name(annotation, package)
|
|
266
|
+
+ ", "
|
|
267
|
+
+ repr(parameter.optional)
|
|
268
|
+
+ ", "
|
|
269
|
+
+ (key.__name__ if key else "None")
|
|
270
|
+
+ ")"
|
|
271
|
+
)
|
|
272
|
+
for _vi, variant in enumerate(declaration.variants):
|
|
273
|
+
parameters = {}
|
|
274
|
+
paths: list[tuple[str, str, str | None]] = []
|
|
275
|
+
for parameter in declaration.parameters:
|
|
276
|
+
if parameter.optional and parameter.name not in variant.presence:
|
|
277
|
+
continue
|
|
278
|
+
members = (
|
|
279
|
+
get_args(parameter.carrier)
|
|
280
|
+
if get_origin(parameter.carrier) in (Union, UnionType)
|
|
281
|
+
else (parameter.carrier,)
|
|
282
|
+
)
|
|
283
|
+
remaining = [m for m in members if m is not MISSING]
|
|
284
|
+
annotation = remaining[0]
|
|
285
|
+
for member in remaining[1:]:
|
|
286
|
+
annotation = annotation | member
|
|
287
|
+
if parameter.key_components:
|
|
288
|
+
key = next(
|
|
289
|
+
m
|
|
290
|
+
for m in remaining
|
|
291
|
+
if isinstance(m, type) and issubclass(m, StrictModel)
|
|
292
|
+
)
|
|
293
|
+
for component in parameter.key_components:
|
|
294
|
+
flat = parameter.name + "__" + component
|
|
295
|
+
parameters[flat] = (key.model_fields[component].annotation, ...)
|
|
296
|
+
paths.append((flat, parameter.name, component))
|
|
297
|
+
else:
|
|
298
|
+
parameters[parameter.name] = (annotation, ...)
|
|
299
|
+
paths.append((parameter.name, parameter.name, None))
|
|
300
|
+
for target in targets:
|
|
301
|
+
is_manifest = target["kind"] == "truss"
|
|
302
|
+
if is_manifest:
|
|
303
|
+
configurations = target.get("manifestCommands", {})
|
|
304
|
+
if type(configurations) is not dict:
|
|
305
|
+
raise CommandBuildError("MANIFEST_ORIGINAL_CONFIGURATION_REQUIRED")
|
|
306
|
+
program = compile_manifest_command(
|
|
307
|
+
compiler, variant, target, reference,
|
|
308
|
+
configurations.get(name + ":" + str(_vi)),
|
|
309
|
+
manifest["inputDigest"], parameters,
|
|
310
|
+
)
|
|
311
|
+
else:
|
|
312
|
+
request = action_requests[(target["id"], reference.module, reference.action)]
|
|
313
|
+
program = compile_command(
|
|
314
|
+
compiler, declaration, variant, record, target, request,
|
|
315
|
+
manifest["inputDigest"], parameters,
|
|
316
|
+
)
|
|
317
|
+
import hashlib
|
|
318
|
+
import json
|
|
319
|
+
|
|
320
|
+
digest = hashlib.sha256(
|
|
321
|
+
json.dumps(
|
|
322
|
+
target["binding"],
|
|
323
|
+
ensure_ascii=False,
|
|
324
|
+
sort_keys=True,
|
|
325
|
+
separators=(",", ":"),
|
|
326
|
+
allow_nan=False,
|
|
327
|
+
).encode()
|
|
328
|
+
).hexdigest()
|
|
329
|
+
pin = (
|
|
330
|
+
target["kind"],
|
|
331
|
+
target["backendId"],
|
|
332
|
+
target["backendVersion"],
|
|
333
|
+
target["targetProfile"],
|
|
334
|
+
digest,
|
|
335
|
+
tuple(
|
|
336
|
+
(p["name"], tuple(str(v) for v in p["versions"]))
|
|
337
|
+
for p in target["platform"]
|
|
338
|
+
),
|
|
339
|
+
)
|
|
340
|
+
if is_manifest:
|
|
341
|
+
retained = f"ManifestProgram({program.configuration_json!r}, {program.request_json!r}, {program.response_json!r}, {program.bundle_input_digest!r})"
|
|
342
|
+
variants.append(f"ManifestCommandVariant({variant.presence!r}, TargetPin{pin!r}, {retained}, {symbol}, {tuple(paths)!r})")
|
|
343
|
+
artifact = json.loads(program.response_json)
|
|
344
|
+
else:
|
|
345
|
+
variants.append(
|
|
346
|
+
f"CommandVariant({variant.presence!r}, TargetPin{pin!r}, NativeProgram({program.original_json!r}, {program.statements_json!r}, {program.bundle_input_digest!r}), {symbol}, {tuple(paths)!r})"
|
|
347
|
+
)
|
|
348
|
+
artifact = json.loads(program.original_json)
|
|
349
|
+
entries.append(
|
|
350
|
+
{
|
|
351
|
+
"name": name,
|
|
352
|
+
"kind": "command",
|
|
353
|
+
"targetId": target["id"],
|
|
354
|
+
"presence": variant.presence,
|
|
355
|
+
"pin": pin,
|
|
356
|
+
"artifact": artifact,
|
|
357
|
+
"parameters": paths,
|
|
358
|
+
}
|
|
359
|
+
)
|
|
360
|
+
plan = f"_C{number}"
|
|
361
|
+
plan_class = "MixedManifestCommandPlan" if mixed_target else "ManifestCommandPlan" if manifest_target else "CommandPlan"
|
|
362
|
+
sync_target = "ManifestBulkTarget" if manifest_target else "BulkTarget"
|
|
363
|
+
async_target = "AsyncManifestBulkTarget" if manifest_target else "AsyncBulkTarget"
|
|
364
|
+
sync_type = "BulkTarget[_PlanT] | ManifestBulkTarget[_PlanT]" if mixed_target else sync_target + "[_PlanT]"
|
|
365
|
+
async_type = "AsyncBulkTarget[_PlanT] | AsyncManifestBulkTarget[_PlanT]" if mixed_target else async_target + "[_PlanT]"
|
|
366
|
+
implementation_types = "BulkTarget[object] | ManifestBulkTarget[object] | AsyncBulkTarget[object] | AsyncManifestBulkTarget[object]" if mixed_target else sync_target + "[object] | " + async_target + "[object]"
|
|
367
|
+
lines.extend(
|
|
368
|
+
[
|
|
369
|
+
f"{plan} = {plan_class}({name!r}, ("
|
|
370
|
+
+ ", ".join(arguments)
|
|
371
|
+
+ ("," if arguments else "")
|
|
372
|
+
+ "), ("
|
|
373
|
+
+ ", ".join(variants)
|
|
374
|
+
+ ",))",
|
|
375
|
+
"",
|
|
376
|
+
]
|
|
377
|
+
)
|
|
378
|
+
ordered = [s for s in signature if " = MISSING" not in s] + [
|
|
379
|
+
s for s in signature if " = MISSING" in s
|
|
380
|
+
]
|
|
381
|
+
tail = ", *, " + ", ".join(ordered + ["timeout: timedelta | None = None"])
|
|
382
|
+
values = "{" + ", ".join(repr(n) + ": " + n for n in names) + "}"
|
|
383
|
+
lines.extend(
|
|
384
|
+
[
|
|
385
|
+
"@overload",
|
|
386
|
+
f"def {name}(target: {async_type}{tail}) -> Awaitable[_PlanT]: ...",
|
|
387
|
+
"@overload",
|
|
388
|
+
f"def {name}(target: {sync_type}{tail}) -> _PlanT: ...",
|
|
389
|
+
f"def {name}(target: {implementation_types}{tail}) -> object:",
|
|
390
|
+
f" return {plan}.run(target, {values}, timeout=timeout)",
|
|
391
|
+
"",
|
|
392
|
+
]
|
|
393
|
+
)
|
|
394
|
+
return lines, entries
|