Merge pull request #875 from BigRoy/enhancement/workfile_template_resolve_path

Workfile template builder: Allow custom `resolve_template_path`
This commit is contained in:
Jakub Trllo 2024-09-10 14:09:27 +02:00 committed by GitHub
commit 7653e098ce
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -859,7 +859,7 @@ class AbstractTemplateBuilder(ABC):
"Settings\\Profiles"
).format(host_name.title()))
# Try fill path with environments and anatomy roots
# Try to fill path with environments and anatomy roots
anatomy = Anatomy(project_name)
fill_data = {
key: value
@ -872,9 +872,7 @@ class AbstractTemplateBuilder(ABC):
"code": anatomy.project_code,
}
result = StringTemplate.format_template(path, fill_data)
if result.solved:
path = result.normalized()
path = self.resolve_template_path(path, fill_data)
if path and os.path.exists(path):
self.log.info("Found template at: '{}'".format(path))
@ -914,6 +912,27 @@ class AbstractTemplateBuilder(ABC):
"create_first_version": create_first_version
}
def resolve_template_path(self, path, fill_data) -> str:
"""Resolve the template path.
By default, this does nothing except returning the path directly.
This can be overridden in host integrations to perform additional
resolving over the template. Like, `hou.text.expandString` in Houdini.
Arguments:
path (str): The input path.
fill_data (dict[str, str]): Data to use for template formatting.
Returns:
str: The resolved path.
"""
result = StringTemplate.format_template(path, fill_data)
if result.solved:
path = result.normalized()
return path
def emit_event(self, topic, data=None, source=None) -> Event:
return self._event_system.emit(topic, data, source)