From 713af514fdeec381867fd8a15486ce71cdbf5b0b Mon Sep 17 00:00:00 2001 From: BenoitConnan Date: Fri, 5 Nov 2021 12:11:33 +0100 Subject: [PATCH] Move template loader to lib and maya api --- .../{plugins/init => api}/template_loader.py | 15 ++---------- openpype/hosts/maya/plugins/init/__init__.py | 0 .../load => lib}/abstract_load_template.py | 0 openpype/lib/build_template.py | 24 ++++++++++++------- openpype/plugins/__init__.py | 0 openpype/plugins/load/__init__.py | 0 6 files changed, 17 insertions(+), 22 deletions(-) rename openpype/hosts/maya/{plugins/init => api}/template_loader.py (91%) delete mode 100644 openpype/hosts/maya/plugins/init/__init__.py rename openpype/{plugins/load => lib}/abstract_load_template.py (100%) delete mode 100644 openpype/plugins/__init__.py delete mode 100644 openpype/plugins/load/__init__.py diff --git a/openpype/hosts/maya/plugins/init/template_loader.py b/openpype/hosts/maya/api/template_loader.py similarity index 91% rename from openpype/hosts/maya/plugins/init/template_loader.py rename to openpype/hosts/maya/api/template_loader.py index 95c9d6fe436..73506331bb9 100644 --- a/openpype/hosts/maya/plugins/init/template_loader.py +++ b/openpype/hosts/maya/api/template_loader.py @@ -1,12 +1,5 @@ -from openpype.plugins.load.abstract_load_template import AbstractTemplateLoader -import importlib - -cmds = None - - -def init_cmds(): - global cmds - cmds = cmds or importlib.import_module('maya').cmds +from openpype.lib.abstract_load_template import AbstractTemplateLoader +from maya import cmds ATTRIBUTES = ['builder_type', 'representation', 'families', @@ -15,10 +8,6 @@ def init_cmds(): class TemplateLoader(AbstractTemplateLoader): - def __init__(self): - init_cmds() - super(TemplateLoader, self).__init__() - def import_template(self, path): self.newNodes = cmds.file(path, i=True, returnNewNodes=True) diff --git a/openpype/hosts/maya/plugins/init/__init__.py b/openpype/hosts/maya/plugins/init/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/openpype/plugins/load/abstract_load_template.py b/openpype/lib/abstract_load_template.py similarity index 100% rename from openpype/plugins/load/abstract_load_template.py rename to openpype/lib/abstract_load_template.py diff --git a/openpype/lib/build_template.py b/openpype/lib/build_template.py index d5c5984d74d..b36495a1974 100644 --- a/openpype/lib/build_template.py +++ b/openpype/lib/build_template.py @@ -1,18 +1,24 @@ import avalon -from openpype.hosts.maya.plugins.init.template_loader \ - import TemplateLoader as maya_TemplateLoader - +import importlib def get_concrete_template_loader(): - concrete_loaders = { - 'maya': maya_TemplateLoader + concrete_loaders_modules = { + 'maya': 'openpype.hosts.maya.api.template_loader' } dcc = avalon.io.Session['AVALON_APP'] - loader = concrete_loaders.get(dcc) - if not loader: - raise ValueError('DCC not found for template') - return loader + module_path = concrete_loaders_modules.get(dcc, None) + + if not module_path: + raise ValueError("Template not found for DCC '{}'".format(dcc)) + + module = importlib.import_module(module_path) + if not hasattr(module, 'TemplateLoader'): + raise ValueError("Linked module '{}' does not implement a template loader".format(module_path)) + + concrete_loader = module.TemplateLoader + + return concrete_loader class BuildWorkfileTemplate: diff --git a/openpype/plugins/__init__.py b/openpype/plugins/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/openpype/plugins/load/__init__.py b/openpype/plugins/load/__init__.py deleted file mode 100644 index e69de29bb2d..00000000000