gorgeous-winter-99296
10/08/2022, 5:13 PMUnionRules
only for @goal_rule? I'm investigating using them to route a "build" request in my OCI plugin such that ImageBundleRequest
is either translated into a Build...
or Pull...
variant. However; that doesn't seem to work correctly, complaining that my union subtype isn't created by a rule or in-place. Which is true - it's never mentioned explicitly.fast-nail-55400
10/08/2022, 5:37 PM@union
decorator.fast-nail-55400
10/08/2022, 5:37 PMfast-nail-55400
10/08/2022, 5:38 PMUnionRule
to declare implementations of the union.gorgeous-winter-99296
10/08/2022, 5:38 PMgorgeous-winter-99296
10/08/2022, 5:47 PMgorgeous-winter-99296
10/08/2022, 5:51 PMNo installed rules return the type BuildImageBundleRequest, and it was not provided by potential callers of @rule(backends.oci.util_rules.build_image_bundle:51:build_oci_bundle_package(BuildImageBundleRequest, UmociTool) -> FallibleImageBundle, gets=[Get(Targets, UnparsedAddressInputs), Get(DownloadedExternalTool, ExternalToolRequest), Get(Targets, DependenciesRequest), Get(FieldSetsPerTarget, FieldSetsPerTargetRequest), Get(Digest, MergeDigests), Get(FallibleProcessResult, Process)]).
And this is how I map them - I've tried a bunch of variations here, with a raw targets, etc...
@rule
def ibr_to_fibr(
request: ImageBundleRequest, union_membership: UnionMembership
) -> FallibleImageBundleRequest:
tgt = request.target
concrete_requests = [
request_type(request_type.field_set_type.create(tgt))
for request_type in union_membership[FallibleImageBundleRequest]
if request_type.field_set_type.is_valid(tgt)
]
if len(concrete_requests) > 1:
raise ValueError(
f"Multiple registered builders from {ImageBundleRequest.__name__} can "
f"build target {tgt.name}. It is ambiguous which implementation to "
f"use.\n\n"
f"Possible implementations:\n\n"
f"{bullet_list(sorted(generator.__name__ for generator in concrete_requests))}"
)
if not concrete_requests:
return None
first_concrete = concrete_requests[0]
return first_concrete(tgt)
fast-nail-55400
10/08/2022, 6:01 PMfast-nail-55400
10/08/2022, 6:04 PMNone
, the engine expects the rule to return the declared type. you should probably just raise an exception there just like the >1
casefast-nail-55400
10/08/2022, 6:05 PMgorgeous-winter-99296
10/08/2022, 6:05 PMpants list ::
. One sec and I'll push the very WIP code.gorgeous-winter-99296
10/08/2022, 6:10 PMutil_rules
gorgeous-winter-99296
10/08/2022, 6:10 PMfast-nail-55400
10/08/2022, 6:14 PMBuildImageBundleRequest
needs to subclass the union base type.fast-nail-55400
10/08/2022, 6:17 PM@union
(https://github.com/tgolsson/pants-backend-oci/blob/20a2e5fa1109e2e0880ee619ee6fae9[…]2ba35e0e0/pants-plugins/backends/oci/util_rules/image_bundle.py)fast-nail-55400
10/08/2022, 6:18 PMfast-nail-55400
10/08/2022, 6:20 PMgorgeous-winter-99296
10/08/2022, 6:21 PMgorgeous-winter-99296
10/08/2022, 6:22 PMfast-nail-55400
10/08/2022, 6:24 PMfast-nail-55400
10/08/2022, 6:25 PMfast-nail-55400
10/08/2022, 6:26 PMfast-nail-55400
10/08/2022, 6:30 PMfast-nail-55400
10/08/2022, 6:30 PMGoCodegenBuildRequest
, the rules for each union impl produce a BuildGoPackageRequest
which is not a union and contains all information necessary to build a Go packagefast-nail-55400
10/08/2022, 6:31 PMFallibleImageBundleRequest
is marked as a unionfast-nail-55400
10/08/2022, 6:33 PMgorgeous-winter-99296
10/08/2022, 7:40 PMgorgeous-winter-99296
10/08/2022, 7:41 PMfast-nail-55400
10/08/2022, 7:49 PMDigest
represents a filesystem tree, can an image be represented by some value during processing? maybe the sha-256 of the intermediate image.fast-nail-55400
10/08/2022, 7:51 PMgorgeous-winter-99296
10/08/2022, 7:52 PMgorgeous-winter-99296
10/08/2022, 7:52 PMgorgeous-winter-99296
10/08/2022, 7:54 PMfast-nail-55400
10/08/2022, 7:57 PMImageHandle | None
as the type, then the base steps just either ignore the prior image handle or raise an exception that they were invoked incorrectlyfast-nail-55400
10/08/2022, 7:58 PMfast-nail-55400
10/08/2022, 8:00 PMfast-nail-55400
10/08/2022, 8:01 PMImageTransformer
fast-nail-55400
10/08/2022, 8:04 PMImageTransformer
to use to get the previous imagefast-nail-55400
10/08/2022, 8:05 PMImageTransformer
would run an await Get(ImageStepApplication, ImageTransformer, request.prior_step_transformer_class(request.prior_step))
fast-nail-55400
10/08/2022, 8:06 PMfast-nail-55400
10/08/2022, 8:07 PMfast-nail-55400
10/08/2022, 8:08 PMgorgeous-winter-99296
10/08/2022, 8:08 PMrequest.prior_step_transformer_class(request.prior_step)
would be creating the union-variant that I'm currently trying to create with a rule?gorgeous-winter-99296
10/08/2022, 8:09 PMfast-nail-55400
10/08/2022, 8:11 PMfast-nail-55400
10/08/2022, 8:12 PMfast-nail-55400
10/08/2022, 8:12 PMflatMap
on a Scala Future
just records the operation but doesn't actually apply it until the base Future
resolvesfast-nail-55400
10/08/2022, 8:13 PMfast-nail-55400
10/08/2022, 8:15 PMBuildGoPackageTargetRequest
to invoke the builder logic which then constructs a tree of FallibleBuildGoPackageRequest
instances which just record what builds will happen.fast-nail-55400
10/08/2022, 8:15 PMFallibleBuildGoPackageRequest
for the root of the tree into a BuiltGoPackage
fast-nail-55400
10/08/2022, 8:16 PMfast-nail-55400
10/08/2022, 8:16 PMBuildGoPackageTargetRequest
just hard-codes the 2 or 3 cases it needs to convertfast-nail-55400
10/08/2022, 8:17 PMgorgeous-winter-99296
10/08/2022, 9:52 PMgorgeous-winter-99296
10/08/2022, 10:34 PM-ltrace
gave me a graphviz view to see what it was trying to resolve, so I knew where to start pulling. Now it at least moves forward.fast-nail-55400
10/08/2022, 10:37 PM