Quck thought about some behavioural changes to make developing and running plug-ins more explicit.
import pyblish.api # Example 1 class MyPlugin(pyblish.api.Validator): run_per_instance = True def process(self): assert self.current_instance.data("color") == "blue", "Color is not blue!" # Example 2 class MyPlugin(pyblish.api.Validator): run_per_instance = False def process(self): assert self.current_instance is None # Example 3 class MyPlugin(pyblish.api.Validator): run_per_instance = False def process(self): assert self.context.data("filename")
- no arguments
- an explicit flag to determine whether or not to run once per
Instance, or not.
Here’s an alternative.
# Example 4 class MyPlugin(pyblish.api.InstanceValidator): def process(self, instance): assert instance.data("color") # Example 5 class MyPlugin(pyblish.api.ContextValidator): def process(self, context): assert context.data("filename")
- Explicit class per behaviour
- Maintain arguments, but they differ according to the class
Which means we could also do.
# Example 6 class MyPlugin(pyblish.api.Validator): def process(self): assert time.time() < 16000
In the off chance that neither
Instance is of interest.
From a conversation with Justin on the Python Inside Maya list, it struck me that behaviour is embedded into the argument signature, which can be hard to learn and harder to remember and reason about.
This way, behaviour is explicit, at the cost of more typing and more super classes.
Technically, the latter alternative is something we could implement today whilst maintaining backwards compatibility, and phase off as we did with Dependency Injection. The question is, does this improve our code and does it make it easier for newcomers to pick up?
It would eliminate the need for Dependency Injection, something cool and useful but not very Pythonic, along with the possibility of custom Services, which I haven’t yet seen anyone make use of.
Let me know your thoughts.