I have a couple of questions for a plugin I'm work...
# plugins
b
I have a couple of questions for a plugin I'm working on writing: 1. Is there a method to have a rule detect what BUILD files are targeted when running a goal? I have a couple of BUILD files that require a very specific rule to be run prior to pytest kicking off, but the majority of the BUILD files in my repo don't require the plugin to run so I'd like to exit early if I'm targeting a BUILD file that doesn't require the rule to be run 2. The new rule that I created currently returns
PythonTestFieldSet
which was something the pants engine recommended as I was creating the plugin, however I'm curious if there are good examples on how to return that type so that the pants engine doesn't fail with
StopIteration
? The new rule is a union of a custom action that's a UnionRule with the TestFieldSet type
Is anyone able to help give some guidance on this today?
h
Hi, sorry for the delay. The plugin API is target-centric, or more precisely fieldset-centric. So one idiomatic way to get a rule to only act on specific targets is to have those BUILD files utilize a custom target type (e.g., MyPythonTests) and corresponding fieldset, and your rule converts MyFieldSet to PythonTestFieldSet, which pytest then acts on. Well, something like that, I may have glossed over a couple of details... But, this partly also depends on what your rule does. Is it running for its side-effects (such as starting up a test database)? If so, it may run afoul of caching if not written with care.
Re the StopIteration, I don't think I've seen that before, can you share the code schematics and the stack trace?
b
No worries, I know everyone is pretty busy. I'll put together a little package with the code and stack trace that I see from the iteration when I run it.
Here is a tgz of the items that are used in the plugin. Happy to try anything out as I'm a little confused by what I'm supposed to return in the rule function
One more thing that I thought may help, I tried returning the
PythonTestFieldSet
but couldn't figure out what I needed to use to populate the expected types. If I return something other than that class, pants complains about not having the proper return type