Merge pull request #1561 from BigRoy/enhancement/allow_color_management_profile_to_disable_management

OCIO Color management: Allow profiles to also choose to disable OCIO management
This commit is contained in:
Jakub Trllo 2025-12-01 10:43:24 +01:00 committed by GitHub
commit 617887d0c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 21 deletions

View file

@ -7,6 +7,7 @@ import platform
import tempfile import tempfile
import warnings import warnings
from copy import deepcopy from copy import deepcopy
from dataclasses import dataclass
import ayon_api import ayon_api
@ -26,6 +27,18 @@ from ayon_core.pipeline.load import get_representation_path_with_anatomy
log = Logger.get_logger(__name__) log = Logger.get_logger(__name__)
@dataclass
class ConfigData:
"""OCIO Config to use in a certain context.
When enabled and no path/template are set, it will be considered invalid
and will error on OCIO path not found. Enabled must be False to explicitly
allow OCIO to be disabled."""
path: str = ""
template: str = ""
enabled: bool = True
class CachedData: class CachedData:
remapping = {} remapping = {}
has_compatible_ocio_package = None has_compatible_ocio_package = None
@ -710,7 +723,7 @@ def _get_config_path_from_profile_data(
template_data (dict[str, Any]): Template data. template_data (dict[str, Any]): Template data.
Returns: Returns:
dict[str, str]: Config data with path and template. ConfigData: Config data with path and template.
""" """
template = profile[profile_type] template = profile[profile_type]
result = StringTemplate.format_strict_template( result = StringTemplate.format_strict_template(
@ -719,12 +732,12 @@ def _get_config_path_from_profile_data(
normalized_path = str(result.normalized()) normalized_path = str(result.normalized())
if not os.path.exists(normalized_path): if not os.path.exists(normalized_path):
log.warning(f"Path was not found '{normalized_path}'.") log.warning(f"Path was not found '{normalized_path}'.")
return None return ConfigData() # Return invalid config data
return { return ConfigData(
"path": normalized_path, path=normalized_path,
"template": template template=template
} )
def _get_global_config_data( def _get_global_config_data(
@ -735,7 +748,7 @@ def _get_global_config_data(
imageio_global, imageio_global,
folder_id, folder_id,
log, log,
): ) -> ConfigData:
"""Get global config data. """Get global config data.
Global config from core settings is using profiles that are based on Global config from core settings is using profiles that are based on
@ -759,8 +772,7 @@ def _get_global_config_data(
log (logging.Logger): Logger object. log (logging.Logger): Logger object.
Returns: Returns:
Union[dict[str, str], None]: Config data with path and template ConfigData: Config data with path and template.
or None.
""" """
task_name = task_type = None task_name = task_type = None
@ -779,12 +791,14 @@ def _get_global_config_data(
) )
if profile is None: if profile is None:
log.info(f"No config profile matched filters {str(filter_values)}") log.info(f"No config profile matched filters {str(filter_values)}")
return None return ConfigData(enabled=False)
profile_type = profile["type"] profile_type = profile["type"]
if profile_type in ("builtin_path", "custom_path"): if profile_type in {"builtin_path", "custom_path"}:
return _get_config_path_from_profile_data( return _get_config_path_from_profile_data(
profile, profile_type, template_data) profile, profile_type, template_data)
elif profile_type == "disabled":
return ConfigData(enabled=False)
# TODO decide if this is the right name for representation # TODO decide if this is the right name for representation
repre_name = "ocioconfig" repre_name = "ocioconfig"
@ -798,7 +812,7 @@ def _get_global_config_data(
"Colorspace OCIO config path cannot be set. " "Colorspace OCIO config path cannot be set. "
"Profile is set to published product but `Product name` is empty." "Profile is set to published product but `Product name` is empty."
) )
return None return ConfigData()
folder_info = template_data.get("folder") folder_info = template_data.get("folder")
if not folder_info: if not folder_info:
@ -819,7 +833,7 @@ def _get_global_config_data(
) )
if not folder_entity: if not folder_entity:
log.warning(f"Folder entity '{folder_path}' was not found..") log.warning(f"Folder entity '{folder_path}' was not found..")
return None return ConfigData()
folder_id = folder_entity["id"] folder_id = folder_entity["id"]
product_entities_by_name = { product_entities_by_name = {
@ -855,7 +869,7 @@ def _get_global_config_data(
log.info( log.info(
f"Product '{product_name}' does not have available any versions." f"Product '{product_name}' does not have available any versions."
) )
return None return ConfigData()
# Find 'ocioconfig' representation entity # Find 'ocioconfig' representation entity
repre_entity = ayon_api.get_representation_by_name( repre_entity = ayon_api.get_representation_by_name(
@ -868,15 +882,15 @@ def _get_global_config_data(
f"Representation '{repre_name}'" f"Representation '{repre_name}'"
f" not found on product '{product_name}'." f" not found on product '{product_name}'."
) )
return None return ConfigData()
path = get_representation_path_with_anatomy(repre_entity, anatomy) path = get_representation_path_with_anatomy(repre_entity, anatomy)
template = repre_entity["attrib"]["template"] template = repre_entity["attrib"]["template"]
return { return ConfigData(
"path": path, path=path,
"template": template, template=template
} )
def get_imageio_config_preset( def get_imageio_config_preset(
@ -1015,13 +1029,19 @@ def get_imageio_config_preset(
host_ocio_config["filepath"], template_data host_ocio_config["filepath"], template_data
) )
if not config_data: if not config_data.enabled:
return {} # OCIO management disabled
if not config_data.path:
raise FileExistsError( raise FileExistsError(
"No OCIO config found in settings. It is" "No OCIO config found in settings. It is"
" either missing or there is typo in path inputs" " either missing or there is typo in path inputs"
) )
return config_data return {
"path": config_data.path,
"template": config_data.template,
}
def _get_host_config_data(templates, template_data): def _get_host_config_data(templates, template_data):

View file

@ -59,6 +59,7 @@ def _ocio_config_profile_types():
{"value": "builtin_path", "label": "AYON built-in OCIO config"}, {"value": "builtin_path", "label": "AYON built-in OCIO config"},
{"value": "custom_path", "label": "Path to OCIO config"}, {"value": "custom_path", "label": "Path to OCIO config"},
{"value": "published_product", "label": "Published product"}, {"value": "published_product", "label": "Published product"},
{"value": "disabled", "label": "Disable OCIO management"},
] ]