pyblish / pyblish-base

Pyblish base library - see https://github.com/pyblish/pyblish for details.
Other
126 stars 59 forks source link

Setup and Teardown plug-ins #352

Open mottosso opened 4 years ago

mottosso commented 4 years ago

Goal

Enable preparation and handling of the initial and final stages of the publishing pipeline.

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)
tokejepsen commented 4 years ago

api.register_setup_teardown(MyTeardown)

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

mottosso commented 4 years ago

Oh, yes, you're right. Typo.

davidlatwe commented 4 years ago

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.