From fb4567560ec9973aab354c566bd1e00674190e5b Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 30 Aug 2023 14:53:04 +0200 Subject: [PATCH 01/28] colorspace: aggregating typed config context data --- openpype/scripts/ocio_wrapper.py | 36 +++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/openpype/scripts/ocio_wrapper.py b/openpype/scripts/ocio_wrapper.py index 16558642c6..e8a503e42e 100644 --- a/openpype/scripts/ocio_wrapper.py +++ b/openpype/scripts/ocio_wrapper.py @@ -96,11 +96,41 @@ def _get_colorspace_data(config_path): config = ocio.Config().CreateFromFile(str(config_path)) - return { - c.getName(): c.getFamily() - for c in config.getColorSpaces() + colorspace_data = { + color.getName(): { + "type": "colorspace", + "family": color.getFamily(), + "categories": list(color.getCategories()), + "aliases": list(color.getAliases()), + "equalitygroup": color.getEqualityGroup(), + } + for color in config.getColorSpaces() } + # add looks + looks = config.getLooks() + if looks: + colorspace_data.update({ + look.getName(): { + "type": "look", + "process_space": look.getProcessSpace() + } + for look in looks + }) + + # add roles + roles = config.getRoles() + if roles: + colorspace_data.update({ + role[0]: { + "type": "role", + "colorspace": role[1] + } + for role in roles + }) + + return colorspace_data + @config.command( name="get_views", From 3cc8c51ea2cb4bf9655bf3ae9cd5f53befb84b95 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 30 Aug 2023 14:53:58 +0200 Subject: [PATCH 02/28] traypublish: adding colorspace look product type publishing workflow --- .../plugins/create/create_colorspace_look.py | 185 ++++++++++++++++++ .../publish/collect_colorspace_look.py | 46 +++++ .../publish/extract_colorspace_look.py | 43 ++++ .../publish/validate_colorspace_look.py | 70 +++++++ openpype/plugins/publish/integrate.py | 1 + 5 files changed, 345 insertions(+) create mode 100644 openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py create mode 100644 openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py create mode 100644 openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py create mode 100644 openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py new file mode 100644 index 0000000000..62ecc391f6 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -0,0 +1,185 @@ +# -*- coding: utf-8 -*- +"""Creator of colorspace look files. + +This creator is used to publish colorspace look files thanks to +production type `ociolook`. All files are published as representation. +""" +from pathlib import Path + +from openpype.client import get_asset_by_name +from openpype.lib.attribute_definitions import ( + FileDef, EnumDef, TextDef, UISeparatorDef +) +from openpype.pipeline import ( + CreatedInstance, + CreatorError +) +from openpype.pipeline.create import ( + get_subset_name, + TaskNotSetError, +) +from openpype.pipeline import colorspace +from openpype.hosts.traypublisher.api.plugin import TrayPublishCreator + + +class CreateColorspaceLook(TrayPublishCreator): + """Creates colorspace look files.""" + + identifier = "io.openpype.creators.traypublisher.colorspace_look" + label = "Colorspace Look" + family = "ociolook" + description = "Publishes color space look file." + extensions = [".cc", ".cube", ".3dl", ".spi1d", ".spi3d", ".csp", ".lut"] + enabled = False + + colorspace_items = [ + (None, "Not set") + ] + colorspace_attr_show = False + + def get_detail_description(self): + return """# Colorspace Look + +This creator publishes color space look file (LUT). + """ + + def get_icon(self): + return "mdi.format-color-fill" + + def create(self, subset_name, instance_data, pre_create_data): + repr_file = pre_create_data.get("luts_file") + if not repr_file: + raise CreatorError("No files specified") + + files = repr_file.get("filenames") + if not files: + # this should never happen + raise CreatorError("Missing files from representation") + + asset_doc = get_asset_by_name( + self.project_name, instance_data["asset"]) + + subset_name = self._get_subset( + asset_doc, instance_data["variant"], self.project_name, + instance_data["task"] + ) + + instance_data["creator_attributes"] = { + "abs_lut_path": ( + Path(repr_file["directory"]) / files[0]).as_posix() + } + + # Create new instance + new_instance = CreatedInstance(self.family, subset_name, + instance_data, self) + self._store_new_instance(new_instance) + + def get_instance_attr_defs(self): + return [ + EnumDef( + "working_colorspace", + self.colorspace_items, + default="Not set", + label="Working Colorspace", + ), + UISeparatorDef( + label="Advanced1" + ), + TextDef( + "abs_lut_path", + label="LUT Path", + ), + EnumDef( + "input_colorspace", + self.colorspace_items, + default="Not set", + label="Input Colorspace", + ), + EnumDef( + "direction", + [ + (None, "Not set"), + ("forward", "Forward"), + ("inverse", "Inverse") + ], + default="Not set", + label="Direction" + ), + EnumDef( + "interpolation", + [ + (None, "Not set"), + ("linear", "Linear"), + ("tetrahedral", "Tetrahedral"), + ("best", "Best"), + ("nearest", "Nearest") + ], + default="Not set", + label="Interpolation" + ), + EnumDef( + "output_colorspace", + self.colorspace_items, + default="Not set", + label="Output Colorspace", + ), + ] + + def get_pre_create_attr_defs(self): + return [ + FileDef( + "luts_file", + folders=False, + extensions=self.extensions, + allow_sequences=False, + single_item=True, + label="Look Files", + ) + ] + + def apply_settings(self, project_settings, system_settings): + host = self.create_context.host + host_name = host.name + project_name = host.get_current_project_name() + config_data = colorspace.get_imageio_config( + project_name, host_name, + project_settings=project_settings + ) + + if config_data: + filepath = config_data["path"] + config_items = colorspace.get_ocio_config_colorspaces(filepath) + + self.colorspace_items.extend(( + (name, f"{name} [{data_['type']}]") + for name, data_ in config_items.items() + if data_.get("type") == "colorspace" + )) + self.enabled = True + + def _get_subset(self, asset_doc, variant, project_name, task_name=None): + """Create subset name according to standard template process""" + + try: + subset_name = get_subset_name( + self.family, + variant, + task_name, + asset_doc, + project_name + ) + except TaskNotSetError: + # Create instance with fake task + # - instance will be marked as invalid so it can't be published + # but user have ability to change it + # NOTE: This expect that there is not task 'Undefined' on asset + task_name = "Undefined" + subset_name = get_subset_name( + self.family, + variant, + task_name, + asset_doc, + project_name + ) + + return subset_name diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py new file mode 100644 index 0000000000..739ab33f9c --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py @@ -0,0 +1,46 @@ +import os +import pyblish.api +from openpype.pipeline import publish + + +class CollectColorspaceLook(pyblish.api.InstancePlugin, + publish.OpenPypePyblishPluginMixin): + """Collect OCIO colorspace look from LUT file + """ + + label = "Collect Colorspace Look" + order = pyblish.api.CollectorOrder + hosts = ["traypublisher"] + families = ["ociolook"] + + def process(self, instance): + creator_attrs = instance.data["creator_attributes"] + + lut_repre_name = "LUTfile" + file_url = creator_attrs["abs_lut_path"] + file_name = os.path.basename(file_url) + _, ext = os.path.splitext(file_name) + + # create lut representation data + lut_repre = { + "name": lut_repre_name, + "ext": ext.lstrip("."), + "files": file_name, + "stagingDir": os.path.dirname(file_url), + "tags": [] + } + instance.data.update({ + "representations": [lut_repre], + "source": file_url, + "ocioLookItems": [ + { + "name": lut_repre_name, + "ext": ext.lstrip("."), + "working_colorspace": creator_attrs["working_colorspace"], + "input_colorspace": creator_attrs["input_colorspace"], + "output_colorspace": creator_attrs["output_colorspace"], + "direction": creator_attrs["direction"], + "interpolation": creator_attrs["interpolation"] + } + ] + }) diff --git a/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py new file mode 100644 index 0000000000..ffd877af1d --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py @@ -0,0 +1,43 @@ +import os +import json +import pyblish.api +from openpype.pipeline import publish + + +class ExtractColorspaceLook(publish.Extractor, + publish.OpenPypePyblishPluginMixin): + """Extract OCIO colorspace look from LUT file + """ + + label = "Extract Colorspace Look" + order = pyblish.api.ExtractorOrder + hosts = ["traypublisher"] + families = ["ociolook"] + + def process(self, instance): + ociolook_items = instance.data["ocioLookItems"] + staging_dir = self.staging_dir(instance) + + # create ociolook file attributes + ociolook_file_name = "ocioLookFile.json" + ociolook_file_content = { + "version": 1, + "data": { + "ocioLookItems": ociolook_items + } + } + + # write ociolook content into json file saved in staging dir + file_url = os.path.join(staging_dir, ociolook_file_name) + with open(file_url, "w") as f_: + json.dump(ociolook_file_content, f_, indent=4) + + # create lut representation data + ociolook_repre = { + "name": "ocioLookFile", + "ext": "json", + "files": ociolook_file_name, + "stagingDir": staging_dir, + "tags": [] + } + instance.data["representations"].append(ociolook_repre) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py new file mode 100644 index 0000000000..7de8881321 --- /dev/null +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py @@ -0,0 +1,70 @@ +import pyblish.api + +from openpype.pipeline import ( + publish, + PublishValidationError +) + + +class ValidateColorspaceLook(pyblish.api.InstancePlugin, + publish.OpenPypePyblishPluginMixin): + """Validate colorspace look attributes""" + + label = "Validate colorspace look attributes" + order = pyblish.api.ValidatorOrder + hosts = ["traypublisher"] + families = ["ociolook"] + + def process(self, instance): + create_context = instance.context.data["create_context"] + created_instance = create_context.get_instance_by_id( + instance.data["instance_id"]) + creator_defs = created_instance.creator_attribute_defs + + ociolook_items = instance.data.get("ocioLookItems", []) + + for ociolook_item in ociolook_items: + self.validate_colorspace_set_attrs(ociolook_item, creator_defs) + + def validate_colorspace_set_attrs(self, ociolook_item, creator_defs): + """Validate colorspace look attributes""" + + self.log.debug(f"Validate colorspace look attributes: {ociolook_item}") + self.log.debug(f"Creator defs: {creator_defs}") + + check_keys = [ + "working_colorspace", + "input_colorspace", + "output_colorspace", + "direction", + "interpolation" + ] + not_set_keys = [] + for key in check_keys: + if ociolook_item[key]: + # key is set and it is correct + continue + + def_label = next( + (d_.label for d_ in creator_defs if key == d_.key), + None + ) + if not def_label: + def_attrs = [(d_.key, d_.label) for d_ in creator_defs] + # raise since key is not recognized by creator defs + raise KeyError( + f"Colorspace look attribute '{key}' is not " + f"recognized by creator attributes: {def_attrs}" + ) + not_set_keys.append(def_label) + + if not_set_keys: + message = ( + f"Colorspace look attributes are not set: " + f"{', '.join(not_set_keys)}" + ) + raise PublishValidationError( + title="Colorspace Look attributes", + message=message, + description=message + ) diff --git a/openpype/plugins/publish/integrate.py b/openpype/plugins/publish/integrate.py index be07cffe72..fe4bfc81f6 100644 --- a/openpype/plugins/publish/integrate.py +++ b/openpype/plugins/publish/integrate.py @@ -107,6 +107,7 @@ class IntegrateAsset(pyblish.api.InstancePlugin): "rig", "plate", "look", + "ociolook", "audio", "yetiRig", "yeticache", From 7727a017da8e0a27debae5dd5c0a3140adab3803 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 30 Aug 2023 14:57:22 +0200 Subject: [PATCH 03/28] filtering families into explicit colorspace --- .../traypublisher/plugins/publish/collect_explicit_colorspace.py | 1 + .../hosts/traypublisher/plugins/publish/validate_colorspace.py | 1 + 2 files changed, 2 insertions(+) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index eb7fbd87a0..860c36ccf8 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -13,6 +13,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, label = "Choose representation colorspace" order = pyblish.api.CollectorOrder + 0.49 hosts = ["traypublisher"] + families = ["render", "plate", "reference", "image", "online"] colorspace_items = [ (None, "Don't override") diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py index 75b41cf606..03f9f299b2 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace.py @@ -18,6 +18,7 @@ class ValidateColorspace(pyblish.api.InstancePlugin, label = "Validate representation colorspace" order = pyblish.api.ValidatorOrder hosts = ["traypublisher"] + families = ["render", "plate", "reference", "image", "online"] def process(self, instance): From 74ca6a3c44071035e9c3ef5a1ae22cd077647cee Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 30 Aug 2023 14:58:15 +0200 Subject: [PATCH 04/28] explicit colorspace includes types and aliases to offered colorspace --- .../publish/collect_explicit_colorspace.py | 24 ++++++++++++++++--- 1 file changed, 21 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 860c36ccf8..be8cf20e22 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -1,5 +1,4 @@ import pyblish.api -from openpype.pipeline import registered_host from openpype.pipeline import publish from openpype.lib import EnumDef from openpype.pipeline import colorspace @@ -38,7 +37,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, @classmethod def apply_settings(cls, project_settings): - host = registered_host() + host = self.create_context.host host_name = host.name project_name = host.get_current_project_name() config_data = colorspace.get_imageio_config( @@ -49,9 +48,28 @@ class CollectColorspace(pyblish.api.InstancePlugin, if config_data: filepath = config_data["path"] config_items = colorspace.get_ocio_config_colorspaces(filepath) + aliases = set() + for _, value_ in config_items.items(): + if value_.get("type") != "colorspace": + continue + if not value_.get("aliases"): + continue + for alias in value_.get("aliases"): + aliases.add(alias) + + colorspaces = { + name + for name, data_ in config_items.items() + if name not in aliases and data_.get("type") == "colorspace" + } + cls.colorspace_items.extend(( - (name, name) for name in config_items.keys() + (name, name) for name in colorspaces )) + if aliases: + cls.colorspace_items.extend(( + (name, name) for name in aliases + )) cls.colorspace_attr_show = True @classmethod From a10206c05493bee85ca2c2bf92818bbb1fb3bdc1 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 30 Aug 2023 15:24:56 +0200 Subject: [PATCH 05/28] explicit colorspace switch and item labeling --- .../publish/collect_explicit_colorspace.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index be8cf20e22..08479b8363 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -1,5 +1,8 @@ import pyblish.api -from openpype.pipeline import publish +from openpype.pipeline import ( + publish, + registered_host +) from openpype.lib import EnumDef from openpype.pipeline import colorspace @@ -13,6 +16,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, order = pyblish.api.CollectorOrder + 0.49 hosts = ["traypublisher"] families = ["render", "plate", "reference", "image", "online"] + enabled = False colorspace_items = [ (None, "Don't override") @@ -37,7 +41,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, @classmethod def apply_settings(cls, project_settings): - host = self.create_context.host + host = registered_host() host_name = host.name project_name = host.get_current_project_name() config_data = colorspace.get_imageio_config( @@ -46,6 +50,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, ) if config_data: + filepath = config_data["path"] config_items = colorspace.get_ocio_config_colorspaces(filepath) aliases = set() @@ -58,19 +63,18 @@ class CollectColorspace(pyblish.api.InstancePlugin, aliases.add(alias) colorspaces = { - name - for name, data_ in config_items.items() - if name not in aliases and data_.get("type") == "colorspace" + name for name, data_ in config_items.items() + if data_.get("type") == "colorspace" } cls.colorspace_items.extend(( - (name, name) for name in colorspaces + (name, f"{name} [colorspace]") for name in colorspaces )) if aliases: cls.colorspace_items.extend(( - (name, name) for name in aliases + (name, f"{name} [alias]") for name in aliases )) - cls.colorspace_attr_show = True + cls.enabled = True @classmethod def get_attribute_defs(cls): @@ -79,7 +83,6 @@ class CollectColorspace(pyblish.api.InstancePlugin, "colorspace", cls.colorspace_items, default="Don't override", - label="Override Colorspace", - hidden=not cls.colorspace_attr_show + label="Override Colorspace" ) ] From 2317ab057f56138154308dc83bf5f510e6514052 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 3 Oct 2023 13:20:07 +0200 Subject: [PATCH 06/28] Update openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py Co-authored-by: Roy Nieterau --- .../traypublisher/plugins/publish/validate_colorspace_look.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py index 7de8881321..2a9b2040d1 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py @@ -60,7 +60,7 @@ class ValidateColorspaceLook(pyblish.api.InstancePlugin, if not_set_keys: message = ( - f"Colorspace look attributes are not set: " + "Colorspace look attributes are not set: " f"{', '.join(not_set_keys)}" ) raise PublishValidationError( From 774050eff300c28ea33ef58f5f5227cf66d94ea8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Je=C5=BEek?= Date: Tue, 3 Oct 2023 13:27:14 +0200 Subject: [PATCH 07/28] Update openpype/scripts/ocio_wrapper.py Co-authored-by: Roy Nieterau --- openpype/scripts/ocio_wrapper.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openpype/scripts/ocio_wrapper.py b/openpype/scripts/ocio_wrapper.py index 2bd25002c5..092d94623f 100644 --- a/openpype/scripts/ocio_wrapper.py +++ b/openpype/scripts/ocio_wrapper.py @@ -132,11 +132,11 @@ def _get_colorspace_data(config_path): roles = config.getRoles() if roles: colorspace_data.update({ - role[0]: { + role: { "type": "role", - "colorspace": role[1] + "colorspace": colorspace } - for role in roles + for (role, colorspace) in roles }) return colorspace_data From c30eb6ed4d9eea479e4bfd2f7235d941a0350f08 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 3 Oct 2023 13:32:39 +0200 Subject: [PATCH 08/28] improving creator def aggregation cycle in validator --- .../plugins/publish/validate_colorspace_look.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py index 7de8881321..c24bd6ee11 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py @@ -39,22 +39,21 @@ class ValidateColorspaceLook(pyblish.api.InstancePlugin, "direction", "interpolation" ] + creator_defs_by_key = {_def.key: _def.label for _def in creator_defs} + not_set_keys = [] for key in check_keys: if ociolook_item[key]: # key is set and it is correct continue - def_label = next( - (d_.label for d_ in creator_defs if key == d_.key), - None - ) + def_label = creator_defs_by_key.get(key) + if not def_label: - def_attrs = [(d_.key, d_.label) for d_ in creator_defs] # raise since key is not recognized by creator defs raise KeyError( f"Colorspace look attribute '{key}' is not " - f"recognized by creator attributes: {def_attrs}" + f"recognized by creator attributes: {creator_defs_by_key}" ) not_set_keys.append(def_label) From 1d0e55aa833d99180b99cbbd718954933c5103b2 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 13:00:42 +0200 Subject: [PATCH 09/28] improving colorspace categorization also adding new abstract function for returning all settings options nicely labelled --- .../plugins/create/create_colorspace_look.py | 13 ++-- .../publish/collect_explicit_colorspace.py | 29 ++----- openpype/pipeline/colorspace.py | 77 ++++++++++++++++++- openpype/scripts/ocio_wrapper.py | 33 ++++---- 4 files changed, 101 insertions(+), 51 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py index 62ecc391f6..3f3fa5348a 100644 --- a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -148,13 +148,12 @@ This creator publishes color space look file (LUT). if config_data: filepath = config_data["path"] - config_items = colorspace.get_ocio_config_colorspaces(filepath) - - self.colorspace_items.extend(( - (name, f"{name} [{data_['type']}]") - for name, data_ in config_items.items() - if data_.get("type") == "colorspace" - )) + labeled_colorspaces = colorspace.get_labeled_colorspaces( + filepath, + include_aliases=True, + include_roles=True + ) + self.colorspace_items.extend(labeled_colorspaces) self.enabled = True def _get_subset(self, asset_doc, variant, project_name, task_name=None): diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 08479b8363..06ceac5923 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -50,30 +50,13 @@ class CollectColorspace(pyblish.api.InstancePlugin, ) if config_data: - filepath = config_data["path"] - config_items = colorspace.get_ocio_config_colorspaces(filepath) - aliases = set() - for _, value_ in config_items.items(): - if value_.get("type") != "colorspace": - continue - if not value_.get("aliases"): - continue - for alias in value_.get("aliases"): - aliases.add(alias) - - colorspaces = { - name for name, data_ in config_items.items() - if data_.get("type") == "colorspace" - } - - cls.colorspace_items.extend(( - (name, f"{name} [colorspace]") for name in colorspaces - )) - if aliases: - cls.colorspace_items.extend(( - (name, f"{name} [alias]") for name in aliases - )) + labeled_colorspaces = colorspace.get_labeled_colorspaces( + filepath, + include_aliases=True, + include_roles=True + ) + cls.colorspace_items.extend(labeled_colorspaces) cls.enabled = True @classmethod diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 2800050496..39fdef046b 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -356,7 +356,10 @@ def parse_colorspace_from_filepath( "Must provide `config_path` if `colorspaces` is not provided." ) - colorspaces = colorspaces or get_ocio_config_colorspaces(config_path) + colorspaces = ( + colorspaces + or get_ocio_config_colorspaces(config_path)["colorspace"] + ) underscored_colorspaces = { key.replace(" ", "_"): key for key in colorspaces if " " in key @@ -393,7 +396,7 @@ def validate_imageio_colorspace_in_config(config_path, colorspace_name): Returns: bool: True if exists """ - colorspaces = get_ocio_config_colorspaces(config_path) + colorspaces = get_ocio_config_colorspaces(config_path)["colorspace"] if colorspace_name not in colorspaces: raise KeyError( "Missing colorspace '{}' in config file '{}'".format( @@ -530,6 +533,76 @@ def get_ocio_config_colorspaces(config_path): return CachedData.ocio_config_colorspaces[config_path] +def get_labeled_colorspaces( + config_path, + include_aliases=False, + include_looks=False, + include_roles=False, + +): + """Get all colorspace data with labels + + Wrapper function for aggregating all names and its families. + Families can be used for building menu and submenus in gui. + + Args: + config_path (str): path leading to config.ocio file + include_aliases (bool): include aliases in result + include_looks (bool): include looks in result + include_roles (bool): include roles in result + + Returns: + list[tuple[str,str]]: colorspace and family in couple + """ + config_items = get_ocio_config_colorspaces(config_path) + labeled_colorspaces = [] + aliases = set() + colorspaces = set() + looks = set() + roles = set() + for items_type, colorspace_items in config_items.items(): + if items_type == "colorspace": + for color_name, color_data in colorspace_items.items(): + if color_data.get("aliases"): + aliases.update([ + "{} ({})".format(alias_name, color_name) + for alias_name in color_data["aliases"] + ]) + colorspaces.add(color_name) + elif items_type == "look": + looks.update([ + "{} ({})".format(name, role_data["process_space"]) + for name, role_data in colorspace_items.items() + ]) + elif items_type == "role": + roles.update([ + "{} ({})".format(name, role_data["colorspace"]) + for name, role_data in colorspace_items.items() + ]) + + if roles and include_roles: + labeled_colorspaces.extend(( + (name, f"[role] {name}") for name in roles + )) + + labeled_colorspaces.extend(( + (name, f"[colorspace] {name}") for name in colorspaces + )) + + if aliases and include_aliases: + labeled_colorspaces.extend(( + (name, f"[alias] {name}") for name in aliases + )) + + if looks and include_looks: + labeled_colorspaces.extend(( + (name, f"[look] {name}") for name in looks + )) + + + return labeled_colorspaces + + # TODO: remove this in future - backward compatibility @deprecated("_get_wrapped_with_subprocess") def get_colorspace_data_subprocess(config_path): diff --git a/openpype/scripts/ocio_wrapper.py b/openpype/scripts/ocio_wrapper.py index 092d94623f..be21f0984f 100644 --- a/openpype/scripts/ocio_wrapper.py +++ b/openpype/scripts/ocio_wrapper.py @@ -107,37 +107,32 @@ def _get_colorspace_data(config_path): config = ocio.Config().CreateFromFile(str(config_path)) colorspace_data = { - color.getName(): { - "type": "colorspace", - "family": color.getFamily(), - "categories": list(color.getCategories()), - "aliases": list(color.getAliases()), - "equalitygroup": color.getEqualityGroup(), + "colorspace": { + color.getName(): { + "family": color.getFamily(), + "categories": list(color.getCategories()), + "aliases": list(color.getAliases()), + "equalitygroup": color.getEqualityGroup(), + } + for color in config.getColorSpaces() } - for color in config.getColorSpaces() } # add looks looks = config.getLooks() if looks: - colorspace_data.update({ - look.getName(): { - "type": "look", - "process_space": look.getProcessSpace() - } + colorspace_data["look"] = { + look.getName(): {"process_space": look.getProcessSpace()} for look in looks - }) + } # add roles roles = config.getRoles() if roles: - colorspace_data.update({ - role: { - "type": "role", - "colorspace": colorspace - } + colorspace_data["role"] = { + role: {"colorspace": colorspace} for (role, colorspace) in roles - }) + } return colorspace_data From af3ebd190cd9c2cbf71eaa3c16bbd7bee4632ed5 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 13:24:18 +0200 Subject: [PATCH 10/28] fix in labeling --- openpype/pipeline/colorspace.py | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 39fdef046b..c456baa70f 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -565,39 +565,33 @@ def get_labeled_colorspaces( for color_name, color_data in colorspace_items.items(): if color_data.get("aliases"): aliases.update([ - "{} ({})".format(alias_name, color_name) + (alias_name, "[alias] {} ({})".format(alias_name, color_name)) for alias_name in color_data["aliases"] ]) colorspaces.add(color_name) elif items_type == "look": looks.update([ - "{} ({})".format(name, role_data["process_space"]) + (name, "[look] {} ({})".format(name, role_data["process_space"])) for name, role_data in colorspace_items.items() ]) elif items_type == "role": roles.update([ - "{} ({})".format(name, role_data["colorspace"]) + (name, "[role] {} ({})".format(name, role_data["colorspace"])) for name, role_data in colorspace_items.items() ]) if roles and include_roles: - labeled_colorspaces.extend(( - (name, f"[role] {name}") for name in roles - )) + labeled_colorspaces.extend(roles) labeled_colorspaces.extend(( (name, f"[colorspace] {name}") for name in colorspaces )) if aliases and include_aliases: - labeled_colorspaces.extend(( - (name, f"[alias] {name}") for name in aliases - )) + labeled_colorspaces.extend(aliases) if looks and include_looks: - labeled_colorspaces.extend(( - (name, f"[look] {name}") for name in looks - )) + labeled_colorspaces.extend(looks) return labeled_colorspaces From 919540038ff969c966acb7fe098cc64da77363d7 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 13:24:41 +0200 Subject: [PATCH 11/28] unit testing of labeling --- .../pipeline/test_colorspace_labels.py | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 tests/unit/openpype/pipeline/test_colorspace_labels.py diff --git a/tests/unit/openpype/pipeline/test_colorspace_labels.py b/tests/unit/openpype/pipeline/test_colorspace_labels.py new file mode 100644 index 0000000000..a135c3258b --- /dev/null +++ b/tests/unit/openpype/pipeline/test_colorspace_labels.py @@ -0,0 +1,81 @@ +import unittest +from unittest.mock import patch +from openpype.pipeline.colorspace import get_labeled_colorspaces + + +class TestGetLabeledColorspaces(unittest.TestCase): + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_returns_list_of_tuples(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspace': { + 'sRGB': {}, + 'Rec.709': {}, + }, + 'look': { + 'sRGB to Rec.709': { + 'process_space': 'Rec.709', + }, + }, + 'role': { + 'reference': { + 'colorspace': 'sRGB', + }, + }, + } + result = get_labeled_colorspaces('config.ocio') + self.assertIsInstance(result, list) + self.assertTrue(all(isinstance(item, tuple) for item in result)) + + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_includes_colorspaces(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspace': { + 'sRGB': {} + }, + 'look': {}, + 'role': {}, + } + result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=False, include_roles=False) + self.assertEqual(result, [('sRGB', '[colorspace] sRGB')]) + + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_includes_aliases(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspace': { + 'sRGB': { + 'aliases': ['sRGB (D65)'], + }, + }, + 'look': {}, + 'role': {}, + } + result = get_labeled_colorspaces('config.ocio', include_aliases=True, include_looks=False, include_roles=False) + self.assertEqual(result, [('sRGB', '[colorspace] sRGB'), ('sRGB (D65)', '[alias] sRGB (D65) (sRGB)')]) + + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_includes_looks(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspace': {}, + 'look': { + 'sRGB to Rec.709': { + 'process_space': 'Rec.709', + }, + }, + 'role': {}, + } + result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=True, include_roles=False) + self.assertEqual(result, [('sRGB to Rec.709', '[look] sRGB to Rec.709 (Rec.709)')]) + + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_includes_roles(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspace': {}, + 'look': {}, + 'role': { + 'reference': { + 'colorspace': 'sRGB', + }, + }, + } + result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=False, include_roles=True) + self.assertEqual(result, [('reference', '[role] reference (sRGB)')]) From 7782c333dc6d4e0934b3f14dbb792730f9887eac Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 13:26:18 +0200 Subject: [PATCH 12/28] renaming test file --- ...space_labels.py => test_colorspace_get_labeled_colorspaces.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/unit/openpype/pipeline/{test_colorspace_labels.py => test_colorspace_get_labeled_colorspaces.py} (100%) diff --git a/tests/unit/openpype/pipeline/test_colorspace_labels.py b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py similarity index 100% rename from tests/unit/openpype/pipeline/test_colorspace_labels.py rename to tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py From 042d5d9d16546a6a0a57687a103870976f833141 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 19:10:26 +0200 Subject: [PATCH 13/28] colorspace types in plural also updating and fixing unit tests --- openpype/pipeline/colorspace.py | 23 ++++++++------ openpype/scripts/ocio_wrapper.py | 6 ++-- .../pipeline/publish/test_publish_plugins.py | 13 ++++---- ...test_colorspace_get_labeled_colorspaces.py | 30 +++++++++---------- 4 files changed, 38 insertions(+), 34 deletions(-) diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index c456baa70f..1088a15157 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -358,7 +358,7 @@ def parse_colorspace_from_filepath( colorspaces = ( colorspaces - or get_ocio_config_colorspaces(config_path)["colorspace"] + or get_ocio_config_colorspaces(config_path)["colorspaces"] ) underscored_colorspaces = { key.replace(" ", "_"): key for key in colorspaces @@ -396,7 +396,7 @@ def validate_imageio_colorspace_in_config(config_path, colorspace_name): Returns: bool: True if exists """ - colorspaces = get_ocio_config_colorspaces(config_path)["colorspace"] + colorspaces = get_ocio_config_colorspaces(config_path)["colorspaces"] if colorspace_name not in colorspaces: raise KeyError( "Missing colorspace '{}' in config file '{}'".format( @@ -561,20 +561,25 @@ def get_labeled_colorspaces( looks = set() roles = set() for items_type, colorspace_items in config_items.items(): - if items_type == "colorspace": + if items_type == "colorspaces": for color_name, color_data in colorspace_items.items(): if color_data.get("aliases"): aliases.update([ - (alias_name, "[alias] {} ({})".format(alias_name, color_name)) - for alias_name in color_data["aliases"] - ]) + ( + alias_name, + "[alias] {} ({})".format(alias_name, color_name) + ) + for alias_name in color_data["aliases"] + ]) colorspaces.add(color_name) - elif items_type == "look": + + elif items_type == "looks": looks.update([ (name, "[look] {} ({})".format(name, role_data["process_space"])) for name, role_data in colorspace_items.items() ]) - elif items_type == "role": + + elif items_type == "roles": roles.update([ (name, "[role] {} ({})".format(name, role_data["colorspace"])) for name, role_data in colorspace_items.items() @@ -583,6 +588,7 @@ def get_labeled_colorspaces( if roles and include_roles: labeled_colorspaces.extend(roles) + # add colorspace after roles so it is first in menu labeled_colorspaces.extend(( (name, f"[colorspace] {name}") for name in colorspaces )) @@ -593,7 +599,6 @@ def get_labeled_colorspaces( if looks and include_looks: labeled_colorspaces.extend(looks) - return labeled_colorspaces diff --git a/openpype/scripts/ocio_wrapper.py b/openpype/scripts/ocio_wrapper.py index be21f0984f..bca977cc3b 100644 --- a/openpype/scripts/ocio_wrapper.py +++ b/openpype/scripts/ocio_wrapper.py @@ -107,7 +107,7 @@ def _get_colorspace_data(config_path): config = ocio.Config().CreateFromFile(str(config_path)) colorspace_data = { - "colorspace": { + "colorspaces": { color.getName(): { "family": color.getFamily(), "categories": list(color.getCategories()), @@ -121,7 +121,7 @@ def _get_colorspace_data(config_path): # add looks looks = config.getLooks() if looks: - colorspace_data["look"] = { + colorspace_data["looks"] = { look.getName(): {"process_space": look.getProcessSpace()} for look in looks } @@ -129,7 +129,7 @@ def _get_colorspace_data(config_path): # add roles roles = config.getRoles() if roles: - colorspace_data["role"] = { + colorspace_data["roles"] = { role: {"colorspace": colorspace} for (role, colorspace) in roles } diff --git a/tests/unit/openpype/pipeline/publish/test_publish_plugins.py b/tests/unit/openpype/pipeline/publish/test_publish_plugins.py index aace8cf7e3..1f7f551237 100644 --- a/tests/unit/openpype/pipeline/publish/test_publish_plugins.py +++ b/tests/unit/openpype/pipeline/publish/test_publish_plugins.py @@ -37,7 +37,7 @@ class TestPipelinePublishPlugins(TestPipeline): # files are the same as those used in `test_pipeline_colorspace` TEST_FILES = [ ( - "1Lf-mFxev7xiwZCWfImlRcw7Fj8XgNQMh", + "1csqimz8bbNcNgxtEXklLz6GRv91D3KgA", "test_pipeline_colorspace.zip", "" ) @@ -123,8 +123,7 @@ class TestPipelinePublishPlugins(TestPipeline): def test_get_colorspace_settings(self, context, config_path_asset): expected_config_template = ( - "{root[work]}/{project[name]}" - "/{hierarchy}/{asset}/config/aces.ocio" + "{root[work]}/{project[name]}/config/aces.ocio" ) expected_file_rules = { "comp_review": { @@ -177,16 +176,16 @@ class TestPipelinePublishPlugins(TestPipeline): # load plugin function for testing plugin = publish_plugins.ColormanagedPyblishPluginMixin() plugin.log = log + context.data["imageioSettings"] = (config_data_nuke, file_rules_nuke) plugin.set_representation_colorspace( - representation_nuke, context, - colorspace_settings=(config_data_nuke, file_rules_nuke) + representation_nuke, context ) # load plugin function for testing plugin = publish_plugins.ColormanagedPyblishPluginMixin() plugin.log = log + context.data["imageioSettings"] = (config_data_hiero, file_rules_hiero) plugin.set_representation_colorspace( - representation_hiero, context, - colorspace_settings=(config_data_hiero, file_rules_hiero) + representation_hiero, context ) colorspace_data_nuke = representation_nuke.get("colorspaceData") diff --git a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py index a135c3258b..ae3e4117bc 100644 --- a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py +++ b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py @@ -7,16 +7,16 @@ class TestGetLabeledColorspaces(unittest.TestCase): @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_returns_list_of_tuples(self, mock_get_ocio_config_colorspaces): mock_get_ocio_config_colorspaces.return_value = { - 'colorspace': { + 'colorspaces': { 'sRGB': {}, 'Rec.709': {}, }, - 'look': { + 'looks': { 'sRGB to Rec.709': { 'process_space': 'Rec.709', }, }, - 'role': { + 'roles': { 'reference': { 'colorspace': 'sRGB', }, @@ -29,11 +29,11 @@ class TestGetLabeledColorspaces(unittest.TestCase): @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_colorspaces(self, mock_get_ocio_config_colorspaces): mock_get_ocio_config_colorspaces.return_value = { - 'colorspace': { + 'colorspaces': { 'sRGB': {} }, - 'look': {}, - 'role': {}, + 'looks': {}, + 'roles': {}, } result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=False, include_roles=False) self.assertEqual(result, [('sRGB', '[colorspace] sRGB')]) @@ -41,13 +41,13 @@ class TestGetLabeledColorspaces(unittest.TestCase): @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_aliases(self, mock_get_ocio_config_colorspaces): mock_get_ocio_config_colorspaces.return_value = { - 'colorspace': { + 'colorspaces': { 'sRGB': { 'aliases': ['sRGB (D65)'], }, }, - 'look': {}, - 'role': {}, + 'looks': {}, + 'roles': {}, } result = get_labeled_colorspaces('config.ocio', include_aliases=True, include_looks=False, include_roles=False) self.assertEqual(result, [('sRGB', '[colorspace] sRGB'), ('sRGB (D65)', '[alias] sRGB (D65) (sRGB)')]) @@ -55,13 +55,13 @@ class TestGetLabeledColorspaces(unittest.TestCase): @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_looks(self, mock_get_ocio_config_colorspaces): mock_get_ocio_config_colorspaces.return_value = { - 'colorspace': {}, - 'look': { + 'colorspaces': {}, + 'looks': { 'sRGB to Rec.709': { 'process_space': 'Rec.709', }, }, - 'role': {}, + 'roles': {}, } result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=True, include_roles=False) self.assertEqual(result, [('sRGB to Rec.709', '[look] sRGB to Rec.709 (Rec.709)')]) @@ -69,9 +69,9 @@ class TestGetLabeledColorspaces(unittest.TestCase): @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_roles(self, mock_get_ocio_config_colorspaces): mock_get_ocio_config_colorspaces.return_value = { - 'colorspace': {}, - 'look': {}, - 'role': { + 'colorspaces': {}, + 'looks': {}, + 'roles': { 'reference': { 'colorspace': 'sRGB', }, From 957a713db216c82f9e30d01c8aecea7f2ac36663 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 4 Oct 2023 20:04:06 +0200 Subject: [PATCH 14/28] adding display and views --- openpype/pipeline/colorspace.py | 11 +++++++++++ openpype/scripts/ocio_wrapper.py | 13 ++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 1088a15157..8985b07cde 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -538,6 +538,7 @@ def get_labeled_colorspaces( include_aliases=False, include_looks=False, include_roles=False, + include_display_views=False ): """Get all colorspace data with labels @@ -560,6 +561,7 @@ def get_labeled_colorspaces( colorspaces = set() looks = set() roles = set() + display_views = set() for items_type, colorspace_items in config_items.items(): if items_type == "colorspaces": for color_name, color_data in colorspace_items.items(): @@ -579,6 +581,12 @@ def get_labeled_colorspaces( for name, role_data in colorspace_items.items() ]) + elif items_type == "displays_views": + display_views.update([ + (name, "[view (display)] {}".format(name)) + for name, _ in colorspace_items.items() + ]) + elif items_type == "roles": roles.update([ (name, "[role] {} ({})".format(name, role_data["colorspace"])) @@ -599,6 +607,9 @@ def get_labeled_colorspaces( if looks and include_looks: labeled_colorspaces.extend(looks) + if display_views and include_display_views: + labeled_colorspaces.extend(display_views) + return labeled_colorspaces diff --git a/openpype/scripts/ocio_wrapper.py b/openpype/scripts/ocio_wrapper.py index bca977cc3b..fa231cd047 100644 --- a/openpype/scripts/ocio_wrapper.py +++ b/openpype/scripts/ocio_wrapper.py @@ -107,6 +107,7 @@ def _get_colorspace_data(config_path): config = ocio.Config().CreateFromFile(str(config_path)) colorspace_data = { + "roles": {}, "colorspaces": { color.getName(): { "family": color.getFamily(), @@ -115,7 +116,17 @@ def _get_colorspace_data(config_path): "equalitygroup": color.getEqualityGroup(), } for color in config.getColorSpaces() - } + }, + "displays_views": { + f"{view} ({display})": { + "display": display, + "view": view + + } + for display in config.getDisplays() + for view in config.getViews(display) + }, + "looks": {} } # add looks From db029884b0cc2d527dceac07ed0dd85663b1f48f Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Oct 2023 11:57:48 +0200 Subject: [PATCH 15/28] colorspace labeled unittests for display and view --- ...test_colorspace_get_labeled_colorspaces.py | 57 +++++++++++++++++-- 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py index ae3e4117bc..1760000e45 100644 --- a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py +++ b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py @@ -35,7 +35,12 @@ class TestGetLabeledColorspaces(unittest.TestCase): 'looks': {}, 'roles': {}, } - result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=False, include_roles=False) + result = get_labeled_colorspaces( + 'config.ocio', + include_aliases=False, + include_looks=False, + include_roles=False + ) self.assertEqual(result, [('sRGB', '[colorspace] sRGB')]) @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') @@ -49,8 +54,18 @@ class TestGetLabeledColorspaces(unittest.TestCase): 'looks': {}, 'roles': {}, } - result = get_labeled_colorspaces('config.ocio', include_aliases=True, include_looks=False, include_roles=False) - self.assertEqual(result, [('sRGB', '[colorspace] sRGB'), ('sRGB (D65)', '[alias] sRGB (D65) (sRGB)')]) + result = get_labeled_colorspaces( + 'config.ocio', + include_aliases=True, + include_looks=False, + include_roles=False + ) + self.assertEqual( + result, [ + ('sRGB', '[colorspace] sRGB'), + ('sRGB (D65)', '[alias] sRGB (D65) (sRGB)') + ] + ) @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_looks(self, mock_get_ocio_config_colorspaces): @@ -63,8 +78,14 @@ class TestGetLabeledColorspaces(unittest.TestCase): }, 'roles': {}, } - result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=True, include_roles=False) - self.assertEqual(result, [('sRGB to Rec.709', '[look] sRGB to Rec.709 (Rec.709)')]) + result = get_labeled_colorspaces( + 'config.ocio', + include_aliases=False, + include_looks=True, + include_roles=False + ) + self.assertEqual( + result, [('sRGB to Rec.709', '[look] sRGB to Rec.709 (Rec.709)')]) @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') def test_includes_roles(self, mock_get_ocio_config_colorspaces): @@ -77,5 +98,29 @@ class TestGetLabeledColorspaces(unittest.TestCase): }, }, } - result = get_labeled_colorspaces('config.ocio', include_aliases=False, include_looks=False, include_roles=True) + result = get_labeled_colorspaces( + 'config.ocio', + include_aliases=False, + include_looks=False, + include_roles=True + ) self.assertEqual(result, [('reference', '[role] reference (sRGB)')]) + + @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') + def test_includes_display_views(self, mock_get_ocio_config_colorspaces): + mock_get_ocio_config_colorspaces.return_value = { + 'colorspaces': {}, + 'looks': {}, + 'roles': {}, + 'displays_views': { + 'sRGB (ACES)': { + 'view': 'sRGB', + 'display': 'ACES', + }, + }, + } + result = get_labeled_colorspaces( + 'config.ocio', + include_display_views=True + ) + self.assertEqual(result, [('sRGB (ACES)', '[view (display)] sRGB (ACES)')]) From 9d6340a8a18a0e41651580a38fedbb9dec732f5c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Oct 2023 17:03:54 +0200 Subject: [PATCH 16/28] colorspace: add`convert_colorspace_enumerator_item` - improving unittests - adding unittest for `convert_colorspace_enumerator_item` - separating `config_items` from `get_colorspaces_enumerator_items` so they can be stored in context --- .../plugins/create/create_colorspace_look.py | 7 +- .../publish/collect_explicit_colorspace.py | 7 +- openpype/pipeline/colorspace.py | 94 ++++++++++--- ...pace_convert_colorspace_enumerator_item.py | 118 ++++++++++++++++ ...rspace_get_colorspaces_enumerator_items.py | 114 ++++++++++++++++ ...test_colorspace_get_labeled_colorspaces.py | 126 ------------------ 6 files changed, 321 insertions(+), 145 deletions(-) create mode 100644 tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py create mode 100644 tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py delete mode 100644 tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py index 3f3fa5348a..3e1c20d96a 100644 --- a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -36,6 +36,7 @@ class CreateColorspaceLook(TrayPublishCreator): (None, "Not set") ] colorspace_attr_show = False + config_items = None def get_detail_description(self): return """# Colorspace Look @@ -148,11 +149,13 @@ This creator publishes color space look file (LUT). if config_data: filepath = config_data["path"] - labeled_colorspaces = colorspace.get_labeled_colorspaces( - filepath, + config_items = colorspace.get_ocio_config_colorspaces(filepath) + labeled_colorspaces = colorspace.get_colorspaces_enumerator_items( + config_items, include_aliases=True, include_roles=True ) + self.config_items = config_items self.colorspace_items.extend(labeled_colorspaces) self.enabled = True diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py index 06ceac5923..5db2b0cbad 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_explicit_colorspace.py @@ -22,6 +22,7 @@ class CollectColorspace(pyblish.api.InstancePlugin, (None, "Don't override") ] colorspace_attr_show = False + config_items = None def process(self, instance): values = self.get_attr_values_from_data(instance.data) @@ -51,11 +52,13 @@ class CollectColorspace(pyblish.api.InstancePlugin, if config_data: filepath = config_data["path"] - labeled_colorspaces = colorspace.get_labeled_colorspaces( - filepath, + config_items = colorspace.get_ocio_config_colorspaces(filepath) + labeled_colorspaces = colorspace.get_colorspaces_enumerator_items( + config_items, include_aliases=True, include_roles=True ) + cls.config_items = config_items cls.colorspace_items.extend(labeled_colorspaces) cls.enabled = True diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 8985b07cde..8bebc934fc 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -1,4 +1,3 @@ -from copy import deepcopy import re import os import json @@ -7,6 +6,7 @@ import functools import platform import tempfile import warnings +from copy import deepcopy from openpype import PACKAGE_DIR from openpype.settings import get_project_settings @@ -533,13 +533,63 @@ def get_ocio_config_colorspaces(config_path): return CachedData.ocio_config_colorspaces[config_path] -def get_labeled_colorspaces( - config_path, +def convert_colorspace_enumerator_item( + colorspace_enum_item, + config_items +): + """Convert colorspace enumerator item to dictionary + + Args: + colorspace_item (str): colorspace and family in couple + config_items (dict[str,dict]): colorspace data + + Returns: + dict: colorspace data + """ + # split string with `::` separator and set first as key and second as value + item_type, item_name = colorspace_enum_item.split("::") + + item_data = None + if item_type == "aliases": + # loop through all colorspaces and find matching alias + for name, _data in config_items.get("colorspaces", {}).items(): + if item_name in _data.get("aliases", []): + item_data = deepcopy(_data) + item_data.update({ + "name": name, + "type": "colorspace" + }) + break + else: + # find matching colorspace item found in labeled_colorspaces + item_data = config_items.get(item_type, {}).get(item_name) + if item_data: + item_data = deepcopy(item_data) + item_data.update({ + "name": item_name, + "type": item_type + }) + + # raise exception if item is not found + if not item_data: + message_config_keys = ", ".join( + "'{}':{}".format(key, set(config_items.get(key, {}).keys())) for key in config_items.keys() + ) + raise KeyError( + "Missing colorspace item '{}' in config data: [{}]".format( + colorspace_enum_item, message_config_keys + ) + ) + + return item_data + + +def get_colorspaces_enumerator_items( + config_items, include_aliases=False, include_looks=False, include_roles=False, include_display_views=False - ): """Get all colorspace data with labels @@ -547,7 +597,7 @@ def get_labeled_colorspaces( Families can be used for building menu and submenus in gui. Args: - config_path (str): path leading to config.ocio file + config_items (dict[str,dict]): colorspace data include_aliases (bool): include aliases in result include_looks (bool): include looks in result include_roles (bool): include roles in result @@ -555,7 +605,6 @@ def get_labeled_colorspaces( Returns: list[tuple[str,str]]: colorspace and family in couple """ - config_items = get_ocio_config_colorspaces(config_path) labeled_colorspaces = [] aliases = set() colorspaces = set() @@ -568,46 +617,61 @@ def get_labeled_colorspaces( if color_data.get("aliases"): aliases.update([ ( - alias_name, + "aliases::{}".format(alias_name), "[alias] {} ({})".format(alias_name, color_name) ) for alias_name in color_data["aliases"] ]) - colorspaces.add(color_name) + colorspaces.add(( + "{}::{}".format(items_type, color_name), + "[colorspace] {}".format(color_name) + )) elif items_type == "looks": looks.update([ - (name, "[look] {} ({})".format(name, role_data["process_space"])) + ( + "{}::{}".format(items_type, name), + "[look] {} ({})".format(name, role_data["process_space"]) + ) for name, role_data in colorspace_items.items() ]) elif items_type == "displays_views": display_views.update([ - (name, "[view (display)] {}".format(name)) + ( + "{}::{}".format(items_type, name), + "[view (display)] {}".format(name) + ) for name, _ in colorspace_items.items() ]) elif items_type == "roles": roles.update([ - (name, "[role] {} ({})".format(name, role_data["colorspace"])) + ( + "{}::{}".format(items_type, name), + "[role] {} ({})".format(name, role_data["colorspace"]) + ) for name, role_data in colorspace_items.items() ]) if roles and include_roles: + roles = sorted(roles, key=lambda x: x[0]) labeled_colorspaces.extend(roles) - # add colorspace after roles so it is first in menu - labeled_colorspaces.extend(( - (name, f"[colorspace] {name}") for name in colorspaces - )) + # add colorspaces as second so it is not first in menu + colorspaces = sorted(colorspaces, key=lambda x: x[0]) + labeled_colorspaces.extend(colorspaces) if aliases and include_aliases: + aliases = sorted(aliases, key=lambda x: x[0]) labeled_colorspaces.extend(aliases) if looks and include_looks: + looks = sorted(looks, key=lambda x: x[0]) labeled_colorspaces.extend(looks) if display_views and include_display_views: + display_views = sorted(display_views, key=lambda x: x[0]) labeled_colorspaces.extend(display_views) return labeled_colorspaces diff --git a/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py b/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py new file mode 100644 index 0000000000..bffe8eda90 --- /dev/null +++ b/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py @@ -0,0 +1,118 @@ +from ast import alias +import unittest +from openpype.pipeline.colorspace import convert_colorspace_enumerator_item + + +class TestConvertColorspaceEnumeratorItem(unittest.TestCase): + def setUp(self): + self.config_items = { + "colorspaces": { + "sRGB": { + "aliases": ["sRGB_1"], + "family": "colorspace", + "categories": ["colors"], + "equalitygroup": "equalitygroup", + }, + "Rec.709": { + "aliases": ["rec709_1", "rec709_2"], + }, + }, + "looks": { + "sRGB_to_Rec.709": { + "process_space": "sRGB", + }, + }, + "displays_views": { + "sRGB (ACES)": { + "view": "sRGB", + "display": "ACES", + }, + "Rec.709 (ACES)": { + "view": "Rec.709", + "display": "ACES", + }, + }, + "roles": { + "compositing_linear": { + "colorspace": "linear", + }, + }, + } + + def test_valid_item(self): + colorspace_item_data = convert_colorspace_enumerator_item( + "colorspaces::sRGB", self.config_items) + self.assertEqual( + colorspace_item_data, + { + "name": "sRGB", + "type": "colorspaces", + "aliases": ["sRGB_1"], + "family": "colorspace", + "categories": ["colors"], + "equalitygroup": "equalitygroup" + } + ) + + alias_item_data = convert_colorspace_enumerator_item( + "aliases::rec709_1", self.config_items) + self.assertEqual( + alias_item_data, + { + "aliases": ["rec709_1", "rec709_2"], + "name": "Rec.709", + "type": "colorspace" + } + ) + + display_view_item_data = convert_colorspace_enumerator_item( + "displays_views::sRGB (ACES)", self.config_items) + self.assertEqual( + display_view_item_data, + { + "type": "displays_views", + "name": "sRGB (ACES)", + "view": "sRGB", + "display": "ACES" + } + ) + + role_item_data = convert_colorspace_enumerator_item( + "roles::compositing_linear", self.config_items) + self.assertEqual( + role_item_data, + { + "name": "compositing_linear", + "type": "roles", + "colorspace": "linear" + } + ) + + look_item_data = convert_colorspace_enumerator_item( + "looks::sRGB_to_Rec.709", self.config_items) + self.assertEqual( + look_item_data, + { + "type": "looks", + "name": "sRGB_to_Rec.709", + "process_space": "sRGB" + } + ) + + def test_invalid_item(self): + config_items = { + "RGB": { + "sRGB": {"red": 255, "green": 255, "blue": 255}, + "AdobeRGB": {"red": 255, "green": 255, "blue": 255}, + } + } + with self.assertRaises(KeyError): + convert_colorspace_enumerator_item("RGB::invalid", config_items) + + def test_missing_config_data(self): + config_items = {} + with self.assertRaises(KeyError): + convert_colorspace_enumerator_item("RGB::sRGB", config_items) + +if __name__ == '__main__': + unittest.main() diff --git a/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py b/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py new file mode 100644 index 0000000000..de3e333670 --- /dev/null +++ b/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py @@ -0,0 +1,114 @@ +import unittest + +from openpype.pipeline.colorspace import get_colorspaces_enumerator_items + + +class TestGetColorspacesEnumeratorItems(unittest.TestCase): + def setUp(self): + self.config_items = { + "colorspaces": { + "sRGB": { + "aliases": ["sRGB_1"], + }, + "Rec.709": { + "aliases": ["rec709_1", "rec709_2"], + }, + }, + "looks": { + "sRGB_to_Rec.709": { + "process_space": "sRGB", + }, + }, + "displays_views": { + "sRGB (ACES)": { + "view": "sRGB", + "display": "ACES", + }, + "Rec.709 (ACES)": { + "view": "Rec.709", + "display": "ACES", + }, + }, + "roles": { + "compositing_linear": { + "colorspace": "linear", + }, + }, + } + + def test_colorspaces(self): + result = get_colorspaces_enumerator_items(self.config_items) + expected = [ + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ] + self.assertEqual(result, expected) + + def test_aliases(self): + result = get_colorspaces_enumerator_items(self.config_items, include_aliases=True) + expected = [ + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ("aliases::rec709_1", "[alias] rec709_1 (Rec.709)"), + ("aliases::rec709_2", "[alias] rec709_2 (Rec.709)"), + ("aliases::sRGB_1", "[alias] sRGB_1 (sRGB)"), + ] + self.assertEqual(result, expected) + + def test_looks(self): + result = get_colorspaces_enumerator_items(self.config_items, include_looks=True) + expected = [ + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ("looks::sRGB_to_Rec.709", "[look] sRGB_to_Rec.709 (sRGB)"), + ] + self.assertEqual(result, expected) + + def test_display_views(self): + result = get_colorspaces_enumerator_items(self.config_items, include_display_views=True) + expected = [ + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), + ("displays_views::sRGB (ACES)", "[view (display)] sRGB (ACES)"), + + ] + self.assertEqual(result, expected) + + def test_roles(self): + result = get_colorspaces_enumerator_items(self.config_items, include_roles=True) + expected = [ + ("roles::compositing_linear", "[role] compositing_linear (linear)"), + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ] + self.assertEqual(result, expected) + + def test_all(self): + message_config_keys = ", ".join( + "'{}':{}".format(key, set(self.config_items.get(key, {}).keys())) for key in self.config_items.keys() + ) + print("Testing with config: [{}]".format(message_config_keys)) + result = get_colorspaces_enumerator_items( + self.config_items, + include_aliases=True, + include_looks=True, + include_roles=True, + include_display_views=True, + ) + expected = [ + ("roles::compositing_linear", "[role] compositing_linear (linear)"), + ("colorspaces::Rec.709", "[colorspace] Rec.709"), + ("colorspaces::sRGB", "[colorspace] sRGB"), + ("aliases::rec709_1", "[alias] rec709_1 (Rec.709)"), + ("aliases::rec709_2", "[alias] rec709_2 (Rec.709)"), + ("aliases::sRGB_1", "[alias] sRGB_1 (sRGB)"), + ("looks::sRGB_to_Rec.709", "[look] sRGB_to_Rec.709 (sRGB)"), + ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), + ("displays_views::sRGB (ACES)", "[view (display)] sRGB (ACES)"), + ] + self.assertEqual(result, expected) + + +if __name__ == "__main__": + unittest.main() diff --git a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py b/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py deleted file mode 100644 index 1760000e45..0000000000 --- a/tests/unit/openpype/pipeline/test_colorspace_get_labeled_colorspaces.py +++ /dev/null @@ -1,126 +0,0 @@ -import unittest -from unittest.mock import patch -from openpype.pipeline.colorspace import get_labeled_colorspaces - - -class TestGetLabeledColorspaces(unittest.TestCase): - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_returns_list_of_tuples(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': { - 'sRGB': {}, - 'Rec.709': {}, - }, - 'looks': { - 'sRGB to Rec.709': { - 'process_space': 'Rec.709', - }, - }, - 'roles': { - 'reference': { - 'colorspace': 'sRGB', - }, - }, - } - result = get_labeled_colorspaces('config.ocio') - self.assertIsInstance(result, list) - self.assertTrue(all(isinstance(item, tuple) for item in result)) - - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_includes_colorspaces(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': { - 'sRGB': {} - }, - 'looks': {}, - 'roles': {}, - } - result = get_labeled_colorspaces( - 'config.ocio', - include_aliases=False, - include_looks=False, - include_roles=False - ) - self.assertEqual(result, [('sRGB', '[colorspace] sRGB')]) - - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_includes_aliases(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': { - 'sRGB': { - 'aliases': ['sRGB (D65)'], - }, - }, - 'looks': {}, - 'roles': {}, - } - result = get_labeled_colorspaces( - 'config.ocio', - include_aliases=True, - include_looks=False, - include_roles=False - ) - self.assertEqual( - result, [ - ('sRGB', '[colorspace] sRGB'), - ('sRGB (D65)', '[alias] sRGB (D65) (sRGB)') - ] - ) - - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_includes_looks(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': {}, - 'looks': { - 'sRGB to Rec.709': { - 'process_space': 'Rec.709', - }, - }, - 'roles': {}, - } - result = get_labeled_colorspaces( - 'config.ocio', - include_aliases=False, - include_looks=True, - include_roles=False - ) - self.assertEqual( - result, [('sRGB to Rec.709', '[look] sRGB to Rec.709 (Rec.709)')]) - - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_includes_roles(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': {}, - 'looks': {}, - 'roles': { - 'reference': { - 'colorspace': 'sRGB', - }, - }, - } - result = get_labeled_colorspaces( - 'config.ocio', - include_aliases=False, - include_looks=False, - include_roles=True - ) - self.assertEqual(result, [('reference', '[role] reference (sRGB)')]) - - @patch('openpype.pipeline.colorspace.get_ocio_config_colorspaces') - def test_includes_display_views(self, mock_get_ocio_config_colorspaces): - mock_get_ocio_config_colorspaces.return_value = { - 'colorspaces': {}, - 'looks': {}, - 'roles': {}, - 'displays_views': { - 'sRGB (ACES)': { - 'view': 'sRGB', - 'display': 'ACES', - }, - }, - } - result = get_labeled_colorspaces( - 'config.ocio', - include_display_views=True - ) - self.assertEqual(result, [('sRGB (ACES)', '[view (display)] sRGB (ACES)')]) From 124c528c5ce4dcf9580defb0e0788e7548b2721c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Thu, 5 Oct 2023 18:24:22 +0200 Subject: [PATCH 17/28] colorspace: improving collected ocio lut data --- .../plugins/create/create_colorspace_look.py | 39 +++++++++++----- .../publish/collect_colorspace_look.py | 44 ++++++++++++++++--- 2 files changed, 66 insertions(+), 17 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py index 3e1c20d96a..0daffc728c 100644 --- a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -37,6 +37,7 @@ class CreateColorspaceLook(TrayPublishCreator): ] colorspace_attr_show = False config_items = None + config_data = None def get_detail_description(self): return """# Colorspace Look @@ -73,8 +74,20 @@ This creator publishes color space look file (LUT). # Create new instance new_instance = CreatedInstance(self.family, subset_name, instance_data, self) + new_instance.transient_data["config_items"] = self.config_items + new_instance.transient_data["config_data"] = self.config_data + self._store_new_instance(new_instance) + + def collect_instances(self): + super().collect_instances() + for instance in self.create_context.instances: + if instance.creator_identifier == self.identifier: + instance.transient_data["config_items"] = self.config_items + instance.transient_data["config_data"] = self.config_data + + def get_instance_attr_defs(self): return [ EnumDef( @@ -147,17 +160,21 @@ This creator publishes color space look file (LUT). project_settings=project_settings ) - if config_data: - filepath = config_data["path"] - config_items = colorspace.get_ocio_config_colorspaces(filepath) - labeled_colorspaces = colorspace.get_colorspaces_enumerator_items( - config_items, - include_aliases=True, - include_roles=True - ) - self.config_items = config_items - self.colorspace_items.extend(labeled_colorspaces) - self.enabled = True + if not config_data: + self.enabled = False + return + + filepath = config_data["path"] + config_items = colorspace.get_ocio_config_colorspaces(filepath) + labeled_colorspaces = colorspace.get_colorspaces_enumerator_items( + config_items, + include_aliases=True, + include_roles=True + ) + self.config_items = config_items + self.config_data = config_data + self.colorspace_items.extend(labeled_colorspaces) + self.enabled = True def _get_subset(self, asset_doc, variant, project_name, task_name=None): """Create subset name according to standard template process""" diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py index 739ab33f9c..4dc5348fb1 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py @@ -1,7 +1,8 @@ import os +from pprint import pformat import pyblish.api from openpype.pipeline import publish - +from openpype.pipeline import colorspace class CollectColorspaceLook(pyblish.api.InstancePlugin, publish.OpenPypePyblishPluginMixin): @@ -19,11 +20,36 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, lut_repre_name = "LUTfile" file_url = creator_attrs["abs_lut_path"] file_name = os.path.basename(file_url) - _, ext = os.path.splitext(file_name) + base_name, ext = os.path.splitext(file_name) + + # set output name with base_name which was cleared + # of all symbols and all parts were capitalized + output_name = (base_name.replace("_", " ") + .replace(".", " ") + .replace("-", " ") + .title() + .replace(" ", "")) + + + # get config items + config_items = instance.data["transientData"]["config_items"] + config_data = instance.data["transientData"]["config_data"] + + # get colorspace items + converted_color_data = {} + for colorspace_key in [ + "working_colorspace", + "input_colorspace", + "output_colorspace" + ]: + color_data = colorspace.convert_colorspace_enumerator_item( + creator_attrs[colorspace_key], config_items) + converted_color_data[colorspace_key] = color_data # create lut representation data lut_repre = { "name": lut_repre_name, + "output": output_name, "ext": ext.lstrip("."), "files": file_name, "stagingDir": os.path.dirname(file_url), @@ -36,11 +62,17 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, { "name": lut_repre_name, "ext": ext.lstrip("."), - "working_colorspace": creator_attrs["working_colorspace"], - "input_colorspace": creator_attrs["input_colorspace"], - "output_colorspace": creator_attrs["output_colorspace"], + "working_colorspace": converted_color_data[ + "working_colorspace"], + "input_colorspace": converted_color_data[ + "input_colorspace"], + "output_colorspace": converted_color_data[ + "output_colorspace"], "direction": creator_attrs["direction"], - "interpolation": creator_attrs["interpolation"] + "interpolation": creator_attrs["interpolation"], + "config_data": config_data } ] }) + + self.log.debug(pformat(instance.data)) From 9ff279d52f2a92471bf530a2664dafcbf9018c03 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 9 Oct 2023 16:07:32 +0200 Subject: [PATCH 18/28] using `self.get_subset_name` rather then own function --- .../plugins/create/create_colorspace_look.py | 39 +++---------------- 1 file changed, 5 insertions(+), 34 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py index 0daffc728c..a1b7896fba 100644 --- a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -14,10 +14,6 @@ from openpype.pipeline import ( CreatedInstance, CreatorError ) -from openpype.pipeline.create import ( - get_subset_name, - TaskNotSetError, -) from openpype.pipeline import colorspace from openpype.hosts.traypublisher.api.plugin import TrayPublishCreator @@ -61,9 +57,11 @@ This creator publishes color space look file (LUT). asset_doc = get_asset_by_name( self.project_name, instance_data["asset"]) - subset_name = self._get_subset( - asset_doc, instance_data["variant"], self.project_name, - instance_data["task"] + subset_name = self.get_subset_name( + variant=instance_data["variant"], + task_name=instance_data["task"] or "Not set", + project_name=self.project_name, + asset_doc=asset_doc, ) instance_data["creator_attributes"] = { @@ -175,30 +173,3 @@ This creator publishes color space look file (LUT). self.config_data = config_data self.colorspace_items.extend(labeled_colorspaces) self.enabled = True - - def _get_subset(self, asset_doc, variant, project_name, task_name=None): - """Create subset name according to standard template process""" - - try: - subset_name = get_subset_name( - self.family, - variant, - task_name, - asset_doc, - project_name - ) - except TaskNotSetError: - # Create instance with fake task - # - instance will be marked as invalid so it can't be published - # but user have ability to change it - # NOTE: This expect that there is not task 'Undefined' on asset - task_name = "Undefined" - subset_name = get_subset_name( - self.family, - variant, - task_name, - asset_doc, - project_name - ) - - return subset_name From 5c6a7b6b25f49bdd7da2e372d5d3172844ca8948 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 9 Oct 2023 16:13:25 +0200 Subject: [PATCH 19/28] hound suggestions --- openpype/pipeline/colorspace.py | 5 +++- ...pace_convert_colorspace_enumerator_item.py | 2 +- ...rspace_get_colorspaces_enumerator_items.py | 25 ++++++++++++------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 8bebc934fc..1dbe869ad9 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -573,7 +573,10 @@ def convert_colorspace_enumerator_item( # raise exception if item is not found if not item_data: message_config_keys = ", ".join( - "'{}':{}".format(key, set(config_items.get(key, {}).keys())) for key in config_items.keys() + "'{}':{}".format( + key, + set(config_items.get(key, {}).keys()) + ) for key in config_items.keys() ) raise KeyError( "Missing colorspace item '{}' in config data: [{}]".format( diff --git a/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py b/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py index bffe8eda90..56ac2a5d28 100644 --- a/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py +++ b/tests/unit/openpype/pipeline/test_colorspace_convert_colorspace_enumerator_item.py @@ -1,4 +1,3 @@ -from ast import alias import unittest from openpype.pipeline.colorspace import convert_colorspace_enumerator_item @@ -114,5 +113,6 @@ class TestConvertColorspaceEnumeratorItem(unittest.TestCase): with self.assertRaises(KeyError): convert_colorspace_enumerator_item("RGB::sRGB", config_items) + if __name__ == '__main__': unittest.main() diff --git a/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py b/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py index de3e333670..c221712d70 100644 --- a/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py +++ b/tests/unit/openpype/pipeline/test_colorspace_get_colorspaces_enumerator_items.py @@ -45,7 +45,8 @@ class TestGetColorspacesEnumeratorItems(unittest.TestCase): self.assertEqual(result, expected) def test_aliases(self): - result = get_colorspaces_enumerator_items(self.config_items, include_aliases=True) + result = get_colorspaces_enumerator_items( + self.config_items, include_aliases=True) expected = [ ("colorspaces::Rec.709", "[colorspace] Rec.709"), ("colorspaces::sRGB", "[colorspace] sRGB"), @@ -56,7 +57,8 @@ class TestGetColorspacesEnumeratorItems(unittest.TestCase): self.assertEqual(result, expected) def test_looks(self): - result = get_colorspaces_enumerator_items(self.config_items, include_looks=True) + result = get_colorspaces_enumerator_items( + self.config_items, include_looks=True) expected = [ ("colorspaces::Rec.709", "[colorspace] Rec.709"), ("colorspaces::sRGB", "[colorspace] sRGB"), @@ -65,20 +67,22 @@ class TestGetColorspacesEnumeratorItems(unittest.TestCase): self.assertEqual(result, expected) def test_display_views(self): - result = get_colorspaces_enumerator_items(self.config_items, include_display_views=True) + result = get_colorspaces_enumerator_items( + self.config_items, include_display_views=True) expected = [ ("colorspaces::Rec.709", "[colorspace] Rec.709"), ("colorspaces::sRGB", "[colorspace] sRGB"), - ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), + ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), # noqa: E501 ("displays_views::sRGB (ACES)", "[view (display)] sRGB (ACES)"), ] self.assertEqual(result, expected) def test_roles(self): - result = get_colorspaces_enumerator_items(self.config_items, include_roles=True) + result = get_colorspaces_enumerator_items( + self.config_items, include_roles=True) expected = [ - ("roles::compositing_linear", "[role] compositing_linear (linear)"), + ("roles::compositing_linear", "[role] compositing_linear (linear)"), # noqa: E501 ("colorspaces::Rec.709", "[colorspace] Rec.709"), ("colorspaces::sRGB", "[colorspace] sRGB"), ] @@ -86,7 +90,10 @@ class TestGetColorspacesEnumeratorItems(unittest.TestCase): def test_all(self): message_config_keys = ", ".join( - "'{}':{}".format(key, set(self.config_items.get(key, {}).keys())) for key in self.config_items.keys() + "'{}':{}".format( + key, + set(self.config_items.get(key, {}).keys()) + ) for key in self.config_items.keys() ) print("Testing with config: [{}]".format(message_config_keys)) result = get_colorspaces_enumerator_items( @@ -97,14 +104,14 @@ class TestGetColorspacesEnumeratorItems(unittest.TestCase): include_display_views=True, ) expected = [ - ("roles::compositing_linear", "[role] compositing_linear (linear)"), + ("roles::compositing_linear", "[role] compositing_linear (linear)"), # noqa: E501 ("colorspaces::Rec.709", "[colorspace] Rec.709"), ("colorspaces::sRGB", "[colorspace] sRGB"), ("aliases::rec709_1", "[alias] rec709_1 (Rec.709)"), ("aliases::rec709_2", "[alias] rec709_2 (Rec.709)"), ("aliases::sRGB_1", "[alias] sRGB_1 (sRGB)"), ("looks::sRGB_to_Rec.709", "[look] sRGB_to_Rec.709 (sRGB)"), - ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), + ("displays_views::Rec.709 (ACES)", "[view (display)] Rec.709 (ACES)"), # noqa: E501 ("displays_views::sRGB (ACES)", "[view (display)] sRGB (ACES)"), ] self.assertEqual(result, expected) From b9185af47fa0f631ff054dff62b1bb865e03f7cf Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 9 Oct 2023 16:30:38 +0200 Subject: [PATCH 20/28] hound and docstring suggestion --- .../traypublisher/plugins/create/create_colorspace_look.py | 2 -- .../traypublisher/plugins/publish/collect_colorspace_look.py | 2 +- openpype/pipeline/colorspace.py | 3 ++- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py index a1b7896fba..5628d0973f 100644 --- a/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/create/create_colorspace_look.py @@ -77,7 +77,6 @@ This creator publishes color space look file (LUT). self._store_new_instance(new_instance) - def collect_instances(self): super().collect_instances() for instance in self.create_context.instances: @@ -85,7 +84,6 @@ This creator publishes color space look file (LUT). instance.transient_data["config_items"] = self.config_items instance.transient_data["config_data"] = self.config_data - def get_instance_attr_defs(self): return [ EnumDef( diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py index 4dc5348fb1..c7a886a619 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py @@ -4,6 +4,7 @@ import pyblish.api from openpype.pipeline import publish from openpype.pipeline import colorspace + class CollectColorspaceLook(pyblish.api.InstancePlugin, publish.OpenPypePyblishPluginMixin): """Collect OCIO colorspace look from LUT file @@ -30,7 +31,6 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, .title() .replace(" ", "")) - # get config items config_items = instance.data["transientData"]["config_items"] config_data = instance.data["transientData"]["config_data"] diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 1dbe869ad9..82d9b17a37 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -600,7 +600,8 @@ def get_colorspaces_enumerator_items( Families can be used for building menu and submenus in gui. Args: - config_items (dict[str,dict]): colorspace data + config_items (dict[str,dict]): colorspace data coming from + `get_ocio_config_colorspaces` function include_aliases (bool): include aliases in result include_looks (bool): include looks in result include_roles (bool): include roles in result From 4ff71554d3c7f76c753f3c6e0796f367b3548dcb Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 9 Oct 2023 17:16:40 +0200 Subject: [PATCH 21/28] nuke: ocio look loader wip --- .../hosts/nuke/plugins/load/load_ociolook.py | 260 ++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 openpype/hosts/nuke/plugins/load/load_ociolook.py diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py new file mode 100644 index 0000000000..76216e14cc --- /dev/null +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -0,0 +1,260 @@ +import json +from collections import OrderedDict +import nuke +import six + +from openpype.client import ( + get_version_by_id, + get_last_version_by_subset_id, +) +from openpype.pipeline import ( + load, + get_current_project_name, + get_representation_path, +) +from openpype.hosts.nuke.api import ( + containerise, + update_container, + viewer_update_and_undo_stop +) + + +class LoadOcioLook(load.LoaderPlugin): + """Loading Ocio look to the nuke node graph""" + + families = ["ociolook"] + representations = ["*"] + extension = {"json"} + + label = "Load OcioLook" + order = 0 + icon = "cc" + color = "white" + ignore_attr = ["useLifetime"] + + # json file variables + schema_version = 1 + + + def load(self, context, name, namespace, data): + """ + Loading function to get the soft effects to particular read node + + Arguments: + context (dict): context of version + name (str): name of the version + namespace (str): asset name + data (dict): compulsory attribute > not used + + Returns: + nuke node: containerised nuke node object + """ + # get main variables + version = context['version'] + version_data = version.get("data", {}) + vname = version.get("name", None) + root_working_colorspace = nuke.root()["working_colorspace"].value() + + namespace = namespace or context['asset']['name'] + object_name = "{}_{}".format(name, namespace) + + data_imprint = { + "version": vname, + "objectName": object_name, + "source": version_data.get("source", None), + "author": version_data.get("author", None), + "fps": version_data.get("fps", None), + } + + # getting file path + file = self.filepath_from_context(context).replace("\\", "/") + + # getting data from json file with unicode conversion + with open(file, "r") as f: + json_f = { + self.byteify(key): self.byteify(value) + for key, value in json.load(f).items() + } + + # check if the version in json_f is the same as plugin version + if json_f["version"] != self.schema_version: + raise KeyError( + "Version of json file is not the same as plugin version") + + json_data = json_f["data"] + ocio_working_colorspace = json_data["ocioLookWorkingSpace"] + + # adding nodes to node graph + # just in case we are in group lets jump out of it + nuke.endGroup() + + GN = nuke.createNode( + "Group", + "name {}_1".format(object_name), + inpanel=False + ) + + # adding content to the group node + with GN: + pre_colorspace = root_working_colorspace + pre_node = nuke.createNode("Input") + pre_node["name"].setValue("rgb") + + # Compare script working colorspace with ocio working colorspace + # found in json file and convert to json's if needed + if pre_colorspace != ocio_working_colorspace: + pre_node = _add_ocio_colorspace_node( + pre_node, + pre_colorspace, + ocio_working_colorspace + ) + pre_colorspace = ocio_working_colorspace + + for ocio_item in json_data["ocioLookItems"]: + input_space = _colorspace_name_by_type( + ocio_item["input_colorspace"]) + output_space = _colorspace_name_by_type( + ocio_item["output_colorspace"]) + + # making sure we are set to correct colorspace for otio item + if pre_colorspace != input_space: + pre_node = _add_ocio_colorspace_node( + pre_node, + pre_colorspace, + input_space + ) + + node = nuke.createNode("OCIOFileTransform") + + # TODO: file path from lut representation + node["file"].setValue(ocio_item["file"]) + node["name"].setValue(ocio_item["name"]) + node["direction"].setValue(ocio_item["direction"]) + node["interpolation"].setValue(ocio_item["interpolation"]) + node["working_space"].setValue(input_space) + + node.setInput(0, pre_node) + # pass output space into pre_colorspace for next iteration + # or for output node comparison + pre_colorspace = output_space + pre_node = node + + # making sure we are back in script working colorspace + if pre_colorspace != root_working_colorspace: + pre_node = _add_ocio_colorspace_node( + pre_node, + pre_colorspace, + root_working_colorspace + ) + + output = nuke.createNode("Output") + output.setInput(0, pre_node) + + GN["tile_color"].setValue(int("0x3469ffff", 16)) + + self.log.info("Loaded lut setup: `{}`".format(GN["name"].value())) + + return containerise( + node=GN, + name=name, + namespace=namespace, + context=context, + loader=self.__class__.__name__, + data=data_imprint) + + def update(self, container, representation): + """Update the Loader's path + + Nuke automatically tries to reset some variables when changing + the loader's path to a new file. These automatic changes are to its + inputs: + + """ + # get main variables + # Get version from io + project_name = get_current_project_name() + version_doc = get_version_by_id(project_name, representation["parent"]) + + # get corresponding node + GN = nuke.toNode(container['objectName']) + + file = get_representation_path(representation).replace("\\", "/") + name = container['name'] + version_data = version_doc.get("data", {}) + vname = version_doc.get("name", None) + namespace = container['namespace'] + object_name = "{}_{}".format(name, namespace) + + + def byteify(self, input): + """ + Converts unicode strings to strings + It goes through all dictionary + + Arguments: + input (dict/str): input + + Returns: + dict: with fixed values and keys + + """ + + if isinstance(input, dict): + return {self.byteify(key): self.byteify(value) + for key, value in input.items()} + elif isinstance(input, list): + return [self.byteify(element) for element in input] + elif isinstance(input, six.text_type): + return str(input) + else: + return input + + def switch(self, container, representation): + self.update(container, representation) + + def remove(self, container): + node = nuke.toNode(container['objectName']) + with viewer_update_and_undo_stop(): + nuke.delete(node) + + +def _colorspace_name_by_type(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"])) + + + + +def _add_ocio_colorspace_node(pre_node, input_space, output_space): + """ + Adds OCIOColorSpace node to the node graph + + Arguments: + pre_node (nuke node): node to connect to + input_space (str): input colorspace + output_space (str): output colorspace + + Returns: + nuke node: node with OCIOColorSpace node + """ + node = nuke.createNode("OCIOColorSpace") + node.setInput(0, pre_node) + node["in_colorspace"].setValue(input_space) + node["out_colorspace"].setValue(output_space) + + node.setInput(0, pre_node) + return node From 5e01929cb652725cd8999854ed5c6ac3cdb5667b Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Mon, 9 Oct 2023 17:35:25 +0200 Subject: [PATCH 22/28] ocio look loader wip2: final loader --- .../hosts/nuke/plugins/load/load_ociolook.py | 52 ++++++++++++------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index 76216e14cc..9f5a68dfc4 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -1,12 +1,9 @@ +import os import json -from collections import OrderedDict import nuke import six -from openpype.client import ( - get_version_by_id, - get_last_version_by_subset_id, -) +from openpype.client import get_version_by_id from openpype.pipeline import ( load, get_current_project_name, @@ -19,14 +16,14 @@ from openpype.hosts.nuke.api import ( ) -class LoadOcioLook(load.LoaderPlugin): +class LoadOcioLookNodes(load.LoaderPlugin): """Loading Ocio look to the nuke node graph""" families = ["ociolook"] representations = ["*"] - extension = {"json"} + extensions = {"json"} - label = "Load OcioLook" + label = "Load OcioLook [nodes]" order = 0 icon = "cc" color = "white" @@ -47,13 +44,13 @@ class LoadOcioLook(load.LoaderPlugin): data (dict): compulsory attribute > not used Returns: - nuke node: containerised nuke node object + nuke node: containerized nuke node object """ # get main variables version = context['version'] version_data = version.get("data", {}) vname = version.get("name", None) - root_working_colorspace = nuke.root()["working_colorspace"].value() + root_working_colorspace = nuke.root()["workingSpaceLUT"].value() namespace = namespace or context['asset']['name'] object_name = "{}_{}".format(name, namespace) @@ -67,14 +64,16 @@ class LoadOcioLook(load.LoaderPlugin): } # getting file path - file = self.filepath_from_context(context).replace("\\", "/") + file = self.filepath_from_context(context) + print(file) + + dir_path = os.path.dirname(file) + all_files = os.listdir(dir_path) # getting data from json file with unicode conversion with open(file, "r") as f: - json_f = { - self.byteify(key): self.byteify(value) - for key, value in json.load(f).items() - } + json_f = {self.bytify(key): self.bytify(value) + for key, value in json.load(f).items()} # check if the version in json_f is the same as plugin version if json_f["version"] != self.schema_version: @@ -82,7 +81,8 @@ class LoadOcioLook(load.LoaderPlugin): "Version of json file is not the same as plugin version") json_data = json_f["data"] - ocio_working_colorspace = json_data["ocioLookWorkingSpace"] + ocio_working_colorspace = _colorspace_name_by_type( + json_data["ocioLookWorkingSpace"]) # adding nodes to node graph # just in case we are in group lets jump out of it @@ -127,7 +127,19 @@ class LoadOcioLook(load.LoaderPlugin): node = nuke.createNode("OCIOFileTransform") # TODO: file path from lut representation - node["file"].setValue(ocio_item["file"]) + extension = ocio_item["ext"] + item_lut_file = next( + (file for file in all_files if file.endswith(extension)), + None + ) + if not item_lut_file: + raise ValueError( + "File with extension {} not found in directory".format( + extension)) + + item_lut_path = os.path.join( + dir_path, item_lut_file).replace("\\", "/") + node["file"].setValue(item_lut_path) node["name"].setValue(ocio_item["name"]) node["direction"].setValue(ocio_item["direction"]) node["interpolation"].setValue(ocio_item["interpolation"]) @@ -186,7 +198,7 @@ class LoadOcioLook(load.LoaderPlugin): object_name = "{}_{}".format(name, namespace) - def byteify(self, input): + def bytify(self, input): """ Converts unicode strings to strings It goes through all dictionary @@ -200,10 +212,10 @@ class LoadOcioLook(load.LoaderPlugin): """ if isinstance(input, dict): - return {self.byteify(key): self.byteify(value) + return {self.bytify(key): self.bytify(value) for key, value in input.items()} elif isinstance(input, list): - return [self.byteify(element) for element in input] + return [self.bytify(element) for element in input] elif isinstance(input, six.text_type): return str(input) else: From 58e5cf20b3023ea0c440304b2ba5184af6110312 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 10 Oct 2023 14:34:35 +0200 Subject: [PATCH 23/28] loader ociolook with updating --- .../hosts/nuke/plugins/load/load_ociolook.py | 209 +++++++++++------- 1 file changed, 130 insertions(+), 79 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index 9f5a68dfc4..6cf9236e1b 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -1,5 +1,6 @@ import os import json +import secrets import nuke import six @@ -17,7 +18,7 @@ from openpype.hosts.nuke.api import ( class LoadOcioLookNodes(load.LoaderPlugin): - """Loading Ocio look to the nuke node graph""" + """Loading Ocio look to the nuke.Node graph""" families = ["ociolook"] representations = ["*"] @@ -27,7 +28,7 @@ class LoadOcioLookNodes(load.LoaderPlugin): order = 0 icon = "cc" color = "white" - ignore_attr = ["useLifetime"] + igroup_nodeore_attr = ["useLifetime"] # json file variables schema_version = 1 @@ -44,61 +45,98 @@ class LoadOcioLookNodes(load.LoaderPlugin): data (dict): compulsory attribute > not used Returns: - nuke node: containerized nuke node object + nuke.Node: containerized nuke.Node object """ - # get main variables - version = context['version'] - version_data = version.get("data", {}) - vname = version.get("name", None) - root_working_colorspace = nuke.root()["workingSpaceLUT"].value() - namespace = namespace or context['asset']['name'] - object_name = "{}_{}".format(name, namespace) - - data_imprint = { - "version": vname, - "objectName": object_name, - "source": version_data.get("source", None), - "author": version_data.get("author", None), - "fps": version_data.get("fps", None), - } + suffix = secrets.token_hex(nbytes=4) + object_name = "{}_{}_{}".format( + name, namespace, suffix) # getting file path - file = self.filepath_from_context(context) - print(file) + filepath = self.filepath_from_context(context) - dir_path = os.path.dirname(file) + json_f = self._load_json_data(filepath) + + group_node = self._create_group_node( + object_name, filepath, json_f["data"]) + + group_node["tile_color"].setValue(int("0x3469ffff", 16)) + + self.log.info("Loaded lut setup: `{}`".format(group_node["name"].value())) + + return containerise( + node=group_node, + name=name, + namespace=namespace, + context=context, + loader=self.__class__.__name__, + data={ + "objectName": object_name, + } + ) + + def _create_group_node( + self, + object_name, + filepath, + data + ): + """Creates group node with all the nodes inside. + + Creating mainly `OCIOFileTransform` nodes with `OCIOColorSpace` nodes + in between - in case those are needed. + + Arguments: + object_name (str): name of the group node + filepath (str): path to json file + data (dict): data from json file + + Returns: + nuke.Node: group node with all the nodes inside + """ + # get corresponding node + + root_working_colorspace = nuke.root()["workingSpaceLUT"].value() + + dir_path = os.path.dirname(filepath) all_files = os.listdir(dir_path) - # getting data from json file with unicode conversion - with open(file, "r") as f: - json_f = {self.bytify(key): self.bytify(value) - for key, value in json.load(f).items()} - - # check if the version in json_f is the same as plugin version - if json_f["version"] != self.schema_version: - raise KeyError( - "Version of json file is not the same as plugin version") - - json_data = json_f["data"] ocio_working_colorspace = _colorspace_name_by_type( - json_data["ocioLookWorkingSpace"]) + data["ocioLookWorkingSpace"]) # adding nodes to node graph # just in case we are in group lets jump out of it nuke.endGroup() - GN = nuke.createNode( - "Group", - "name {}_1".format(object_name), - inpanel=False - ) + input_node = None + output_node = None + group_node = nuke.toNode(object_name) + if group_node: + # remove all nodes between Input and Output nodes + for node in group_node.nodes(): + if node.Class() not in ["Input", "Output"]: + nuke.delete(node) + if node.Class() == "Input": + input_node = node + if node.Class() == "Output": + output_node = node + else: + group_node = nuke.createNode( + "Group", + "name {}_1".format(object_name), + inpanel=False + ) # adding content to the group node - with GN: + with group_node: pre_colorspace = root_working_colorspace - pre_node = nuke.createNode("Input") - pre_node["name"].setValue("rgb") + + # reusing input node if it exists during update + if input_node: + pre_node = input_node + else: + pre_node = nuke.createNode("Input") + pre_node["name"].setValue("rgb") # Compare script working colorspace with ocio working colorspace # found in json file and convert to json's if needed @@ -110,7 +148,7 @@ class LoadOcioLookNodes(load.LoaderPlugin): ) pre_colorspace = ocio_working_colorspace - for ocio_item in json_data["ocioLookItems"]: + for ocio_item in data["ocioLookItems"]: input_space = _colorspace_name_by_type( ocio_item["input_colorspace"]) output_space = _colorspace_name_by_type( @@ -126,10 +164,16 @@ class LoadOcioLookNodes(load.LoaderPlugin): node = nuke.createNode("OCIOFileTransform") - # TODO: file path from lut representation + # file path from lut representation extension = ocio_item["ext"] + item_name = ocio_item["name"] + item_lut_file = next( - (file for file in all_files if file.endswith(extension)), + ( + file for file in all_files + if file.endswith(extension) + and item_name in file + ), None ) if not item_lut_file: @@ -140,12 +184,14 @@ class LoadOcioLookNodes(load.LoaderPlugin): item_lut_path = os.path.join( dir_path, item_lut_file).replace("\\", "/") node["file"].setValue(item_lut_path) - node["name"].setValue(ocio_item["name"]) + node["name"].setValue(item_name) node["direction"].setValue(ocio_item["direction"]) node["interpolation"].setValue(ocio_item["interpolation"]) node["working_space"].setValue(input_space) + pre_node.autoplace() node.setInput(0, pre_node) + node.autoplace() # pass output space into pre_colorspace for next iteration # or for output node comparison pre_colorspace = output_space @@ -159,46 +205,48 @@ class LoadOcioLookNodes(load.LoaderPlugin): root_working_colorspace ) - output = nuke.createNode("Output") + # reusing output node if it exists during update + if not output_node: + output = nuke.createNode("Output") + else: + output = output_node + output.setInput(0, pre_node) - GN["tile_color"].setValue(int("0x3469ffff", 16)) - - self.log.info("Loaded lut setup: `{}`".format(GN["name"].value())) - - return containerise( - node=GN, - name=name, - namespace=namespace, - context=context, - loader=self.__class__.__name__, - data=data_imprint) + return group_node def update(self, container, representation): - """Update the Loader's path - Nuke automatically tries to reset some variables when changing - the loader's path to a new file. These automatic changes are to its - inputs: + object_name = container['objectName'] - """ - # get main variables - # Get version from io - project_name = get_current_project_name() - version_doc = get_version_by_id(project_name, representation["parent"]) + filepath = get_representation_path(representation) - # get corresponding node - GN = nuke.toNode(container['objectName']) + json_f = self._load_json_data(filepath) - file = get_representation_path(representation).replace("\\", "/") - name = container['name'] - version_data = version_doc.get("data", {}) - vname = version_doc.get("name", None) - namespace = container['namespace'] - object_name = "{}_{}".format(name, namespace) + new_group_node = self._create_group_node( + object_name, + filepath, + json_f["data"] + ) + + self.log.info("Updated lut setup: `{}`".format( + new_group_node["name"].value())) - def bytify(self, input): + def _load_json_data(self, filepath): + # getting data from json file with unicode conversion + with open(filepath, "r") as _file: + json_f = {self._bytify(key): self._bytify(value) + for key, value in json.load(_file).items()} + + # check if the version in json_f is the same as plugin version + if json_f["version"] != self.schema_version: + raise KeyError( + "Version of json file is not the same as plugin version") + + return json_f + + def _bytify(self, input): """ Converts unicode strings to strings It goes through all dictionary @@ -212,10 +260,10 @@ class LoadOcioLookNodes(load.LoaderPlugin): """ if isinstance(input, dict): - return {self.bytify(key): self.bytify(value) + return {self._bytify(key): self._bytify(value) for key, value in input.items()} elif isinstance(input, list): - return [self.bytify(element) for element in input] + return [self._bytify(element) for element in input] elif isinstance(input, six.text_type): return str(input) else: @@ -256,17 +304,20 @@ def _add_ocio_colorspace_node(pre_node, input_space, output_space): Adds OCIOColorSpace node to the node graph Arguments: - pre_node (nuke node): node to connect to + pre_node (nuke.Node): node to connect to input_space (str): input colorspace output_space (str): output colorspace Returns: - nuke node: node with OCIOColorSpace node + nuke.Node: node with OCIOColorSpace node """ node = nuke.createNode("OCIOColorSpace") node.setInput(0, pre_node) node["in_colorspace"].setValue(input_space) node["out_colorspace"].setValue(output_space) + pre_node.autoplace() node.setInput(0, pre_node) + node.autoplace() + return node From e422d1900f10acc3c70bd5377a4930bedf2e329c Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 10 Oct 2023 17:18:14 +0200 Subject: [PATCH 24/28] adding color to loaded nodes --- .../hosts/nuke/plugins/load/load_ociolook.py | 38 ++++++++++++++++--- 1 file changed, 32 insertions(+), 6 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index 6cf9236e1b..d2143b5527 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -4,7 +4,10 @@ import secrets import nuke import six -from openpype.client import get_version_by_id +from openpype.client import ( + get_version_by_id, + get_last_version_by_subset_id +) from openpype.pipeline import ( load, get_current_project_name, @@ -12,7 +15,6 @@ from openpype.pipeline import ( ) from openpype.hosts.nuke.api import ( containerise, - update_container, viewer_update_and_undo_stop ) @@ -28,7 +30,11 @@ class LoadOcioLookNodes(load.LoaderPlugin): order = 0 icon = "cc" color = "white" - igroup_nodeore_attr = ["useLifetime"] + ignore_attr = ["useLifetime"] + + # plugin attributes + current_node_color = "0x4ecd91ff" + old_node_color = "0xd88467ff" # json file variables schema_version = 1 @@ -60,7 +66,8 @@ class LoadOcioLookNodes(load.LoaderPlugin): group_node = self._create_group_node( object_name, filepath, json_f["data"]) - group_node["tile_color"].setValue(int("0x3469ffff", 16)) + + self._node_version_color(context["version"], group_node) self.log.info("Loaded lut setup: `{}`".format(group_node["name"].value())) @@ -217,20 +224,25 @@ class LoadOcioLookNodes(load.LoaderPlugin): def update(self, container, representation): + project_name = get_current_project_name() + version_doc = get_version_by_id(project_name, representation["parent"]) + object_name = container['objectName'] filepath = get_representation_path(representation) json_f = self._load_json_data(filepath) - new_group_node = self._create_group_node( + group_node = self._create_group_node( object_name, filepath, json_f["data"] ) + self._node_version_color(version_doc, group_node) + self.log.info("Updated lut setup: `{}`".format( - new_group_node["name"].value())) + group_node["name"].value())) def _load_json_data(self, filepath): @@ -277,6 +289,20 @@ class LoadOcioLookNodes(load.LoaderPlugin): with viewer_update_and_undo_stop(): nuke.delete(node) + def _node_version_color(self, version, node): + """ Coloring a node by correct color by actual version""" + + project_name = get_current_project_name() + last_version_doc = get_last_version_by_subset_id( + project_name, version["parent"], fields=["_id"] + ) + + # change color of node + if version["_id"] == last_version_doc["_id"]: + color_value = self.current_node_color + else: + color_value = self.old_node_color + node["tile_color"].setValue(int(color_value, 16)) def _colorspace_name_by_type(colorspace_data): """ From ac9ead71fdc5c0e326bd46132707fb9fd08cd20f Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Tue, 10 Oct 2023 17:21:06 +0200 Subject: [PATCH 25/28] hound --- openpype/hosts/nuke/plugins/load/load_ociolook.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index d2143b5527..29503ef4de 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -323,8 +323,6 @@ def _colorspace_name_by_type(colorspace_data): colorspace_data["type"])) - - def _add_ocio_colorspace_node(pre_node, input_space, output_space): """ Adds OCIOColorSpace node to the node graph From 620269c2fc56da2b629d6b9d65ff70234c7820ec Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 18 Oct 2023 14:21:28 +0200 Subject: [PATCH 26/28] hound --- openpype/hosts/nuke/plugins/load/load_ociolook.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index 29503ef4de..a22b0ae1af 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -39,7 +39,6 @@ class LoadOcioLookNodes(load.LoaderPlugin): # json file variables schema_version = 1 - def load(self, context, name, namespace, data): """ Loading function to get the soft effects to particular read node @@ -66,10 +65,10 @@ class LoadOcioLookNodes(load.LoaderPlugin): group_node = self._create_group_node( object_name, filepath, json_f["data"]) - self._node_version_color(context["version"], group_node) - self.log.info("Loaded lut setup: `{}`".format(group_node["name"].value())) + self.log.info( + "Loaded lut setup: `{}`".format(group_node["name"].value())) return containerise( node=group_node, @@ -244,7 +243,6 @@ class LoadOcioLookNodes(load.LoaderPlugin): self.log.info("Updated lut setup: `{}`".format( group_node["name"].value())) - def _load_json_data(self, filepath): # getting data from json file with unicode conversion with open(filepath, "r") as _file: @@ -304,6 +302,7 @@ class LoadOcioLookNodes(load.LoaderPlugin): color_value = self.old_node_color node["tile_color"].setValue(int(color_value, 16)) + def _colorspace_name_by_type(colorspace_data): """ Returns colorspace name by type From 2445f6a1e4c6844bbc51c02093af8aac1360ba67 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 18 Oct 2023 15:19:46 +0200 Subject: [PATCH 27/28] fixing lost commit content - loading updating fixed and container data are imprinted with updated representation id - not failing due `::` split on NoneType object - workfile colorspace is separated key from ocio look items - validator treating workfile colorspace key separately --- .../hosts/nuke/plugins/load/load_ociolook.py | 13 +++-- .../publish/collect_colorspace_look.py | 21 +++++--- .../publish/extract_colorspace_look.py | 4 +- .../publish/validate_colorspace_look.py | 52 +++++++++++++------ openpype/pipeline/colorspace.py | 3 ++ 5 files changed, 65 insertions(+), 28 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index a22b0ae1af..3413b85749 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -15,7 +15,8 @@ from openpype.pipeline import ( ) from openpype.hosts.nuke.api import ( containerise, - viewer_update_and_undo_stop + viewer_update_and_undo_stop, + update_container, ) @@ -122,9 +123,9 @@ class LoadOcioLookNodes(load.LoaderPlugin): for node in group_node.nodes(): if node.Class() not in ["Input", "Output"]: nuke.delete(node) - if node.Class() == "Input": + elif node.Class() == "Input": input_node = node - if node.Class() == "Output": + elif node.Class() == "Output": output_node = node else: group_node = nuke.createNode( @@ -178,13 +179,12 @@ class LoadOcioLookNodes(load.LoaderPlugin): ( file for file in all_files if file.endswith(extension) - and item_name in file ), None ) if not item_lut_file: raise ValueError( - "File with extension {} not found in directory".format( + "File with extension '{}' not found in directory".format( extension)) item_lut_path = os.path.join( @@ -243,6 +243,9 @@ class LoadOcioLookNodes(load.LoaderPlugin): self.log.info("Updated lut setup: `{}`".format( group_node["name"].value())) + return update_container( + group_node, {"representation": str(representation["_id"])}) + def _load_json_data(self, filepath): # getting data from json file with unicode conversion with open(filepath, "r") as _file: diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py index c7a886a619..f259b120e9 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py @@ -1,3 +1,4 @@ +from math import e import os from pprint import pformat import pyblish.api @@ -42,9 +43,18 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, "input_colorspace", "output_colorspace" ]: - color_data = colorspace.convert_colorspace_enumerator_item( - creator_attrs[colorspace_key], config_items) - converted_color_data[colorspace_key] = color_data + if creator_attrs[colorspace_key]: + color_data = colorspace.convert_colorspace_enumerator_item( + creator_attrs[colorspace_key], config_items) + converted_color_data[colorspace_key] = color_data + else: + converted_color_data[colorspace_key] = None + + # add colorspace to config data + if converted_color_data["working_colorspace"]: + config_data["colorspace"] = ( + converted_color_data["working_colorspace"]["name"] + ) # create lut representation data lut_repre = { @@ -58,12 +68,11 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, instance.data.update({ "representations": [lut_repre], "source": file_url, + "ocioLookWorkingSpace": converted_color_data["working_colorspace"], "ocioLookItems": [ { "name": lut_repre_name, "ext": ext.lstrip("."), - "working_colorspace": converted_color_data[ - "working_colorspace"], "input_colorspace": converted_color_data[ "input_colorspace"], "output_colorspace": converted_color_data[ @@ -72,7 +81,7 @@ class CollectColorspaceLook(pyblish.api.InstancePlugin, "interpolation": creator_attrs["interpolation"], "config_data": config_data } - ] + ], }) self.log.debug(pformat(instance.data)) diff --git a/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py index ffd877af1d..f94bbc7a49 100644 --- a/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/extract_colorspace_look.py @@ -16,6 +16,7 @@ class ExtractColorspaceLook(publish.Extractor, def process(self, instance): ociolook_items = instance.data["ocioLookItems"] + ociolook_working_color = instance.data["ocioLookWorkingSpace"] staging_dir = self.staging_dir(instance) # create ociolook file attributes @@ -23,7 +24,8 @@ class ExtractColorspaceLook(publish.Extractor, ociolook_file_content = { "version": 1, "data": { - "ocioLookItems": ociolook_items + "ocioLookItems": ociolook_items, + "ocioLookWorkingSpace": ociolook_working_color } } diff --git a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py index ce7f8831fd..548ce9d15a 100644 --- a/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/validate_colorspace_look.py @@ -21,25 +21,54 @@ class ValidateColorspaceLook(pyblish.api.InstancePlugin, instance.data["instance_id"]) creator_defs = created_instance.creator_attribute_defs + ociolook_working_color = instance.data.get("ocioLookWorkingSpace") ociolook_items = instance.data.get("ocioLookItems", []) - for ociolook_item in ociolook_items: - self.validate_colorspace_set_attrs(ociolook_item, creator_defs) + creator_defs_by_key = {_def.key: _def.label for _def in creator_defs} - def validate_colorspace_set_attrs(self, ociolook_item, creator_defs): + not_set_keys = {} + if not ociolook_working_color: + not_set_keys["working_colorspace"] = creator_defs_by_key[ + "working_colorspace"] + + for ociolook_item in ociolook_items: + item_not_set_keys = self.validate_colorspace_set_attrs( + ociolook_item, creator_defs_by_key) + if item_not_set_keys: + not_set_keys[ociolook_item["name"]] = item_not_set_keys + + if not_set_keys: + message = ( + "Colorspace look attributes are not set: \n" + ) + for key, value in not_set_keys.items(): + if isinstance(value, list): + values_string = "\n\t- ".join(value) + message += f"\n\t{key}:\n\t- {values_string}" + else: + message += f"\n\t{value}" + + raise PublishValidationError( + title="Colorspace Look attributes", + message=message, + description=message + ) + + def validate_colorspace_set_attrs( + self, + ociolook_item, + creator_defs_by_key + ): """Validate colorspace look attributes""" self.log.debug(f"Validate colorspace look attributes: {ociolook_item}") - self.log.debug(f"Creator defs: {creator_defs}") check_keys = [ - "working_colorspace", "input_colorspace", "output_colorspace", "direction", "interpolation" ] - creator_defs_by_key = {_def.key: _def.label for _def in creator_defs} not_set_keys = [] for key in check_keys: @@ -57,13 +86,4 @@ class ValidateColorspaceLook(pyblish.api.InstancePlugin, ) not_set_keys.append(def_label) - if not_set_keys: - message = ( - "Colorspace look attributes are not set: " - f"{', '.join(not_set_keys)}" - ) - raise PublishValidationError( - title="Colorspace Look attributes", - message=message, - description=message - ) + return not_set_keys diff --git a/openpype/pipeline/colorspace.py b/openpype/pipeline/colorspace.py index 82d9b17a37..9f720f6ae9 100644 --- a/openpype/pipeline/colorspace.py +++ b/openpype/pipeline/colorspace.py @@ -546,6 +546,9 @@ def convert_colorspace_enumerator_item( Returns: dict: colorspace data """ + if "::" not in colorspace_enum_item: + return None + # split string with `::` separator and set first as key and second as value item_type, item_name = colorspace_enum_item.split("::") From c56560283ab72735718cba46e263887efc7b7d99 Mon Sep 17 00:00:00 2001 From: Jakub Jezek Date: Wed, 18 Oct 2023 15:21:58 +0200 Subject: [PATCH 28/28] hound catches --- openpype/hosts/nuke/plugins/load/load_ociolook.py | 5 +++-- .../traypublisher/plugins/publish/collect_colorspace_look.py | 1 - 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/openpype/hosts/nuke/plugins/load/load_ociolook.py b/openpype/hosts/nuke/plugins/load/load_ociolook.py index 3413b85749..18c8cdba35 100644 --- a/openpype/hosts/nuke/plugins/load/load_ociolook.py +++ b/openpype/hosts/nuke/plugins/load/load_ociolook.py @@ -184,8 +184,9 @@ class LoadOcioLookNodes(load.LoaderPlugin): ) if not item_lut_file: raise ValueError( - "File with extension '{}' not found in directory".format( - extension)) + "File with extension '{}' not " + "found in directory".format(extension) + ) item_lut_path = os.path.join( dir_path, item_lut_file).replace("\\", "/") diff --git a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py index f259b120e9..6aede099bf 100644 --- a/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py +++ b/openpype/hosts/traypublisher/plugins/publish/collect_colorspace_look.py @@ -1,4 +1,3 @@ -from math import e import os from pprint import pformat import pyblish.api