pyblish-base icon indicating copy to clipboard operation
pyblish-base copied to clipboard

Setup and Teardown plug-ins

Open mottosso opened this issue 5 years ago • 3 comments

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)

mottosso avatar Sep 19 '19 08:09 mottosso

api.register_setup_teardown(MyTeardown)

Would this be better with api.register_teardown_plugin(MyTeardown) ?

tokejepsen avatar Sep 19 '19 09:09 tokejepsen

Oh, yes, you're right. Typo.

mottosso avatar Sep 19 '19 09:09 mottosso

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.

davidlatwe avatar Sep 27 '19 10:09 davidlatwe