Skip to content

Commit

Permalink
Adding support for SimplePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
mottosso committed Jun 3, 2015
1 parent c353afa commit 58369aa
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 19 deletions.
21 changes: 11 additions & 10 deletions pyblish_rpc/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,16 @@ def format_plugin(plugin):
"""

try:
# The MRO is as follows: (-1)object, (-2)Plugin, (-3)Selector..
type = plugin.__mro__[-3].__name__
except IndexError:
# Plug-in was not subclasses from any of the
# provided superclasses of pyblish.api. This
# is either a bug or some (very) custom behavior
# on the users part.
type = None
log.critical("This is a bug")
if len(plugin.__mro__) > 3:
# In case of a SVEC plug-in.
try:
# The MRO is as follows: (-1)object, (-2)Plugin, (-3)Selector..
type = plugin.__mro__[-3].__name__
except IndexError:
type = None
log.critical("This is a bug")
else:
type = "Simple"

try:
if plugin.__module__ == "__main__":
Expand Down Expand Up @@ -280,6 +280,7 @@ def format_plugin(plugin):
"hosts": plugin.hosts,
"families": plugin.families,
"doc": inspect.getdoc(plugin),
"active": plugin.active,

# Metadata
"__pre11__": plugin.__pre11__,
Expand Down
33 changes: 33 additions & 0 deletions pyblish_rpc/mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,35 @@ class ValidateWithLongLabel(pyblish.api.Validator):
label = "Validate with Loooooooooooooooooooooong Label"


@pyblish.api.log
class SimplePlugin1(pyblish.api.Plugin):
"""Validate using the simple-plugin interface"""

def process(self):
self.log.info("I'm a simple plug-in, only processed once")


@pyblish.api.log
class SimplePlugin2(pyblish.api.Plugin):
"""Validate using the simple-plugin interface
It doesn't have an order, and will likely end up *before* all
other plug-ins. (due to how sorted([1, 2, 3, None]) works)
"""

def process(self, context):
self.log.info("Processing the context, simply: %s" % context)


@pyblish.api.log
class SimplePlugin3(pyblish.api.Plugin):
"""Simply process every instance"""

def process(self, instance):
self.log.info("Processing the instance, simply: %s" % instance)



instances = [
{
Expand Down Expand Up @@ -381,6 +410,10 @@ class ValidateWithLongLabel(pyblish.api.Validator):
ExtractAsMa,
ConformAsset,

SimplePlugin1,
SimplePlugin2,
SimplePlugin3,

ValidateInstancesDI,
ExtractInstancesDI,
ValidateDIWithRepair,
Expand Down
19 changes: 10 additions & 9 deletions tests/test_blackbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,31 +153,36 @@ def process(self, context):
count["#"] += 1

class RunTwice(pyblish.api.Validator):
"""This supports the family of both instances"""
families = ["myFamily"]

def process(self, instance):
print("Processing: %s" % type(self).__name__)
count["#"] += 1
count["#"] += 10

assert False, "I was programmed to fail"

class DontRun1(pyblish.api.Validator):
"""This isn't run, because of an unsupported family"""
families = ["unsupportedFamily"]

def process(self, instance):
print("Processing: %s" % type(self).__name__)
count["#"] += 1
count["#"] += 100

class DontRun2(pyblish.api.Extractor):
"""This isn't run, because validation fails above"""
def process(self, context):
print("Processing: %s" % type(self).__name__)
count["#"] += 10
count["#"] += 1000

class DontRun3(pyblish.api.Extractor):
"""This isn't run, because validation fails above"""
families = ["myFamily"]

def process(self, instance):
print("Processing: %s" % type(self).__name__)
count["#"] += 100
count["#"] += 10000

pyblish.api.register_plugin(RunOnce)
pyblish.api.register_plugin(RunTwice)
Expand All @@ -199,14 +204,10 @@ def process(self, instance):
test_failed = True
break

if isinstance(result, Exception):
print("Got an exception: %s" % result)
break

context = proxy.context()
assert context[0].name in ["A", "B"]
assert context[1].name in ["A", "B"]
assert_equals(count["#"], 3)
assert_equals(count["#"], 21)
assert_true(test_failed)


Expand Down
1 change: 1 addition & 0 deletions tests/test_mocking.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
def test_plugins():
"""Trigger all plug-ins"""
context = pyblish.api.Context()

for plugin in pyblish_rpc.mocking.plugins:
pyblish.plugin.process(plugin, context)

Expand Down

0 comments on commit 58369aa

Please sign in to comment.