From 3fec8b293a0d08b479a1ab3585b129f5e64de49a Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Dec 2020 10:47:05 +0100 Subject: [PATCH 1/4] implemented `ILaunchHookPaths` interface --- pype/modules/__init__.py | 2 ++ pype/modules/base.py | 47 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) 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 From 1ef7dfbd33a3ace6513b5ab98ddd64a34aa8bcac Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Dec 2020 10:48:13 +0100 Subject: [PATCH 2/4] Ftrack module ingerit `ILaunchHookPaths` and has implemented `get_launch_hook_paths` --- pype/modules/ftrack/ftrack_module.py | 20 +++++++++++++++++-- .../launch_hooks}/post_ftrack_changes.py | 0 2 files changed, 18 insertions(+), 2 deletions(-) rename pype/{hooks/global => modules/ftrack/launch_hooks}/post_ftrack_changes.py (100%) diff --git a/pype/modules/ftrack/ftrack_module.py b/pype/modules/ftrack/ftrack_module.py index 44607681ec..d2de27e1b9 100644 --- a/pype/modules/ftrack/ftrack_module.py +++ b/pype/modules/ftrack/ftrack_module.py @@ -3,9 +3,16 @@ from abc import ABCMeta, abstractmethod import six import pype from pype.modules import ( - PypeModule, ITrayModule, IPluginPaths, ITimersManager, IUserModule + PypeModule, + ITrayModule, + IPluginPaths, + ITimersManager, + IUserModule, + ILaunchHookPaths ) +FTRACK_MODULE_DIR = os.path.dirname(os.path.abspath(__file__)) + @six.add_metaclass(ABCMeta) class IFtrackEventHandlerPaths: @@ -19,7 +26,12 @@ class IFtrackEventHandlerPaths: class FtrackModule( - PypeModule, ITrayModule, IPluginPaths, ITimersManager, IUserModule + PypeModule, + ITrayModule, + IPluginPaths, + ITimersManager, + IUserModule, + ILaunchHookPaths ): name = "ftrack" @@ -54,6 +66,10 @@ class FtrackModule( "publish": [os.path.join(pype.PLUGINS_DIR, "ftrack", "publish")] } + def get_launch_hook_paths(self): + """Implementation of `ILaunchHookPaths`.""" + return os.path.join(FTRACK_MODULE_DIR, "launch_hooks") + def connect_with_modules(self, enabled_modules): for module in enabled_modules: if not isinstance(module, IFtrackEventHandlerPaths): diff --git a/pype/hooks/global/post_ftrack_changes.py b/pype/modules/ftrack/launch_hooks/post_ftrack_changes.py similarity index 100% rename from pype/hooks/global/post_ftrack_changes.py rename to pype/modules/ftrack/launch_hooks/post_ftrack_changes.py From 2cdaf321fb828c64fdc237031963af5b6c2a9173 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Dec 2020 10:48:59 +0100 Subject: [PATCH 3/4] application launch context load modules to collect prelaunch hooks --- pype/lib/applications.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index cccc50d397..f8876179ed 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -610,6 +610,13 @@ class ApplicationLaunchContext: and path not in paths ): paths.append(path) + + # Load modules paths + from pype.modules import ModulesManager + + manager = ModulesManager() + paths.extend(manager.collect_launch_hook_paths()) + return paths def discover_launch_hooks(self, force=False): From 526f15a8528bffe0a8e151e590b53cd68cf71695 Mon Sep 17 00:00:00 2001 From: iLLiCiTiT Date: Tue, 22 Dec 2020 10:51:30 +0100 Subject: [PATCH 4/4] removed TODO --- pype/lib/applications.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pype/lib/applications.py b/pype/lib/applications.py index f8876179ed..c7d6464418 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -580,7 +580,6 @@ class ApplicationLaunchContext: paths = [] # TODO load additional studio paths from settings - # TODO add paths based on used modules (like `ftrack`) import pype pype_dir = os.path.dirname(os.path.abspath(pype.__file__))