mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
added 'context_plugin_should_run' to pipeline publish
This commit is contained in:
parent
08675dcdf5
commit
e28603bf1d
2 changed files with 61 additions and 0 deletions
|
|
@ -20,6 +20,8 @@ from .lib import (
|
|||
|
||||
get_errored_instances_from_context,
|
||||
get_errored_plugins_from_context,
|
||||
|
||||
context_plugin_should_run,
|
||||
)
|
||||
|
||||
from .abstract_expected_files import ExpectedFiles
|
||||
|
|
@ -50,6 +52,8 @@ __all__ = (
|
|||
"get_errored_instances_from_context",
|
||||
"get_errored_plugins_from_context",
|
||||
|
||||
"context_plugin_should_run",
|
||||
|
||||
"ExpectedFiles",
|
||||
|
||||
"RenderInstance",
|
||||
|
|
|
|||
|
|
@ -357,3 +357,60 @@ def get_errored_plugins_from_context(context):
|
|||
plugins.append(result["plugin"])
|
||||
|
||||
return plugins
|
||||
|
||||
|
||||
def filter_instances_for_context_plugin(plugin, context):
|
||||
"""Filter instances on context by context plugin filters.
|
||||
|
||||
This is for cases when context plugin need similar filtering like instance
|
||||
plugin have, but for some reason must run on context.
|
||||
|
||||
Args:
|
||||
plugin (pyblish.api.Plugin): Plugin with filters.
|
||||
context (pyblish.api.Context): Pyblish context with insances.
|
||||
|
||||
Returns:
|
||||
Iterator[pyblish.lib.Instance]: Iteration of valid instances.
|
||||
"""
|
||||
|
||||
if not plugin.families:
|
||||
return []
|
||||
|
||||
plugin_families = set(plugin.families)
|
||||
for instance in context:
|
||||
# Ignore inactive instances
|
||||
if (
|
||||
not instance.data.get("publish", True)
|
||||
or not instance.data.get("active", True)
|
||||
):
|
||||
continue
|
||||
|
||||
family = instance.data.get("family")
|
||||
if family and family in plugin_families:
|
||||
yield instance
|
||||
|
||||
families = instance.data.get("families", [])
|
||||
if any(f in plugin_families for f in families):
|
||||
yield instance
|
||||
|
||||
|
||||
def context_plugin_should_run(plugin, context):
|
||||
"""Return whether the ContextPlugin should run on the given context.
|
||||
|
||||
This is a helper function to work around a bug pyblish-base#250
|
||||
Whenever a ContextPlugin sets specific families it will still trigger even
|
||||
when no instances are present that have those families.
|
||||
|
||||
This actually checks it correctly and returns whether it should run.
|
||||
|
||||
Args:
|
||||
plugin (pyblish.api.Plugin): Plugin with filters.
|
||||
context (pyblish.api.Context): Pyblish context with insances.
|
||||
|
||||
Returns:
|
||||
bool: Context plugin should run based on valid instances.
|
||||
"""
|
||||
|
||||
for instance in filter_instances_for_context_plugin(plugin, context):
|
||||
return True
|
||||
return False
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue