diff --git a/pype/modules/__init__.py b/pype/modules/__init__.py index 4f76dc2df0..33fd45179a 100644 --- a/pype/modules/__init__.py +++ b/pype/modules/__init__.py @@ -5,6 +5,7 @@ from .base import ( ITrayAction, ITrayService, IPluginPaths, + ILaunchHookPaths, ModulesManager, TrayModulesManager ) @@ -45,6 +46,7 @@ __all__ = ( "ITrayAction", "ITrayService", "IPluginPaths", + "ILaunchHookPaths", "ModulesManager", "TrayModulesManager", diff --git a/pype/modules/base.py b/pype/modules/base.py index 525320f1a7..97e5f891af 100644 --- a/pype/modules/base.py +++ b/pype/modules/base.py @@ -84,6 +84,19 @@ class IPluginPaths: pass +@six.add_metaclass(ABCMeta) +class ILaunchHookPaths: + """Module has launch hook paths to return. + + Expected result is list of paths. + ["path/to/launch_hooks_dir"] + """ + + @abstractmethod + def get_launch_hook_paths(self): + pass + + @six.add_metaclass(ABCMeta) class ITrayModule: """Module has special procedures when used in Pype Tray. @@ -421,6 +434,40 @@ class ModulesManager: ).format(expected_keys, " | ".join(msg_items))) return output + def collect_launch_hook_paths(self): + """Helper to collect hooks from modules inherited ILaunchHookPaths. + + Returns: + list: Paths to launch hook directories. + """ + str_type = type("") + expected_types = (list, tuple, set) + + output = [] + for module in self.get_enabled_modules(): + # Skip module that do not inherit from `ILaunchHookPaths` + if not isinstance(module, ILaunchHookPaths): + continue + + hook_paths = module.get_launch_hook_paths() + if not hook_paths: + continue + + # Convert string to list + if isinstance(hook_paths, str_type): + hook_paths = [hook_paths] + + # Skip invalid types + if not isinstance(hook_paths, expected_types): + self.log.warning(( + "Result of `get_launch_hook_paths`" + " has invalid type {}. Expected {}" + ).format(type(hook_paths), expected_types)) + continue + + output.extend(hook_paths) + return output + class TrayModulesManager(ModulesManager): # Define order of modules in menu