implemented collecting of creator plugins for host

This commit is contained in:
Jakub Trllo 2022-05-13 11:29:19 +02:00
parent 6438078587
commit d2afd26ff6
2 changed files with 56 additions and 1 deletions

View file

@ -702,6 +702,32 @@ class ModulesManager:
).format(expected_keys, " | ".join(msg_items)))
return output
def collect_creator_plugin_paths(self, host_name):
"""Helper to collect creator plugin paths from modules.
Args:
host_name (str): For which host are creators meants.
Returns:
list: List of creator plugin paths.
"""
# Output structure
from openpype_interfaces import IPluginPaths
output = []
for module in self.get_enabled_modules():
# Skip module that do not inherit from `IPluginPaths`
if not isinstance(module, IPluginPaths):
continue
paths = module.get_creator_plugin_paths(host_name)
if paths:
# Convert to list if value is not list
if not isinstance(paths, (list, tuple, set)):
paths = [paths]
output.extend(paths)
return output
def collect_launch_hook_paths(self):
"""Helper to collect hooks from modules inherited ILaunchHookPaths.

View file

@ -1,5 +1,7 @@
from abc import abstractmethod
import six
from openpype import resources
from openpype.modules import OpenPypeInterface
@ -14,11 +16,38 @@ class IPluginPaths(OpenPypeInterface):
"publish": ["path/to/publish_plugins"]
}
"""
# TODO validation of an output
@abstractmethod
def get_plugin_paths(self):
pass
def get_creator_plugin_paths(self, host_name):
"""Retreive creator plugin paths.
Give addons ability to add creator plugin paths based on host name.
NOTES:
- Default implementation uses 'get_plugin_paths' and always return
all creator plugins.
- Host name may help to organize plugins by host, but each creator
alsomay have host filtering.
Args:
host_name (str): For which host are the plugins meant.
"""
paths = self.get_plugin_paths()
if not paths or "create" not in paths:
return []
create_paths = paths["create"]
if not create_paths:
return []
if not isinstance(create_paths, (list, tuple, set)):
create_paths = [create_paths]
return create_paths
class ILaunchHookPaths(OpenPypeInterface):
"""Module has launch hook paths to return.