From 4866f20f866607cccd8a01b024bb9ed59742b376 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 8 Dec 2023 12:59:50 +0100 Subject: [PATCH 1/7] Refactor colorspace handling in CollectColorspace plugin - Refactored the code to use more descriptive variable names - Added a helper method `_colorspace_name_by_type` to retrieve the colorspace name based on its type - Updated logging statements for better clarity and readability Fix validation error in ValidateColorspace plugin - Added a check to ensure that the OCIO config contains at least one colorspace - If no colorspaces are found, an error is raised with appropriate messages and descriptions - Updated logging statement to include a pretty-printed representation of the config's colorspaces --- .../publish/collect_explicit_colorspace.py | 31 ++++++++++++++++--- .../plugins/publish/validate_colorspace.py | 14 ++++++++- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 5db2b0cbad..3b62ed7e55 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -26,20 +26,43 @@ class CollectColorspace(pyblish.api.InstancePlugin, def process(self, instance): values = self.get_attr_values_from_data(instance.data) - colorspace = values.get("colorspace", None) - if colorspace is None: + colorspace_value = values.get("colorspace", None) + if colorspace_value is None: return - self.log.debug("Explicit colorspace set to: {}".format(colorspace)) + color_data = colorspace.convert_colorspace_enumerator_item( + colorspace_value, self.config_items) + + colorspace_name = self._colorspace_name_by_type(color_data) + self.log.debug("Explicit colorspace name: {}".format(colorspace_name)) context = instance.context + context.data["colorspaceConfigItems"] = self.config_items for repre in instance.data.get("representations", {}): self.set_representation_colorspace( representation=repre, context=context, - colorspace=colorspace + colorspace=colorspace_name ) + def _colorspace_name_by_type(self, colorspace_data): + """ + Returns colorspace name by type + + Arguments: + colorspace_data (dict): colorspace data + + Returns: + str: colorspace name + """ + if colorspace_data["type"] == "colorspaces": + return colorspace_data["name"] + elif colorspace_data["type"] == "roles": + return colorspace_data["colorspace"] + else: + raise KeyError("Unknown colorspace type: {}".format( + colorspace_data["type"])) + @classmethod def apply_settings(cls, project_settings): host = registered_host() diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 03f9f299b2..c2eee7c515 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -1,3 +1,4 @@ +from pprint import pformat import pyblish.api from openpype.pipeline import ( @@ -33,13 +34,24 @@ class ValidateColorspace(pyblish.api.InstancePlugin, config_path = colorspace_data["config"]["path"] if config_path not in config_colorspaces: colorspaces = get_ocio_config_colorspaces(config_path) - config_colorspaces[config_path] = set(colorspaces) + if not colorspaces.get("colorspaces"): + raise PublishValidationError( + title="Colorspace validation", + message=f"OCIO config '{config_path}' does not contain " + f"any colorspaces. This is error in config. " + "Contact your pipeline TD.", + description=f"OCIO config '{config_path}' does not " + f"contain any colorspaces. This is error " + "in config. Contact your pipeline TD." + ) + config_colorspaces[config_path] = set(colorspaces["colorspaces"]) colorspace = colorspace_data["colorspace"] self.log.debug( f"Validating representation '{repre['name']}' " f"colorspace '{colorspace}'" ) + self.log.debug(pformat(config_colorspaces[config_path])) if colorspace not in config_colorspaces[config_path]: message = ( f"Representation '{repre['name']}' colorspace " From 764775bf006304939ffe59104f0e503e1b8297db Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 8 Dec 2023 13:06:19 +0100 Subject: [PATCH 2/7] hound --- .../traypublisher/plugins/publish/validate_colorspace.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index c2eee7c515..74d8956986 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -37,14 +37,15 @@ class ValidateColorspace(pyblish.api.InstancePlugin, if not colorspaces.get("colorspaces"): raise PublishValidationError( title="Colorspace validation", - message=f"OCIO config '{config_path}' does not contain " + message=f"OCIO config '{config_path}' does not contain " # noqa f"any colorspaces. This is error in config. " "Contact your pipeline TD.", description=f"OCIO config '{config_path}' does not " f"contain any colorspaces. This is error " "in config. Contact your pipeline TD." ) - config_colorspaces[config_path] = set(colorspaces["colorspaces"]) + config_colorspaces[config_path] = set( + colorspaces["colorspaces"]) colorspace = colorspace_data["colorspace"] self.log.debug( From 760adc87bae8de1f99d217d9d9e9d5e98562ab19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 12 Dec 2023 16:55:03 +0100 Subject: [PATCH 3/7] Update openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py Co-authored-by: Roy Nieterau --- .../hosts/traypublisher/plugins/publish/validate_colorspace.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 74d8956986..6ee39584be 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -52,7 +52,6 @@ class ValidateColorspace(pyblish.api.InstancePlugin, f"Validating representation '{repre['name']}' " f"colorspace '{colorspace}'" ) - self.log.debug(pformat(config_colorspaces[config_path])) if colorspace not in config_colorspaces[config_path]: message = ( f"Representation '{repre['name']}' colorspace " From ed3a2556e2dcff2cc5f08aafe7799146aab85333 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 12 Dec 2023 16:55:40 +0100 Subject: [PATCH 4/7] Update openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py Co-authored-by: Roy Nieterau --- .../plugins/publish/validate_colorspace.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 6ee39584be..9b870617fb 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -35,14 +35,15 @@ class ValidateColorspace(pyblish.api.InstancePlugin, if config_path not in config_colorspaces: colorspaces = get_ocio_config_colorspaces(config_path) if not colorspaces.get("colorspaces"): + message = ( + f"OCIO config '{config_path}' does not contain any " + "colorspaces. This is an error in the OCIO config. " + "Contact your pipeline TD.", + ) raise PublishValidationError( title="Colorspace validation", - message=f"OCIO config '{config_path}' does not contain " # noqa - f"any colorspaces. This is error in config. " - "Contact your pipeline TD.", - description=f"OCIO config '{config_path}' does not " - f"contain any colorspaces. This is error " - "in config. Contact your pipeline TD." + message=message, + description=message ) config_colorspaces[config_path] = set( colorspaces["colorspaces"]) From d5866bf7810733e2e4c21384f25619e7b236881c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 12 Dec 2023 17:06:29 +0100 Subject: [PATCH 5/7] hound --- .../hosts/traypublisher/plugins/publish/validate_colorspace.py | 1 - 1 file changed, 1 deletion(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 9b870617fb..58c40938d2 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -1,4 +1,3 @@ -from pprint import pformat import pyblish.api from openpype.pipeline import ( From 4da0bcd5cd80406e98d67d4d3889d4a8a0c6422c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 12 Dec 2023 17:07:01 +0100 Subject: [PATCH 6/7] improving error comunication --- .../plugins/publish/collect_explicit_colorspace.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 3b62ed7e55..5dcc252f03 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -5,6 +5,7 @@ from openpype.pipeline import ( ) from openpype.lib import EnumDef from openpype.pipeline import colorspace +from openpype.pipeline.publish import KnownPublishError class CollectColorspace(pyblish.api.InstancePlugin, @@ -37,7 +38,6 @@ class CollectColorspace(pyblish.api.InstancePlugin, self.log.debug("Explicit colorspace name: {}".format(colorspace_name)) context = instance.context - context.data["colorspaceConfigItems"] = self.config_items for repre in instance.data.get("representations", {}): self.set_representation_colorspace( representation=repre, @@ -60,8 +60,11 @@ class CollectColorspace(pyblish.api.InstancePlugin, elif colorspace_data["type"] == "roles": return colorspace_data["colorspace"] else: - raise KeyError("Unknown colorspace type: {}".format( - colorspace_data["type"])) + raise KnownPublishError( + "Collecting of colorspace failed. used config is missing " + "colorspace type: '{}' .".format(colorspace_data["type"]) + "Please contact your pipeline TD." + ) @classmethod def apply_settings(cls, project_settings): From 3ef475fcd3641dc2faf0fd1d76f7f44b4cdbeccd Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 19 Dec 2023 14:05:47 +0100 Subject: [PATCH 7/7] hound catch --- .../plugins/publish/collect_explicit_colorspace.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 5dcc252f03..75c26ac958 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -61,9 +61,10 @@ class CollectColorspace(pyblish.api.InstancePlugin, return colorspace_data["colorspace"] else: raise KnownPublishError( - "Collecting of colorspace failed. used config is missing " - "colorspace type: '{}' .".format(colorspace_data["type"]) - "Please contact your pipeline TD." + ( + "Collecting of colorspace failed. used config is missing " + "colorspace type: '{}' . Please contact your pipeline TD." + ).format(colorspace_data['type']) ) @classmethod