Skip to content

Instantly share code, notes, and snippets.

@davidlatwe
Last active November 5, 2017 09:55
Show Gist options
  • Save davidlatwe/385e69d63cee0f110b5fb1babf696526 to your computer and use it in GitHub Desktop.
Save davidlatwe/385e69d63cee0f110b5fb1babf696526 to your computer and use it in GitHub Desktop.
Pyblish - Enable Publishing Continues with Validation Error
from pyblish.logic import (
registered_test,
plugins_by_targets,
instances_by_plugin,
log
)
from pyblish.plugin import (
registered_targets,
)
import pyblish.api
import pyblish.lib as lib
import pyblish.logic as logic
import os
def Iterator(plugins, context, state=None):
"""Primary iterator
This is the brains of publishing. It handles logic related
to which plug-in to process with which Instance or Context,
in addition to stopping when necessary.
Arguments:
plugins (list): Plug-ins to consider
context (list): Instances to consider
state (dict): Mutable state
"""
test = registered_test()
state = {
"nextOrder": None,
"ordersWithError": set(),
"failWithError": True
}
# We'll add "default" target if no targets are registered. This happens
# when running the Iterator directly without registering any targets.
targets = registered_targets() or ["default"]
plugins = plugins_by_targets(plugins, targets)
for plugin in plugins:
if not plugin.active:
log.debug("%s was inactive, skipping.." % plugin)
continue
state["nextOrder"] = plugin.order
state["failWithError"] = not plugin.optional
message = test(**state)
if message:
raise StopIteration("Stopped due to %s" % message)
instances = instances_by_plugin(context, plugin)
if plugin.__instanceEnabled__:
for instance in instances:
if instance.data.get("publish") is False:
log.debug("%s was inactive, skipping.." % instance)
continue
yield plugin, instance
else:
yield plugin, None
def ignore_error_test(**vars):
offset = 0.5
validation_order = pyblish.api.ValidatorOrder
# If validation is done
if vars["nextOrder"] >= validation_order + offset:
for order in vars["ordersWithError"]:
if (
lib.inrange(order,
base=validation_order,
offset=offset) and
vars["failWithError"]
):
return "failed validation"
# Register new iter test
pyblish.api.register_test(ignore_error_test)
# override logic.Iterator
logic.Iterator = Iterator
@davidlatwe
Copy link
Author

Modified :

  • Hard code the state in Iterator
  • Add state["failWithError"]
  • Add state["failWithError"] = not plugin.optional
  • Register new iter test which including state["failWithError"] into consideration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment