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
This commit is contained in:
Jakub Jezek 2023-12-08 12:59:50 +01:00
parent 839963915e
commit 4866f20f86
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
2 changed files with 40 additions and 5 deletions

View file

@ -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()

View file

@ -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 "