AcademySoftwareFoundation / OpenColorIO

A color management framework for visual effects and animation.
https://opencolorio.org
BSD 3-Clause "New" or "Revised" License
1.8k stars 456 forks source link

validation fails - file transform source cannot be resolved #2055

Closed p0las closed 2 months ago

p0las commented 2 months ago

why is the validation failing in this case? what am I missing?

import os
import PyOpenColorIO as OCIO

os.environ['SHOT_CDL_PATH'] = 'c:/temp/a.cdl'
os.environ['SHOT_LUT_PATH'] = 'c:/temp/a.lut'

config = OCIO.Config.CreateRaw()

config.addSearchPath('search_path')

config.addEnvironmentVar('SHOT_CDL_PATH', '${SHOT_CDL_PATH}')
config.addEnvironmentVar('SHOT_LUT_PATH', '${SHOT_LUT_PATH}')

config.addColorSpace(OCIO.ColorSpace(name='foobar', family="Project", bitDepth=OCIO.BIT_DEPTH_F32, isData=False,
            description='test', allocation=OCIO.ALLOCATION_UNIFORM, allocationVars=[-0.249136, 1.468],
            fromReference=OCIO.GroupTransform([
                OCIO.FileTransform(src='${SHOT_CDL_PATH}', cccId='0', direction=OCIO.TransformDirection.TRANSFORM_DIR_FORWARD),
                OCIO.FileTransform(src='${SHOT_LUT_PATH}', interpolation=OCIO.Interpolation.INTERP_TETRAHEDRAL, direction=OCIO.TransformDirection.TRANSFORM_DIR_FORWARD)
            ])
        ))

config.validate()

it fails to resolve the env var for some reason: Exception: Config failed validation expanding file transform paths. The file transform source cannot be resolved: '${SHOT_CDL_PATH}'.

p0las commented 2 months ago

It looks like when config.addEnvironmentVar is called, the internal environment variable lookup is reset with the default value provided (here the syntax to indicate none), so that later validate call can’t see the original value assigned with os.environ. You could do this before calling validate to refresh the lookup map:

config.setEnvironmentMode(OCIO.ENV_ENVIRONMENT_LOAD_PREDEFINED)
config.loadEnvironment()