https://pantsbuild.org/ logo
h

happy-kitchen-89482

08/26/2020, 9:47 PM
Do we have a way to deregister a rule? E.g., if a custom plugin wants to override a rule implementation?
w

witty-crayon-22786

08/26/2020, 10:11 PM
we do not. so far the approach has been to declare
@unions
in places where people can plug in logic, rather than replacing things.
…and if that’s possible for the usecase, it’s probably preferable.
h

happy-kitchen-89482

08/26/2020, 10:35 PM
Yeah, that's been my approach so far (this is re custom logic for computing setup-py kwargs, such as
version
, in a `python_distribution`'s
provides=
field.)
w

witty-crayon-22786

08/26/2020, 10:36 PM
would look at AsyncField, as it was how eric expected that custom logic to construct fields would be plugged in
👍 2
or the macro stuff i mentioned.
i think that we might eventually need to provide the ability to de-register a rule, as an escape hatch for things that haven’t been made explicitly pluggable, but avoiding doing that for as long as we can would be great.
h

hundreds-father-404

08/26/2020, 11:42 PM
No, I’ve been wanting this mechanism for a while though. I think it will make it feasible for users to swap out built in rules for their own version
With an AsyncField, it’s important tho that there’s only one rule to hydrate that field. That’s key to the Target API working with subclassibg a field. So, the field author should expose certain entry points that subclasses can implement. For example, the Sources field has the entry point validate_snapshot(), which gets called in the hydration rule
w

witty-crayon-22786

08/26/2020, 11:46 PM
https://pantsbuild.slack.com/archives/C0D7TNJHL/p1598485364046600?thread_ts=1598478454.043400&cid=C0D7TNJHL it’s a bit like monkey-patching. it’s helpful as a stopgap until a true extension point is added, but you don’t want to do it in the long term.
h

hundreds-father-404

08/26/2020, 11:53 PM
Yes for sure it’s monkey patching. It’s really powerful that python lets you monkey patch. Agreed that we should err on the side of proper extensions, but there will always be rules we don’t want to extend. For example, you may want to change how the SourceFiles rule works
w

witty-crayon-22786

08/26/2020, 11:55 PM
if you do that, and upstream never hears about it, it is very likely to break during the next release
(we’re in agreement i think. i’m just trying to highlight the extent to which it is a stopgap until something can be upstreamed/made extensible)
…which is why leaning on it now, when we have the most flexibility to adjust the plugin API to enable this kind of usecase, would be a bad idea i think.