Skip to content

Commit

Permalink
Improve dependency versions support.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Mansencal <[email protected]>
  • Loading branch information
KelSolaar committed Sep 2, 2023
1 parent 3f43963 commit 0670239
Show file tree
Hide file tree
Showing 20 changed files with 301 additions and 523 deletions.
7 changes: 4 additions & 3 deletions docs/opencolorio_config_aces.config.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
Generation
==========

Profile Version
---------------
Version Utilities
-----------------

``opencolorio_config_aces``

Expand All @@ -15,9 +15,10 @@ Profile Version
.. autosummary::
:toctree: generated/

ProfileVersion
PROFILE_VERSION_DEFAULT
SUPPORTED_PROFILE_VERSIONS
DependencyVersions
DEPENDENCY_VERSIONS

Config Generation Common Objects
--------------------------------
Expand Down
7 changes: 2 additions & 5 deletions opencolorio_config_aces/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
BUILTIN_TRANSFORMS,
ConfigData,
PROFILE_VERSION_DEFAULT,
ProfileVersion,
SUPPORTED_PROFILE_VERSIONS,
PROFILE_VERSIONS,
deserialize_config_data,
generate_config,
serialize_config_data,
Expand All @@ -54,7 +53,6 @@
print_aces_taxonomy,
unclassify_ctl_transforms,
version_aces_dev,
version_config_mapping_file,
)
from .config import (
DescriptionStyle,
Expand Down Expand Up @@ -91,8 +89,7 @@
"BUILTIN_TRANSFORMS",
"ConfigData",
"PROFILE_VERSION_DEFAULT",
"ProfileVersion",
"SUPPORTED_PROFILE_VERSIONS",
"PROFILE_VERSIONS",
"deserialize_config_data",
"generate_config",
"serialize_config_data",
Expand Down
12 changes: 6 additions & 6 deletions opencolorio_config_aces/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
)
from .generation import (
BUILTIN_TRANSFORMS,
DEPENDENCY_VERSIONS,
ConfigData,
PROFILE_VERSION_DEFAULT,
ProfileVersion,
SUPPORTED_PROFILE_VERSIONS,
PROFILE_VERSIONS,
DependencyVersions,
deserialize_config_data,
generate_config,
serialize_config_data,
Expand All @@ -36,7 +37,6 @@
print_aces_taxonomy,
unclassify_ctl_transforms,
version_aces_dev,
version_config_mapping_file,
)
from .reference import (
DescriptionStyle,
Expand All @@ -57,10 +57,11 @@
]
__all__ += [
"BUILTIN_TRANSFORMS",
"DEPENDENCY_VERSIONS",
"ConfigData",
"PROFILE_VERSION_DEFAULT",
"ProfileVersion",
"SUPPORTED_PROFILE_VERSIONS",
"PROFILE_VERSIONS",
"DependencyVersions",
"deserialize_config_data",
"generate_config",
"serialize_config_data",
Expand All @@ -80,7 +81,6 @@
"print_aces_taxonomy",
"unclassify_ctl_transforms",
"version_aces_dev",
"version_config_mapping_file",
]
__all__ += [
"DescriptionStyle",
Expand Down
126 changes: 34 additions & 92 deletions opencolorio_config_aces/config/cg/generate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
)
from opencolorio_config_aces.config.generation import (
BUILTIN_TRANSFORMS,
PROFILE_VERSION_DEFAULT,
DEPENDENCY_VERSIONS,
DependencyVersions,
SEPARATOR_COLORSPACE_NAME,
SEPARATOR_BUILTIN_TRANSFORM_NAME,
SEPARATOR_COLORSPACE_FAMILY,
Expand All @@ -37,8 +38,6 @@
)
from opencolorio_config_aces.config.reference import (
DescriptionStyle,
version_aces_dev,
version_config_mapping_file,
generate_config_aces,
)
from opencolorio_config_aces.config.reference.generate.config import (
Expand All @@ -50,7 +49,6 @@
)
from opencolorio_config_aces.utilities import (
attest,
regularise_version,
validate_method,
timestamp,
)
Expand All @@ -75,7 +73,6 @@
"clf_transform_to_named_transform",
"style_to_colorspace",
"style_to_named_transform",
"dependency_versions",
"config_basename_cg",
"config_name_cg",
"config_description_cg",
Expand Down Expand Up @@ -648,57 +645,15 @@ def style_to_named_transform(
return colorspace


def dependency_versions(
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
profile_version=PROFILE_VERSION_DEFAULT,
):
"""
Return the dependency versions of the ACES* Computer Graphics (CG)
*OpenColorIO* config.
Parameters
----------
config_mapping_file_path : str, optional
Path to the *CSV* mapping file.
profile_version : ProfileVersion, optional
*OpenColorIO* config profile version.
Returns
-------
dict
Dependency versions.
Examples
--------
>>> dependency_versions() # doctest: +SKIP
{'aces': 'v1.3', 'ocio': 'v2.0', 'colorspaces': 'v0.2.0'}
"""

versions = {
"aces": regularise_version(version_aces_dev()),
"ocio": regularise_version(str(profile_version)),
"colorspaces": regularise_version(
version_config_mapping_file(config_mapping_file_path)
),
}

return versions


def config_basename_cg(
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
profile_version=PROFILE_VERSION_DEFAULT,
):
def config_basename_cg(dependency_versions):
"""
Generate the ACES* Computer Graphics (CG) *OpenColorIO* config
basename, i.e. the filename devoid of directory affix.
Parameters
----------
config_mapping_file_path : str, optional
Path to the *CSV* mapping file.
profile_version : ProfileVersion, optional
*OpenColorIO* config profile version.
dependency_versions: DependencyVersions
Dependency versions, e.g. *aces-dev*, *colorspaces*, and *OpenColorIO*.
Returns
-------
Expand All @@ -707,28 +662,23 @@ def config_basename_cg(
Examples
--------
>>> config_basename_cg() # doctest: +SKIP
'cg-config-v0.2.0_aces-v1.3_ocio-v2.0.ocio'
>>> config_basename_cg(DependencyVersions())
'cg-config-v0.0.0_aces-v0.0_ocio-v2.0.ocio'
"""

return ("cg-config-{colorspaces}_aces-{aces}_ocio-{ocio}.ocio").format(
**dependency_versions(config_mapping_file_path, profile_version)
**dependency_versions.to_regularised_versions()
)


def config_name_cg(
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
profile_version=PROFILE_VERSION_DEFAULT,
):
def config_name_cg(dependency_versions):
"""
Generate the ACES* Computer Graphics (CG) *OpenColorIO* config name.
Parameters
----------
config_mapping_file_path : str, optional
Path to the *CSV* mapping file.
profile_version : ProfileVersion, optional
*OpenColorIO* config profile version.
dependency_versions: DependencyVersions
Dependency versions, e.g. *aces-dev*, *colorspaces*, and *OpenColorIO*.
Returns
-------
Expand All @@ -737,22 +687,21 @@ def config_name_cg(
Examples
--------
>>> config_name_cg() # doctest: +SKIP
'Academy Color Encoding System - CG Config [COLORSPACES v0.2.0] \
[ACES v1.3] [OCIO v2.0]'
>>> config_name_cg(DependencyVersions())
'Academy Color Encoding System - CG Config [COLORSPACES v0.0.0] \
[ACES v0.0] [OCIO v2.0]'
"""

return (
"Academy Color Encoding System - CG Config "
"[COLORSPACES {colorspaces}] "
"[ACES {aces}] "
"[OCIO {ocio}]"
).format(**dependency_versions(config_mapping_file_path, profile_version))
).format(**dependency_versions.to_regularised_versions())


def config_description_cg(
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
profile_version=PROFILE_VERSION_DEFAULT,
dependency_versions,
describe=DescriptionStyle.SHORT_UNION,
):
"""
Expand All @@ -761,10 +710,8 @@ def config_description_cg(
Parameters
----------
config_mapping_file_path : str, optional
Path to the *CSV* mapping file.
profile_version : ProfileVersion, optional
*OpenColorIO* config profile version.
dependency_versions: DependencyVersions
Dependency versions, e.g. *aces-dev*, *colorspaces*, and *OpenColorIO*.
describe : int, optional
Any value from the
:class:`opencolorio_config_aces.DescriptionStyle` enum.
Expand All @@ -775,7 +722,7 @@ def config_description_cg(
ACES* Computer Graphics (CG) *OpenColorIO* config description.
"""

name = config_name_cg(config_mapping_file_path, profile_version)
name = config_name_cg(dependency_versions)

underline = "-" * len(name)

Expand All @@ -796,7 +743,7 @@ def config_description_cg(
def generate_config_cg(
data=None,
config_name=None,
profile_version=PROFILE_VERSION_DEFAULT,
dependency_versions=DependencyVersions(),
validate=True,
describe=DescriptionStyle.SHORT_UNION,
config_mapping_file_path=PATH_TRANSFORMS_MAPPING_FILE_CG,
Expand Down Expand Up @@ -837,8 +784,8 @@ def generate_config_cg(
config_name : unicode, optional
*OpenColorIO* config file name, if given the config will be written to
disk.
profile_version : ProfileVersion, optional
*OpenColorIO* config profile version.
dependency_versions: DependencyVersions, optional
Dependency versions, e.g. *aces-dev*, *colorspaces*, and *OpenColorIO*.
validate : bool, optional
Whether to validate the config.
describe : int, optional
Expand All @@ -864,7 +811,7 @@ def generate_config_cg(

logger.info(
'Generating "%s" config...',
config_name_cg(config_mapping_file_path, profile_version),
config_name_cg(dependency_versions),
)

clf_transforms = unclassify_clf_transforms(
Expand All @@ -875,7 +822,7 @@ def generate_config_cg(

if data is None:
_config, data, ctl_transforms, amf_components = generate_config_aces(
profile_version=profile_version,
dependency_versions=dependency_versions,
describe=describe,
analytical=False,
scheme=scheme,
Expand Down Expand Up @@ -958,12 +905,12 @@ def clf_transform_from_style(style):
f'"{style}" "BuiltinTransform" style does not exist!',
)

if BUILTIN_TRANSFORMS[style] > profile_version:
if BUILTIN_TRANSFORMS[style] > dependency_versions.ocio:
logger.warning(
'"%s" style is unavailable for "%s" profile version, '
"skipping transform!",
style,
profile_version,
dependency_versions.ocio,
)
continue

Expand Down Expand Up @@ -1002,11 +949,9 @@ def yield_from_config_mapping():
data.name = re.sub(
r"\.ocio$",
"",
config_basename_cg(config_mapping_file_path, profile_version),
)
data.description = config_description_cg(
config_mapping_file_path, profile_version
config_basename_cg(dependency_versions),
)
data.description = config_description_cg(dependency_versions, describe)

# Colorspaces, Looks and View Transforms Filtering
transforms = data.colorspaces + data.view_transforms
Expand Down Expand Up @@ -1252,13 +1197,13 @@ def view_filterer(transform):
}
)

data.profile_version = profile_version
data.profile_version = dependency_versions.ocio

config = generate_config(data, config_name, validate)

logger.info(
'"%s" config generation complete!',
config_name_cg(config_mapping_file_path, profile_version),
config_name_cg(dependency_versions),
)

if additional_data:
Expand All @@ -1268,10 +1213,7 @@ def view_filterer(transform):


if __name__ == "__main__":
from opencolorio_config_aces import (
SUPPORTED_PROFILE_VERSIONS,
serialize_config_data,
)
from opencolorio_config_aces import serialize_config_data
from opencolorio_config_aces.utilities import ROOT_BUILD_DEFAULT

logging.basicConfig()
Expand All @@ -1283,8 +1225,8 @@ def view_filterer(transform):

build_directory.mkdir(parents=True, exist_ok=True)

for profile_version in SUPPORTED_PROFILE_VERSIONS:
config_basename = config_basename_cg(profile_version=profile_version)
for dependency_versions in DEPENDENCY_VERSIONS:
config_basename = config_basename_cg(dependency_versions)
(
config,
data,
Expand All @@ -1293,7 +1235,7 @@ def view_filterer(transform):
amf_components,
) = generate_config_cg(
config_name=build_directory / config_basename,
profile_version=profile_version,
dependency_versions=dependency_versions,
additional_data=True,
)

Expand Down
Loading

0 comments on commit 0670239

Please sign in to comment.