From 4866f20f866607cccd8a01b024bb9ed59742b376 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Fri, 8 Dec 2023 12:59:50 +0100 Subject: [PATCH] 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 "