mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
added more collectors of plugin types and use them on openpype plugin installation
This commit is contained in:
parent
06d99c0bd9
commit
27cb6512cf
3 changed files with 117 additions and 40 deletions
|
|
@ -786,23 +786,15 @@ class ModulesManager:
|
||||||
).format(expected_keys, " | ".join(msg_items)))
|
).format(expected_keys, " | ".join(msg_items)))
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def collect_creator_plugin_paths(self, host_name):
|
def _collect_plugin_paths(self, method_name, *args, **kwargs):
|
||||||
"""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
|
|
||||||
output = []
|
output = []
|
||||||
for module in self.get_enabled_modules():
|
for module in self.get_enabled_modules():
|
||||||
# Skip module that do not inherit from `IPluginPaths`
|
# Skip module that do not inherit from `IPluginPaths`
|
||||||
if not isinstance(module, IPluginPaths):
|
if not isinstance(module, IPluginPaths):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
paths = module.get_creator_plugin_paths(host_name)
|
method = getattr(module, method_name)
|
||||||
|
paths = method(*args, **kwargs)
|
||||||
if paths:
|
if paths:
|
||||||
# Convert to list if value is not list
|
# Convert to list if value is not list
|
||||||
if not isinstance(paths, (list, tuple, set)):
|
if not isinstance(paths, (list, tuple, set)):
|
||||||
|
|
@ -810,6 +802,53 @@ class ModulesManager:
|
||||||
output.extend(paths)
|
output.extend(paths)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
def collect_create_plugin_paths(self, host_name):
|
||||||
|
"""Helper to collect creator plugin paths from modules.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host_name (str): For which host are creators meant.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of creator plugin paths.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._collect_plugin_paths(
|
||||||
|
"get_create_plugin_paths",
|
||||||
|
host_name
|
||||||
|
)
|
||||||
|
|
||||||
|
collect_creator_plugin_paths = collect_create_plugin_paths
|
||||||
|
|
||||||
|
def collect_load_plugin_paths(self, host_name):
|
||||||
|
"""Helper to collect load plugin paths from modules.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host_name (str): For which host are load plugins meant.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of load plugin paths.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._collect_plugin_paths(
|
||||||
|
"get_load_plugin_paths",
|
||||||
|
host_name
|
||||||
|
)
|
||||||
|
|
||||||
|
def collect_publish_plugin_paths(self, host_name):
|
||||||
|
"""Helper to collect load plugin paths from modules.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host_name (str): For which host are load plugins meant.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
list: List of pyblish plugin paths.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._collect_plugin_paths(
|
||||||
|
"get_publish_plugin_paths",
|
||||||
|
host_name
|
||||||
|
)
|
||||||
|
|
||||||
def get_host_module(self, host_name):
|
def get_host_module(self, host_name):
|
||||||
"""Find host module by host name.
|
"""Find host module by host name.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@ class OpenPypeInterface:
|
||||||
|
|
||||||
Child classes of OpenPypeInterface may be used as mixin in different
|
Child classes of OpenPypeInterface may be used as mixin in different
|
||||||
OpenPype modules which means they have to have implemented methods defined
|
OpenPype modules which means they have to have implemented methods defined
|
||||||
in the interface. By default interface does not have any abstract parts.
|
in the interface. By default, interface does not have any abstract parts.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
pass
|
||||||
|
|
@ -44,40 +44,71 @@ class IPluginPaths(OpenPypeInterface):
|
||||||
def get_plugin_paths(self):
|
def get_plugin_paths(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_creator_plugin_paths(self, host_name):
|
def _get_plugin_paths_by_type(self, plugin_type):
|
||||||
"""Retreive creator plugin paths.
|
paths = self.get_plugin_paths()
|
||||||
|
if not paths or plugin_type not in paths:
|
||||||
|
return []
|
||||||
|
|
||||||
Give addons ability to add creator plugin paths based on host name.
|
paths = paths[plugin_type]
|
||||||
|
if not paths:
|
||||||
|
return []
|
||||||
|
|
||||||
NOTES:
|
if not isinstance(paths, (list, tuple, set)):
|
||||||
- Default implementation uses 'get_plugin_paths' and always return
|
paths = [paths]
|
||||||
all creator plugins.
|
return paths
|
||||||
- Host name may help to organize plugins by host, but each creator
|
|
||||||
alsomay have host filtering.
|
def get_create_plugin_paths(self, host_name):
|
||||||
|
"""Receive create plugin paths.
|
||||||
|
|
||||||
|
Give addons ability to add create plugin paths based on host name.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
Default implementation uses 'get_plugin_paths' and always return
|
||||||
|
all create plugin paths.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
host_name (str): For which host are the plugins meant.
|
host_name (str): For which host are the plugins meant.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
paths = self.get_plugin_paths()
|
return self._get_plugin_paths_by_type("create")
|
||||||
if not paths or "create" not in paths:
|
|
||||||
return []
|
|
||||||
|
|
||||||
create_paths = paths["create"]
|
def get_load_plugin_paths(self, host_name):
|
||||||
if not create_paths:
|
"""Receive load plugin paths.
|
||||||
return []
|
|
||||||
|
|
||||||
if not isinstance(create_paths, (list, tuple, set)):
|
Give addons ability to add load plugin paths based on host name.
|
||||||
create_paths = [create_paths]
|
|
||||||
return create_paths
|
Notes:
|
||||||
|
Default implementation uses 'get_plugin_paths' and always return
|
||||||
|
all load plugin paths.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host_name (str): For which host are the plugins meant.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._get_plugin_paths_by_type("load")
|
||||||
|
|
||||||
|
def get_publish_plugin_paths(self, host_name):
|
||||||
|
"""Receive publish plugin paths.
|
||||||
|
|
||||||
|
Give addons ability to add publish plugin paths based on host name.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
Default implementation uses 'get_plugin_paths' and always return
|
||||||
|
all publish plugin paths.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
host_name (str): For which host are the plugins meant.
|
||||||
|
"""
|
||||||
|
|
||||||
|
return self._get_plugin_paths_by_type("publish")
|
||||||
|
|
||||||
|
|
||||||
class ILaunchHookPaths(OpenPypeInterface):
|
class ILaunchHookPaths(OpenPypeInterface):
|
||||||
"""Module has launch hook paths to return.
|
"""Module has launch hook paths to return.
|
||||||
|
|
||||||
Modules does not have to inherit from this interface (changed 8.11.2022).
|
Modules don't have to inherit from this interface (changed 8.11.2022).
|
||||||
Module just have to have implemented 'get_launch_hook_paths' to be able use
|
Module just have to have implemented 'get_launch_hook_paths' to be able to
|
||||||
the advantage.
|
use the advantage.
|
||||||
|
|
||||||
Expected result is list of paths.
|
Expected result is list of paths.
|
||||||
["path/to/launch_hooks_dir"]
|
["path/to/launch_hooks_dir"]
|
||||||
|
|
|
||||||
|
|
@ -158,17 +158,24 @@ def install_openpype_plugins(project_name=None, host_name=None):
|
||||||
pyblish.api.register_discovery_filter(filter_pyblish_plugins)
|
pyblish.api.register_discovery_filter(filter_pyblish_plugins)
|
||||||
register_loader_plugin_path(LOAD_PATH)
|
register_loader_plugin_path(LOAD_PATH)
|
||||||
|
|
||||||
modules_manager = _get_modules_manager()
|
|
||||||
publish_plugin_dirs = modules_manager.collect_plugin_paths()["publish"]
|
|
||||||
for path in publish_plugin_dirs:
|
|
||||||
pyblish.api.register_plugin_path(path)
|
|
||||||
|
|
||||||
if host_name is None:
|
if host_name is None:
|
||||||
host_name = os.environ.get("AVALON_APP")
|
host_name = os.environ.get("AVALON_APP")
|
||||||
|
|
||||||
creator_paths = modules_manager.collect_creator_plugin_paths(host_name)
|
modules_manager = _get_modules_manager()
|
||||||
for creator_path in creator_paths:
|
publish_plugin_dirs = modules_manager.collect_publish_plugin_paths(
|
||||||
register_creator_plugin_path(creator_path)
|
host_name)
|
||||||
|
for path in publish_plugin_dirs:
|
||||||
|
pyblish.api.register_plugin_path(path)
|
||||||
|
|
||||||
|
create_plugin_paths = modules_manager.collect_create_plugin_paths(
|
||||||
|
host_name)
|
||||||
|
for path in create_plugin_paths:
|
||||||
|
register_creator_plugin_path(path)
|
||||||
|
|
||||||
|
load_plugin_paths = modules_manager.collect_load_plugin_paths(
|
||||||
|
host_name)
|
||||||
|
for path in load_plugin_paths:
|
||||||
|
register_loader_plugin_path(path)
|
||||||
|
|
||||||
if project_name is None:
|
if project_name is None:
|
||||||
project_name = os.environ.get("AVALON_PROJECT")
|
project_name = os.environ.get("AVALON_PROJECT")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue