From f0af0a5700c8f18113099381d37ccfe73e222689 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:17:45 +0200 Subject: [PATCH 1/3] Allow custom `resolve_template_path` to be implemented by AYON addon integrations --- .../workfile/workfile_template_builder.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index be5b7437de..b65355fe8b 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -876,6 +876,8 @@ class AbstractTemplateBuilder(ABC): if result.solved: path = result.normalized() + path = self.resolve_template_path(path) + if path and os.path.exists(path): self.log.info("Found template at: '{}'".format(path)) return { @@ -914,6 +916,23 @@ class AbstractTemplateBuilder(ABC): "create_first_version": create_first_version } + def resolve_template_path(self, path: str) -> str: + """Resolve the template path. + + By default, this does nothing except returning the path directly. + But, this allows additional resolving over the template path inside + a custom AYON integration. Like, in Houdini using + `hou.text.expandString` + + Arguments: + path (str): The input path. + + Returns: + str: The resolved path. + + """ + return path + def emit_event(self, topic, data=None, source=None) -> Event: return self._event_system.emit(topic, data, source) From a8a69766ad00ea56b51f5e0c8dd3bdffebc1c67d Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:22:29 +0200 Subject: [PATCH 2/3] Move more logic into the `resolve_template_path` method --- .../workfile/workfile_template_builder.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index b65355fe8b..51dcb48420 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -872,11 +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) + path = self.resolve_template_path(path, fill_data) if path and os.path.exists(path): self.log.info("Found template at: '{}'".format(path)) @@ -916,21 +912,25 @@ class AbstractTemplateBuilder(ABC): "create_first_version": create_first_version } - def resolve_template_path(self, path: str) -> str: + def resolve_template_path(self, path, fill_data) -> str: """Resolve the template path. By default, this does nothing except returning the path directly. - But, this allows additional resolving over the template path inside - a custom AYON integration. Like, in Houdini using - `hou.text.expandString` + + 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: From 0f0b7db2e1f01c57911baa323bedfb77b4922474 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:22:37 +0200 Subject: [PATCH 3/3] Fix grammar in comment --- client/ayon_core/pipeline/workfile/workfile_template_builder.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 51dcb48420..c38725ffba 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -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