diff --git a/pype/hosts/tvpaint/__init__.py b/pype/hosts/tvpaint/__init__.py index 7027f0fb55..e69de29bb2 100644 --- a/pype/hosts/tvpaint/__init__.py +++ b/pype/hosts/tvpaint/__init__.py @@ -1,55 +0,0 @@ -import os -import logging - -from avalon.tvpaint.communication_server import register_localization_file -from avalon.tvpaint import pipeline -import avalon.api -import pyblish.api -from pype import PLUGINS_DIR - -log = logging.getLogger("pype.hosts.tvpaint") - -PUBLISH_PATH = os.path.join(PLUGINS_DIR, "tvpaint", "publish") -LOAD_PATH = os.path.join(PLUGINS_DIR, "tvpaint", "load") -CREATE_PATH = os.path.join(PLUGINS_DIR, "tvpaint", "create") - - -def on_instance_toggle(instance, old_value, new_value): - instance_id = instance.data["uuid"] - found_idx = None - current_instances = pipeline.list_instances() - for idx, workfile_instance in enumerate(current_instances): - if workfile_instance["uuid"] == instance_id: - found_idx = idx - break - - if found_idx is None: - return - - if "active" in current_instances[found_idx]: - current_instances[found_idx]["active"] = new_value - pipeline._write_instances(current_instances) - - -def install(): - log.info("Pype - Installing TVPaint integration") - current_dir = os.path.dirname(os.path.abspath(__file__)) - localization_file = os.path.join(current_dir, "avalon.loc") - register_localization_file(localization_file) - - pyblish.api.register_plugin_path(PUBLISH_PATH) - avalon.api.register_plugin_path(avalon.api.Loader, LOAD_PATH) - avalon.api.register_plugin_path(avalon.api.Creator, CREATE_PATH) - - registered_callbacks = ( - pyblish.api.registered_callbacks().get("instanceToggled") or [] - ) - if on_instance_toggle not in registered_callbacks: - pyblish.api.register_callback("instanceToggled", on_instance_toggle) - - -def uninstall(): - log.info("Pype - Uninstalling TVPaint integration") - pyblish.api.deregister_plugin_path(PUBLISH_PATH) - avalon.api.deregister_plugin_path(avalon.api.Loader, LOAD_PATH) - avalon.api.deregister_plugin_path(avalon.api.Creator, CREATE_PATH) diff --git a/pype/hosts/tvpaint/api/__init__.py b/pype/hosts/tvpaint/api/__init__.py new file mode 100644 index 0000000000..08484895c9 --- /dev/null +++ b/pype/hosts/tvpaint/api/__init__.py @@ -0,0 +1,57 @@ +import os +import logging + +from avalon.tvpaint.communication_server import register_localization_file +from avalon.tvpaint import pipeline +import avalon.api +import pyblish.api + +from pype.hosts import tvpaint + +log = logging.getLogger("pype.hosts.tvpaint") + +HOST_DIR = os.path.dirname(os.path.abspath(tvpaint.__file__)) +PLUGINS_DIR = os.path.join(HOST_DIR, "plugins") +PUBLISH_PATH = os.path.join(PLUGINS_DIR, "publish") +LOAD_PATH = os.path.join(PLUGINS_DIR, "load") +CREATE_PATH = os.path.join(PLUGINS_DIR, "create") + + +def on_instance_toggle(instance, old_value, new_value): + instance_id = instance.data["uuid"] + found_idx = None + current_instances = pipeline.list_instances() + for idx, workfile_instance in enumerate(current_instances): + if workfile_instance["uuid"] == instance_id: + found_idx = idx + break + + if found_idx is None: + return + + if "active" in current_instances[found_idx]: + current_instances[found_idx]["active"] = new_value + pipeline._write_instances(current_instances) + + +def install(): + log.info("Pype - Installing TVPaint integration") + localization_file = os.path.join(HOST_DIR, "resources", "avalon.loc") + register_localization_file(localization_file) + + pyblish.api.register_plugin_path(PUBLISH_PATH) + avalon.api.register_plugin_path(avalon.api.Loader, LOAD_PATH) + avalon.api.register_plugin_path(avalon.api.Creator, CREATE_PATH) + + registered_callbacks = ( + pyblish.api.registered_callbacks().get("instanceToggled") or [] + ) + if on_instance_toggle not in registered_callbacks: + pyblish.api.register_callback("instanceToggled", on_instance_toggle) + + +def uninstall(): + log.info("Pype - Uninstalling TVPaint integration") + pyblish.api.deregister_plugin_path(PUBLISH_PATH) + avalon.api.deregister_plugin_path(avalon.api.Loader, LOAD_PATH) + avalon.api.deregister_plugin_path(avalon.api.Creator, CREATE_PATH) diff --git a/pype/hooks/tvpaint/pre_install_pywin.py b/pype/hosts/tvpaint/hooks/pre_install_pywin.py similarity index 100% rename from pype/hooks/tvpaint/pre_install_pywin.py rename to pype/hosts/tvpaint/hooks/pre_install_pywin.py diff --git a/pype/hooks/tvpaint/pre_launch_args.py b/pype/hosts/tvpaint/hooks/pre_launch_args.py similarity index 96% rename from pype/hooks/tvpaint/pre_launch_args.py rename to pype/hosts/tvpaint/hooks/pre_launch_args.py index 210b1e99c3..ebb911220f 100644 --- a/pype/hooks/tvpaint/pre_launch_args.py +++ b/pype/hosts/tvpaint/hooks/pre_launch_args.py @@ -78,7 +78,9 @@ class TvpaintPrelaunchHook(PreLaunchHook): # TODO add ability to set different template workfile path via # settings pype_dir = os.path.dirname(os.path.abspath(tvpaint.__file__)) - template_path = os.path.join(pype_dir, "template.tvpp") + template_path = os.path.join( + pype_dir, "resources", "template.tvpp" + ) if not os.path.exists(template_path): self.log.warning( diff --git a/pype/plugins/tvpaint/create/create_render_layer.py b/pype/hosts/tvpaint/plugins/create/create_render_layer.py similarity index 100% rename from pype/plugins/tvpaint/create/create_render_layer.py rename to pype/hosts/tvpaint/plugins/create/create_render_layer.py diff --git a/pype/plugins/tvpaint/create/create_render_pass.py b/pype/hosts/tvpaint/plugins/create/create_render_pass.py similarity index 100% rename from pype/plugins/tvpaint/create/create_render_pass.py rename to pype/hosts/tvpaint/plugins/create/create_render_pass.py diff --git a/pype/plugins/tvpaint/create/create_review.py b/pype/hosts/tvpaint/plugins/create/create_review.py similarity index 100% rename from pype/plugins/tvpaint/create/create_review.py rename to pype/hosts/tvpaint/plugins/create/create_review.py diff --git a/pype/plugins/tvpaint/load/load_image.py b/pype/hosts/tvpaint/plugins/load/load_image.py similarity index 100% rename from pype/plugins/tvpaint/load/load_image.py rename to pype/hosts/tvpaint/plugins/load/load_image.py diff --git a/pype/plugins/tvpaint/load/load_reference_image.py b/pype/hosts/tvpaint/plugins/load/load_reference_image.py similarity index 100% rename from pype/plugins/tvpaint/load/load_reference_image.py rename to pype/hosts/tvpaint/plugins/load/load_reference_image.py diff --git a/pype/plugins/tvpaint/publish/collect_instances.py b/pype/hosts/tvpaint/plugins/publish/collect_instances.py similarity index 100% rename from pype/plugins/tvpaint/publish/collect_instances.py rename to pype/hosts/tvpaint/plugins/publish/collect_instances.py diff --git a/pype/plugins/tvpaint/publish/collect_workfile_data.py b/pype/hosts/tvpaint/plugins/publish/collect_workfile_data.py similarity index 100% rename from pype/plugins/tvpaint/publish/collect_workfile_data.py rename to pype/hosts/tvpaint/plugins/publish/collect_workfile_data.py diff --git a/pype/plugins/tvpaint/publish/extract_sequence.py b/pype/hosts/tvpaint/plugins/publish/extract_sequence.py similarity index 100% rename from pype/plugins/tvpaint/publish/extract_sequence.py rename to pype/hosts/tvpaint/plugins/publish/extract_sequence.py diff --git a/pype/plugins/tvpaint/publish/validate_frame_range.py b/pype/hosts/tvpaint/plugins/publish/validate_frame_range.py similarity index 100% rename from pype/plugins/tvpaint/publish/validate_frame_range.py rename to pype/hosts/tvpaint/plugins/publish/validate_frame_range.py diff --git a/pype/plugins/tvpaint/publish/validate_workfile_project_name.py b/pype/hosts/tvpaint/plugins/publish/validate_workfile_project_name.py similarity index 100% rename from pype/plugins/tvpaint/publish/validate_workfile_project_name.py rename to pype/hosts/tvpaint/plugins/publish/validate_workfile_project_name.py diff --git a/pype/hosts/tvpaint/avalon.loc b/pype/hosts/tvpaint/resources/avalon.loc similarity index 100% rename from pype/hosts/tvpaint/avalon.loc rename to pype/hosts/tvpaint/resources/avalon.loc diff --git a/pype/hosts/tvpaint/template.tvpp b/pype/hosts/tvpaint/resources/template.tvpp similarity index 100% rename from pype/hosts/tvpaint/template.tvpp rename to pype/hosts/tvpaint/resources/template.tvpp diff --git a/pype/lib/applications.py b/pype/lib/applications.py index 115db43930..cccc50d397 100644 --- a/pype/lib/applications.py +++ b/pype/lib/applications.py @@ -16,6 +16,8 @@ from .python_module_tools import ( classes_from_module ) +log = PypeLogger().get_logger(__name__) + class ApplicationNotFound(Exception): """Application was not found in ApplicationManager by name.""" @@ -575,19 +577,38 @@ class ApplicationLaunchContext: def paths_to_launch_hooks(self): """Directory paths where to look for launch hooks.""" # This method has potential to be part of application manager (maybe). - - # TODO find better way how to define dir path to default launch hooks - import pype - pype_dir = os.path.dirname(os.path.abspath(pype.__file__)) - hooks_dir = os.path.join(pype_dir, "hooks") + paths = [] # TODO load additional studio paths from settings # TODO add paths based on used modules (like `ftrack`) - paths = [] - subfolder_names = ["global", self.host_name, self.app_name] + import pype + pype_dir = os.path.dirname(os.path.abspath(pype.__file__)) + + # --- START: Backwards compatibility --- + hooks_dir = os.path.join(pype_dir, "hooks") + + subfolder_names = ["global", self.host_name] for subfolder_name in subfolder_names: path = os.path.join(hooks_dir, subfolder_name) - if os.path.exists(path) and os.path.isdir(path): + if ( + os.path.exists(path) + and os.path.isdir(path) + and path not in paths + ): + paths.append(path) + # --- END: Backwards compatibility --- + + subfolders_list = ( + ("hooks", "global"), + ("hosts", self.host_name, "hooks") + ) + for subfolders in subfolders_list: + path = os.path.join(pype_dir, *subfolders) + if ( + os.path.exists(path) + and os.path.isdir(path) + and path not in paths + ): paths.append(path) return paths diff --git a/requirements.txt b/requirements.txt index 24cf4f31c0..658405e2fb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ aiohttp +aiohttp_json_rpc appdirs arrow blessed