Context¶
- class PyOpenColorIO.Context¶
Context
A context defines some overrides to a Config. For example, it can override the search path or change the value of a context variable.
Note
Only some Config::getProcessor methods accept a custom context; otherwise, the default context instance is used (see Config::getCurrentContext).
Context Variables
The context variables allow changes at runtime using environment variables. For example, a color space name (such as src & dst for the ColorSpaceTransform) or a file name (such as LUT file name for the FileTransform) could be defined by context variables. The color transformation is then customized based on some environment variables.
In a config the context variables support three syntaxes (i.e. ${VAR}, $VAR and VAR%) and the parsing starts from longest to shortest. So, the resolve works like ‘$TEST_$TESTING_$TE’ expands in this order ‘2 1 3’.
Config authors are recommended to include the “environment” section in their configs. This improves performance as well as making the config more readable. When present, this section must declare all context variables used in the config. It may also provide a default value, in case the variable is not present in the user’s environment.
A context variable may only be used in the following places: - the :ref:`ColorSpaceTransform` to define the source and the destination color space names, - the :ref:`FileTransform` to define the source file name (e.g. a LUT file name), - the search_path, - the cccid of the :ref:`FileTransform` to only extract one specific transform from the CDL & CCC files.
Some specific restrictions are worth calling out: - they cannot be used as either the name or value of a role, - the context variable characters $ and % are prohibited in a color space name.
- Context(*args, **kwargs)¶
Overloaded function.
__init__(self: PyOpenColorIO.Context) -> None
__init__(self: PyOpenColorIO.Context, workingDir: str = ‘’, searchPaths: List[str] = [], stringVars: Dict[str, str] = {}, environmentMode: PyOpenColorIO.EnvironmentMode = <EnvironmentMode.ENV_ENVIRONMENT_LOAD_PREDEFINED: 1>) -> None
- addSearchPath(path: str) None ¶
- clearSearchPaths() None ¶
- clearStringVars() None ¶
- getCacheID() str ¶
- getEnvironmentMode() PyOpenColorIO.EnvironmentMode ¶
- getSearchPath() str ¶
- getSearchPaths() PyOpenColorIO.Context.SearchPathIterator ¶
- getStringVars() PyOpenColorIO.Context.StringVarIterator ¶
- getWorkingDir() str ¶
- loadEnvironment() None ¶
Seed all string vars with the current environment.
- resolveFileLocation(*args, **kwargs)¶
Overloaded function.
resolveFileLocation(self: PyOpenColorIO.Context, filename: str) -> str
Build the resolved and expanded filepath using the search_path when needed, and check if the filepath exists. If it cannot be resolved or found, an exception will be thrown. The method argument is directly from the config file so it can be an absolute or relative file path or a file name.
Note
The filepath existence check could add a performance hit.
Note
The context variable resolution is performed using
resolveStringVar()
.resolveFileLocation(self: PyOpenColorIO.Context, filename: str, usedContextVars: PyOpenColorIO.Context) -> str
Build the resolved and expanded filepath and return all the context variables used to resolve the filename (empty if no context variables were used).
- resolveStringVar(*args, **kwargs)¶
Overloaded function.
resolveStringVar(self: PyOpenColorIO.Context, string: str) -> str
Resolve all the context variables from the string. It could be color space names or file names. Note that it recursively applies the context variable resolution. Returns the string unchanged if it does not contain any context variable.
resolveStringVar(self: PyOpenColorIO.Context, string: str, usedContextVars: PyOpenColorIO.Context) -> str
Resolve all the context variables from the string and return all the context variables used to resolve the string (empty if no context variables were used).
- setEnvironmentMode(mode: PyOpenColorIO.EnvironmentMode) None ¶
- setSearchPath(path: str) None ¶
- setWorkingDir(dirName: str) None ¶
- class PyOpenColorIO.Context.StringVarNameIterator¶
- self[arg0: int] str ¶
- iter(self) PyOpenColorIO.Context.StringVarNameIterator ¶
- len(self) int ¶
- next(self) str ¶
-
class Context¶
-
A context defines some overrides to a Config. For example, it can override the search path or change the value of a context variable.
Context Variables
The context variables allow changes at runtime using environment variables. For example, a color space name (such as src & dst for the ColorSpaceTransform) or a file name (such as LUT file name for the FileTransform) could be defined by context variables. The color transformation is then customized based on some environment variables.
In a config the context variables support three syntaxes (i.e. ${VAR}, $VAR and VAR%) and the parsing starts from longest to shortest. So, the resolve works like ‘$TEST_$TESTING_$TE’ expands in this order ‘2 1 3’.
Config authors are recommended to include the “environment” section in their configs. This improves performance as well as making the config more readable. When present, this section must declare all context variables used in the config. It may also provide a default value, in case the variable is not present in the user’s environment.
A context variable may only be used in the following places:
the
ColorSpaceTransform
to define the source and the destination color space names,the
FileTransform
to define the source file name (e.g. a LUT file name),the search_path,
the cccid of the
FileTransform
to only extract one specific transform from the CDL & CCC files.
Some specific restrictions are worth calling out:
they cannot be used as either the name or value of a role,
the context variable characters $ and % are prohibited in a color space name.
Note
Only some Config::getProcessor methods accept a custom context; otherwise, the default context instance is used (see Config::getCurrentContext).
Public Functions
-
ContextRcPtr createEditableCopy() const¶
-
const char *getCacheID() const¶
-
void setSearchPath(const char *path)¶
-
const char *getSearchPath() const¶
-
int getNumSearchPaths() const¶
-
const char *getSearchPath(int index) const¶
-
void clearSearchPaths()¶
-
void addSearchPath(const char *path)¶
-
void setWorkingDir(const char *dirname)¶
-
const char *getWorkingDir() const¶
-
void setStringVar(const char *name, const char *value) noexcept¶
Add (or update) a context variable. But it removes it if the value argument is null. Note that a Context StringVar is the same thing as a Config EnvironmentVar and these are both often referred to as a “context var”.
-
const char *getStringVar(const char *name) const noexcept¶
Get the context variable value. It returns an empty string if the context variable is null or does not exist.
-
int getNumStringVars() const¶
-
const char *getStringVarNameByIndex(int index) const¶
-
const char *getStringVarByIndex(int index) const¶
-
void clearStringVars()¶
-
void addStringVars(const ConstContextRcPtr &ctx) noexcept¶
Add to the instance all the context variables from ctx.
-
void setEnvironmentMode(EnvironmentMode mode) noexcept¶
-
EnvironmentMode getEnvironmentMode() const noexcept¶
-
void loadEnvironment() noexcept¶
Seed string vars with the current environment, based on the EnvironmentMode setting.
-
const char *resolveStringVar(const char *string) const noexcept¶
Resolve all the context variables from the string. It could be color space names or file names. Note that it recursively applies the context variable resolution. Returns the string unchanged if it does not contain any context variable.
-
const char *resolveStringVar(const char *string, ContextRcPtr &usedContextVars) const noexcept¶
Resolve all the context variables from the string and return all the context variables used to resolve the string (empty if no context variables were used).
-
const char *resolveFileLocation(const char *filename) const¶
Build the resolved and expanded filepath using the search_path when needed, and check if the filepath exists. If it cannot be resolved or found, an exception will be thrown. The method argument is directly from the config file so it can be an absolute or relative file path or a file name.
Note
The filepath existence check could add a performance hit.
Note
The context variable resolution is performed using :cpp:func:
resolveStringVar
.
-
const char *resolveFileLocation(const char *filename, ContextRcPtr &usedContextVars) const¶
Build the resolved and expanded filepath and return all the context variables used to resolve the filename (empty if no context variables were used).
-
void setConfigIOProxy(ConfigIOProxyRcPtr ciop)¶
Set the ConfigIOProxy object used to provision the config and LUTs from somewhere other than the file system.
-
ConfigIOProxyRcPtr getConfigIOProxy() const¶
-
~Context()¶
Do not use (needed only for pybind11).
Public Static Functions
-
static ContextRcPtr Create()¶