laoder plugin has compatibility method on it's own

This commit is contained in:
Jakub Trllo 2023-01-20 19:56:38 +01:00
parent 439a2b4781
commit a91a980b1b
2 changed files with 35 additions and 18 deletions

View file

@ -2,7 +2,10 @@ import os
import logging
from openpype.settings import get_system_settings, get_project_settings
from openpype.pipeline import legacy_io
from openpype.pipeline import (
schema,
legacy_io,
)
from openpype.pipeline.plugin_discover import (
discover,
register_plugin,
@ -79,6 +82,36 @@ class LoaderPlugin(list):
print(" - setting `{}`: `{}`".format(option, value))
setattr(cls, option, value)
@classmethod
def is_compatible_loader(cls, context):
"""Return whether a loader is compatible with a context.
This checks the version's families and the representation for the given
Loader.
Returns:
bool
"""
maj_version, _ = schema.get_schema_version(context["subset"]["schema"])
if maj_version < 3:
families = context["version"]["data"].get("families", [])
else:
families = context["subset"]["data"]["families"]
representation = context["representation"]
has_family = (
"*" in cls.families or any(
family in cls.families for family in families
)
)
representations = cls.get_representations()
has_representation = (
"*" in representations
or representation["name"] in representations
)
return has_family and has_representation
@classmethod
def get_representations(cls):
return cls.representations

View file

@ -748,25 +748,9 @@ def is_compatible_loader(Loader, context):
Returns:
bool
"""
maj_version, _ = schema.get_schema_version(context["subset"]["schema"])
if maj_version < 3:
families = context["version"]["data"].get("families", [])
else:
families = context["subset"]["data"]["families"]
representation = context["representation"]
has_family = (
"*" in Loader.families or any(
family in Loader.families for family in families
)
)
representations = Loader.get_representations()
has_representation = (
"*" in representations or representation["name"] in representations
)
return has_family and has_representation
return Loader.is_compatible_loader(context)
def loaders_from_repre_context(loaders, repre_context):