Trying my hand at writing a plugin to publish thin...
# plugins
a
Trying my hand at writing a plugin to publish things places. I think I 'get' how the rules work. https://github.com/xlevus/pants2-plugins/blob/publish/src/xlvs/pants/publish/publish_subsystem.py#L79 But stuck here. my
requests
looks good
Copy code
[TwinePublishRequest(package_field_set=PythonDistributionFieldSet(address=Address(examples/pypi_repository:example_package), provides=<class 'pants.backend.python.target_types.PythonProvidesField'>(alias='provides', value=<pants.backend.python.macros.python_artifact.PythonArtifact object at 0x7f9ff81a2e80>, default=None)), field_set=TwineFieldSet(address=Address(examples/pypi_repository:example_package)))]
but when I get to
oof
I get:
Copy code
12:32:01.88 [ERROR] Encountered 5 rule graph errors:
  No installed rules return the type PrePublishRequest, and it was not provided by potential callers of @rule(xlvs.pants.publish.publish_subsystem:51:to_publish_request(PrePublishRequest) -> PublishRequest, gets=[Get(BuiltPackage, ArchiveFieldSet), Get(BuiltPackage, PexBinaryFieldSet), Get(BuiltPackage, PythonDistributionFieldSet), Get(BuiltPackage, DockerImageFieldSet)]).
    If that type should be computed by a rule, ensure that that rule is installed.
    If it should be provided by a caller, ensure that it is included in any relevant Query or Get.
  No source of dependency Get(BuiltPackage, ArchiveFieldSet) for @rule(xlvs.pants.publish.publish_subsystem:51:to_publish_request(PrePublishRequest) -> PublishRequest, gets=[Get(BuiltPackage, ArchiveFieldSet), Get(BuiltPackage, PexBinaryFieldSet), Get(BuiltPackage, PythonDistributionFieldSet), Get(BuiltPackage, DockerImageFieldSet)]). All potential sources were eliminated: []
  No source of dependency Get(BuiltPackage, DockerImageFieldSet) for @rule(xlvs.pants.publish.publish_subsystem:51:to_publish_request(PrePublishRequest) -> PublishRequest, gets=[Get(BuiltPackage, ArchiveFieldSet), Get(BuiltPackage, PexBinaryFieldSet), Get(BuiltPackage, PythonDistributionFieldSet), Get(BuiltPackage, DockerImageFieldSet)]). All potential sources were eliminated: []
  No source of dependency Get(BuiltPackage, PexBinaryFieldSet) for @rule(xlvs.pants.publish.publish_subsystem:51:to_publish_request(PrePublishRequest) -> PublishRequest, gets=[Get(BuiltPackage, ArchiveFieldSet), Get(BuiltPackage, PexBinaryFieldSet), Get(BuiltPackage, PythonDistributionFieldSet), Get(BuiltPackage, DockerImageFieldSet)]). All potential sources were eliminated: []
  No source of dependency Get(BuiltPackage, PythonDistributionFieldSet) for @rule(xlvs.pants.publish.publish_subsystem:51:to_publish_request(PrePublishRequest) -> PublishRequest, gets=[Get(BuiltPackage, ArchiveFieldSet), Get(BuiltPackage, PexBinaryFieldSet), Get(BuiltPackage, PythonDistributionFieldSet), Get(BuiltPackage, DockerImageFieldSet)]). All potential sources were eliminated: []
I'm not requesting a
PrePublishRequest
?? I'm doing
Get(PublishRequest, PrePublishRequest, request)
[edit] Solved
f
Is this occurring from a test?
a
no
well kinda im running
Copy code
pants  --no-dynamic-ui publish //examples/pypi_repository::
f
if it had been from a test, I would have suggested a
QueryRule
for the
RuleRunner
used in the test, but sounds like this is a regular Pants run.
sometimes you will need to reference the rules invoked by your plugin in the
rules
method for you module
I suggest
from pants.core.goals import package
and then include
*package.rules()
in your
rules
so:
Copy code
def rules():
  return [
    *package.rules(),
    *collect_rules(),
  ]
so those rules are ensured to be seen by the engine
(I’m just guessing but this has worked for me in the past. Most of the error message lines are referring to generic
package
goal types and rules. So my first thought is for you to make sure those rules are seen by the engine.)
a
nope, no difference. I even removed the Get in
to_publish_request
f
is there any particular reason why your code is doing
publish_request_types = cast(    "Iterable[Type[PrePublishRequest]]", union_membership[PrePublishRequest]    )
instead of
publish_request_types: Iterable[type[PrePublishRequest]] = union_membership[PrePublishRequest]
?
a
ahhh ding
f
the engine inspects the type annotations so maybe that is confusing it?
a
yeah
my
requests
were actually subclasses
f
side note: the engine doesn’t understand subclasses, only the exact type matters. so the two subclasses are treated as if they were two unrelated types
a
I'm assuming you just need to 'box' subclasses (or at least, that's what I've done)
h
@ambitious-actor-36781 Sounds like that solved the problem? Yes it's very common to box types in order to distinguish them