pyblish-base
pyblish-base copied to clipboard
Setup and Teardown plug-ins
Goal
Enable preparation and handling of the initial and final stages of the publishing pipeline.
- Related https://github.com/pyblish/pyblish-qml/pull/344
Motivation
At the moment, if processing fails in response to a failed test, there's little you can do. If system-wide state was changed during processing - such as files having been extracted, database written to - you aren't given a change to clean things up.
To balance this "teardown" process, we'll also have a "setup" that runs first, regardless of plug-in order. To setup database connections and other things relevant to the whole test, and later torn down in the tearndown plug-in.
Implemenation
from pyblish import api
class MySetup(api.ContextPlugin):
...
class MyTeardown(api.ContextPlugin):
def process(self, context):
if any(r["error"] for r in context.data["results"]):
# do cleanup
api.register_setup_plugin(MySetup)
api.register_setup_teardown(MyTeardown)
api.register_setup_teardown(MyTeardown)
Would this be better with api.register_teardown_plugin(MyTeardown)
?
Oh, yes, you're right. Typo.
Instead of registering as teardown plugins, what about adding an attribute teardown
?
class MyTeardown(api.ContextPlugin):
teardown = True
And these kind of plugins will also guaranty to run even user pressed the GUI Stop button.
:point_up: This is something I might need for pyblish_qml
.