Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor OCIO config handling, introduce fallback mechanism #834

Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d7a2c57
Refactor OCIO config handling, introduce fallback mechanism
jakubjezek001 Jul 31, 2024
9375b8b
Update version references for future removal and conversion functions…
jakubjezek001 Jul 31, 2024
1e026d8
Refactor config data retrieval logic in colorspace module
jakubjezek001 Aug 1, 2024
a482f7d
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Aug 1, 2024
f9e0b05
Refactor fallback handling in colorspace module
jakubjezek001 Aug 9, 2024
d51a04c
Update client/ayon_core/pipeline/colorspace.py
jakubjezek001 Aug 9, 2024
f870575
adding space
jakubjezek001 Aug 9, 2024
46e3ddd
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Aug 9, 2024
3746645
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Sep 17, 2024
c5cc6cb
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Sep 24, 2024
0ec170b
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Sep 25, 2024
453995a
Update imageio config conversion to 0.4.5 version
jakubjezek001 Sep 25, 2024
6085b6b
Refactor imageio settings conversion logic
jakubjezek001 Sep 25, 2024
07ea80d
Update fallback type field names in colorspace and settings modules
jakubjezek001 Sep 25, 2024
6aa31e8
fixing typo
jakubjezek001 Sep 25, 2024
fa4745d
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Sep 26, 2024
e299b40
Update server/settings/conversion.py
jakubjezek001 Oct 2, 2024
8b14e79
Update server/settings/conversion.py
jakubjezek001 Oct 2, 2024
589a642
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Oct 2, 2024
ce977ab
Merge branch 'develop' into enhancement/AY-6198_OCIO-fallback-for-pro…
jakubjezek001 Oct 2, 2024
0b9cea9
Refactor code for better readability and consistency.
jakubjezek001 Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 56 additions & 20 deletions client/ayon_core/pipeline/colorspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,34 @@ def get_ocio_config_views(config_path):
)


def _get_config_path_from_profile_data(
profile, profile_type, template_data
):
"""Get config path from profile data.

Args:
profile (dict[str, Any]): Profile data.
profile_type (str): Profile type.
template_data (dict[str, Any]): Template data.

Returns:
dict[str, str]: Config data with path and template.
"""
template = profile[profile_type]
result = StringTemplate.format_strict_template(
template, template_data
)
normalized_path = str(result.normalized())
if not os.path.exists(normalized_path):
log.warning(f"Path was not found '{normalized_path}'.")
return None

return {
"path": normalized_path,
"template": template
}


def _get_global_config_data(
project_name,
host_name,
Expand All @@ -717,7 +745,7 @@ def _get_global_config_data(
2. Custom path to ocio config.
3. Path to 'ocioconfig' representation on product. Name of product can be
defined in settings. Product name can be regex but exact match is
always preferred.
always preferred. Fallback can be defined in case no product is found.

None is returned when no profile is found, when path

Expand Down Expand Up @@ -755,30 +783,36 @@ def _get_global_config_data(

profile_type = profile["type"]
if profile_type in ("builtin_path", "custom_path"):
template = profile[profile_type]
result = StringTemplate.format_strict_template(
template, template_data
)
normalized_path = str(result.normalized())
if not os.path.exists(normalized_path):
log.warning(f"Path was not found '{normalized_path}'.")
return None

return {
"path": normalized_path,
"template": template
}
return _get_config_path_from_profile_data(
profile, profile_type, template_data)

# TODO decide if this is the right name for representation
repre_name = "ocioconfig"

published_product_data = profile["published_product"]
product_name = published_product_data["product_name"]
fallback_data = published_product_data["fallback"]

if product_name == "":
log.error(
"Colorspace OCIO config path cannot be set. "
"Profile is set to published product but `Product name` is empty."
)
return None

folder_info = template_data.get("folder")
if not folder_info:
log.warning("Folder info is missing.")
return None

log.info("Using fallback data for ocio config path.")
# in case no product was found we need to use fallback
fallback_type = fallback_data["type"]
return _get_config_path_from_profile_data(
fallback_data, fallback_type, template_data
)

folder_path = folder_info["path"]

product_name = profile["product_name"]
if folder_id is None:
folder_entity = ayon_api.get_folder_by_path(
project_name, folder_path, fields={"id"}
Expand All @@ -797,12 +831,13 @@ def _get_global_config_data(
fields={"id", "name"}
)
}

if not product_entities_by_name:
log.debug(
f"No product entities were found for folder '{folder_path}' with"
f" product name filter '{product_name}'."
# in case no product was found we need to use fallback
fallback_type = fallback_data["type"]
return _get_config_path_from_profile_data(
fallback_data, fallback_type, template_data
)
return None

# Try to use exact match first, otherwise use first available product
product_entity = product_entities_by_name.get(product_name)
Expand Down Expand Up @@ -837,6 +872,7 @@ def _get_global_config_data(

path = get_representation_path_with_anatomy(repre_entity, anatomy)
template = repre_entity["attrib"]["template"]

return {
"path": path,
"template": template,
Expand Down
38 changes: 38 additions & 0 deletions server/settings/conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,43 @@
from .publish_plugins import DEFAULT_PUBLISH_VALUES


def _convert_imageio_configs_0_4_4(overrides):
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
"""Imageio config settings did change to profiles since 0.4.4."""
imageio_overrides = overrides.get("imageio") or {}

# make sure settings are already converted to profiles
if (
"ocio_config_profiles" not in imageio_overrides
):
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
return

ocio_config_profiles = imageio_overrides["ocio_config_profiles"]

for inx, profile in enumerate(ocio_config_profiles):
if profile["type"] != "product_name":
continue

# create new profile
new_profile = {
"type": "published_product",
"published_product": {
"product_name": profile["product_name"],
"fallback": {
"type": "builtin_path",
"builtin_path": "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio",
},
},
"host_names": profile["host_names"],
"task_names": profile["task_names"],
"task_types": profile["task_types"],
"custom_path": profile["custom_path"],
"builtin_path": profile["builtin_path"],
}

# replace old profile with new profile
ocio_config_profiles[inx] = new_profile
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved


def _convert_imageio_configs_0_3_1(overrides):
"""Imageio config settings did change to profiles since 0.3.1. ."""
imageio_overrides = overrides.get("imageio") or {}
Expand Down Expand Up @@ -82,5 +119,6 @@ def convert_settings_overrides(
overrides: dict[str, Any],
) -> dict[str, Any]:
_convert_imageio_configs_0_3_1(overrides)
_convert_imageio_configs_0_4_4(overrides)
_conver_publish_plugins(overrides)
return overrides
75 changes: 66 additions & 9 deletions server/settings/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ def _ocio_config_profile_types():
return [
{"value": "builtin_path", "label": "AYON built-in OCIO config"},
{"value": "custom_path", "label": "Path to OCIO config"},
{"value": "product_name", "label": "Published product"},
{"value": "published_product", "label": "Published product"},
]


def _fallback_ocio_config_profile_types():
return [
{"value": "builtin_path", "label": "AYON built-in OCIO config"},
{"value": "custom_path", "label": "Path to OCIO config"},
]


Expand All @@ -76,6 +83,49 @@ def _ocio_built_in_paths():
]


class FallbackProductModel(BaseSettingsModel):
_layout = "expanded"
type: str = SettingsField(
jakubjezek001 marked this conversation as resolved.
Show resolved Hide resolved
title="Fallback config type",
enum_resolver=_fallback_ocio_config_profile_types,
conditionalEnum=True,
default="builtin_path",
description=(
"Type of config which needs to be used in case published "
"product is not found."
),
)
builtin_path: str = SettingsField(
"ACES 1.2",
title="Built-in OCIO config",
enum_resolver=_ocio_built_in_paths,
description=(
"AYON ocio addon distributed OCIO config. "
"Activated addon in bundle is required: 'ayon_ocio' >= 1.1.1"
),
)
custom_path: str = SettingsField(
"",
title="OCIO config path",
description="Path to OCIO config. Anatomy formatting is supported.",
)


class PublishedProductModel(BaseSettingsModel):
_layout = "expanded"
product_name: str = SettingsField(
"",
title="Product name",
description=(
"Context related published product name to get OCIO config from. "
"Partial match is supported via use of regex expression."
),
)
fallback: FallbackProductModel = SettingsField(
default_factory=FallbackProductModel,
)


class CoreImageIOConfigProfilesModel(BaseSettingsModel):
_layout = "expanded"
host_names: list[str] = SettingsField(
Expand All @@ -102,19 +152,19 @@ class CoreImageIOConfigProfilesModel(BaseSettingsModel):
"ACES 1.2",
title="Built-in OCIO config",
enum_resolver=_ocio_built_in_paths,
description=(
"AYON ocio addon distributed OCIO config. "
"Activated addon in bundle is required: 'ayon_ocio' >= 1.1.1"
),
)
custom_path: str = SettingsField(
"",
title="OCIO config path",
description="Path to OCIO config. Anatomy formatting is supported.",
)
product_name: str = SettingsField(
"",
title="Product name",
description=(
"Published product name to get OCIO config from. "
"Partial match is supported."
),
published_product: PublishedProductModel = SettingsField(
default_factory=PublishedProductModel,
title="Published product",
)


Expand Down Expand Up @@ -294,7 +344,14 @@ def validate_json(cls, value):
"type": "builtin_path",
"builtin_path": "{BUILTIN_OCIO_ROOT}/aces_1.2/config.ocio",
"custom_path": "",
"product_name": "",
"published_product": {
"product_name": "",
"fallback": {
"type": "builtin_path",
"builtin_path": "ACES 1.2",
"custom_path": ""
}
}
}
],
"file_rules": {
Expand Down