changing signature of parse_colorspace_from_filepath

This commit is contained in:
Jakub Jezek 2023-08-28 14:00:52 +02:00
parent c2212a6cc1
commit e10ca74b1b
No known key found for this signature in database
GPG key ID: 730D7C02726179A7
2 changed files with 27 additions and 24 deletions

View file

@ -171,8 +171,6 @@ def get_imageio_colorspace_from_filepath(
# from filepath with OCIO v2 way
# QUESTION: should we override file rules from our settings and
# in ocio v2 only focus on file rules set in config file?
# TODO: do the ocio v compatibility check inside of wrapper script
# because of implementation `parseColorSpaceFromString`
if (
compatibility_check_config_version(config_data["path"], major=2)
and not colorspace_name
@ -226,51 +224,56 @@ def get_colorspace_from_filepath(config_path, filepath):
def parse_colorspace_from_filepath(
path, host_name, project_name,
config_data=None,
project_settings=None
filepath, colorspaces=None, config_path=None
):
"""Parse colorspace name from filepath
"""Parse colorspace name from list of filepaths
An input path can have colorspace name used as part of name
or as folder name.
# add example python code block
Example:
>>> config_path = "path/to/config.ocio"
>>> colorspaces = get_ocio_config_colorspaces(config_path)
>>> colorspace = parse_colorspace_from_filepath(
"path/to/file/acescg/file.exr",
colorspaces=colorspaces
)
>>> print(colorspace)
acescg
Args:
path (str): path string
host_name (str): host name
project_name (str): project name
config_data (dict, optional): config path and template in dict.
Defaults to None.
project_settings (dict, optional): project settings. Defaults to None.
filepath (str): path string
colorspaces (Optional[dict[str]]): list of colorspaces
config_path (Optional[str]): path to config.ocio file
Returns:
str: name of colorspace
"""
if not config_data:
project_settings = project_settings or get_project_settings(
project_name
if not colorspaces and not config_path:
raise ValueError(
"You need to provide `config_path` if you don't "
"want to provide input `colorspaces`."
)
config_data = get_imageio_config(
project_name, host_name, project_settings)
config_path = config_data["path"]
colorspaces = colorspaces or get_ocio_config_colorspaces(config_path)
# match file rule from path
colorspace_name = None
colorspaces = get_ocio_config_colorspaces(config_path)
for colorspace_key in colorspaces:
# check underscored variant of colorspace name
# since we are reformatting it in integrate.py
if colorspace_key.replace(" ", "_") in path:
if colorspace_key.replace(" ", "_") in filepath:
colorspace_name = colorspace_key
break
if colorspace_key in path:
if colorspace_key in filepath:
colorspace_name = colorspace_key
break
if not colorspace_name:
log.info("No matching colorspace in config '{}' for path: '{}'".format(
config_path, path
config_path, filepath
))
return None

View file

@ -132,14 +132,14 @@ class TestPipelineColorspace(TestPipeline):
path_1 = "renderCompMain_ACES2065-1.####.exr"
expected_1 = "ACES2065-1"
ret_1 = colorspace.parse_colorspace_from_filepath(
path_1, "nuke", "test_project", project_settings=project_settings
path_1, config_path=config_path_asset
)
assert ret_1 == expected_1, f"Not matching colorspace {expected_1}"
path_2 = "renderCompMain_BMDFilm_WideGamut_Gen5.mov"
expected_2 = "BMDFilm WideGamut Gen5"
ret_2 = colorspace.parse_colorspace_from_filepath(
path_2, "nuke", "test_project", project_settings=project_settings
path_2, config_path=config_path_asset
)
assert ret_2 == expected_2, f"Not matching colorspace {expected_2}"