I'm having trouble just getting off the ground whe...
# plugins
i
I'm having trouble just getting off the ground when writing my plugin. Generally I'm trying to install a Go tool and then utilize it to generate some code. However I can't really get past even downloading the sources. More details in the thread.
Here's the code I currently have:
Copy code
class KbGenerateTarget(Target):
  alias = 'kube_generate'
  core_fields = ...

def target_types():
  # return [KbGenerateTarget, KbManifestsTarget]
  return [KbGenerateTarget]
Copy code
class KbGenerateSubsystem(GoalSubsystem):
  name = 'kb-generate'

class KbGenerate(Goal):
  subsystem_cls = KbGenerateSubsystem
  # environment_behavior = Goal.EnvironmentBehavior.USES_ENVIRONMENTS
  environment_behavior = Goal.EnvironmentBehavior.LOCAL_ONLY


@goal_rule
def kb_generate(
  console: Console, targets: Targets, platform: Platform,
) -> KbGenerate:
  relevant_targets = [
    tgt for tgt in targets if tgt.has_field(GoPackageSourcesField)
  ]
  console.print_stdout('Relevant targets:')
  for target in relevant_targets:
    console.print_stdout(target.address.spec)

  controller_gen = Get(ControllerGenSetupResponse, Platform, ControllerGenSetupRequest())

  return KbGenerate(exit_code=0)

def rules():
  return collect_rules()
Copy code
CONTROLLER_GEN_GO_MOD = ...
CONTROLLER_GEN_GO_SUM = ...

@rule
async def setup_controller_gen(
  platform: Platform,
) -> ControllerGenSetupResponse:
  go_mod_digest = await Get(
    Digest,
    CreateDigest(
      [
        FileContent('go.mod', CONTROLLER_GEN_GO_MOD.encode()),
        FileContent('go.sum', CONTROLLER_GEN_GO_SUM.encode()),
      ]
    ),
  )

  # This fails:
  cg_process = await Get(
    Process,
    GoSdkProcess(
      ['mod', 'download', 'all'],
      input_digest=go_mod_digest,
      output_directories=('gopath',),
      description='Download controller-gen sources.',
      allow_downloads=True,
    ),
  )

  # This never runs
  download_sources_result = await Get(
    ProcessResult,
    Process,
    cg_process,
  )

  # This also fails if the above two commands are removed.
  download_sources_result = await Get(
    ProcessResult,
    GoSdkProcess(
        ['mod', 'download', 'all'],
        input_digest=go_mod_digest,
        output_directories=('gopath',),
        description='Download controller-gen sources.',
        allow_downloads=True,
    ),
  )

def rules():
  return (
    *collect_rules(),
  )
Output:
Copy code
% pants kb-generate .::
04:47:35.73 [INFO] Initializing scheduler...
04:47:35.76 [INFO] Initializing Nailgun pool for 24 processes...
04:47:38.09 [ERROR] Encountered 3 rule graph errors:
  No installed rules return the type Process to satisfy Get(Process, [GoSdkProcess]) for @rule(kubebuilder.controller_gen_rules:196:setup_controller_gen(Platform) -> ControllerGenSetupResponse, gets=[Get(builtins.Digest, [CreateDigest]), Get(Process, [GoSdkProcess])]).
    Ensure that the rule you are expecting to use is installed.
  No source of dependency Get(builtins.Digest, [CreateDigest]) for @rule(kubebuilder.controller_gen_rules:196:setup_controller_gen(Platform) -> ControllerGenSetupResponse, gets=[Get(builtins.Digest, [CreateDigest]), Get(Process, [GoSdkProcess])]). All potential sources were eliminated: []
  No source of dependency Platform for @rule(kubebuilder.controller_gen_rules:196:setup_controller_gen(Platform) -> ControllerGenSetupResponse, gets=[Get(builtins.Digest, [CreateDigest]), Get(Process, [GoSdkProcess])]). All potential sources were eliminated: []
Please let me know if there's anything else I can provide. Thanks in advance for your help!
b
Just guesstimating: You may need to include the extra rules that tell pants how to run a `GoSdkProcess`: https://github.com/pantsbuild/pants/blob/a96cffd5b4ffba2a82de96a488cfdafcbdc67af6/src/python/pants/backend/codegen/protobuf/go/rules.py#L660
i
Ah, that seems like it might be the ticket! I knew it would be simple, but I didn't even have that on my radar.
b
yeah, rule graph errors have very non-obvious solutions!