From 49448fc3ffb13d04281e9bb691ab443f0ed2dbd2 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 5 Sep 2024 16:08:03 +0300 Subject: [PATCH 01/17] fix running builder on start if scene is the default scene --- .../workfile/workfile_template_builder.py | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 7b15dff049..1fce07a722 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -533,29 +533,20 @@ def build_template( if create_first_version: created_version_workfile = self.create_first_workfile_version() - # if first version is created, import template - # and populate placeholders + # Build the template if ( create_first_version and workfile_creation_enabled - and created_version_workfile + and (created_version_workfile or self.host.get_current_workfile() is None) ): self.import_template(template_path) self.populate_scene_placeholders( level_limit, keep_placeholders) - # save workfile after template is populated + # save workfile if a workfile was created. + if created_version_workfile: self.save_workfile(created_version_workfile) - # ignore process if first workfile is enabled - # but a version is already created - if workfile_creation_enabled: - return - - self.import_template(template_path) - self.populate_scene_placeholders( - level_limit, keep_placeholders) - def rebuild_template(self): """Go through existing placeholders in scene and update them. From e4881e2fec7599863e311fd9124db89bc35fd2b8 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Thu, 5 Sep 2024 22:04:55 +0300 Subject: [PATCH 02/17] refactor and simplify `build_template` method --- .../workfile/workfile_template_builder.py | 29 ++++++------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 1fce07a722..283408452e 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -512,39 +512,28 @@ def build_template( process if version is created """ - if any( - value is None - for value in [ - template_path, - keep_placeholders, - create_first_version, - ] - ): - template_preset = self.get_template_preset() - if template_path is None: - template_path = template_preset["path"] + # Get default values if not provided + if template_path is None or keep_placeholders is None or create_first_version is None: + preset = self.get_template_preset() + template_path = template_path or preset["path"] if keep_placeholders is None: - keep_placeholders = template_preset["keep_placeholder"] + keep_placeholders = preset["keep_placeholder"] if create_first_version is None: - create_first_version = template_preset["create_first_version"] + create_first_version = preset["create_first_version"] # check if first version is created - created_version_workfile = False - if create_first_version: - created_version_workfile = self.create_first_workfile_version() + created_version_workfile = create_first_version and self.create_first_workfile_version() # Build the template if ( - create_first_version - and workfile_creation_enabled - and (created_version_workfile or self.host.get_current_workfile() is None) + not self.host.get_current_workfile() or created_version_workfile ): self.import_template(template_path) self.populate_scene_placeholders( level_limit, keep_placeholders) # save workfile if a workfile was created. - if created_version_workfile: + if workfile_creation_enabled and created_version_workfile: self.save_workfile(created_version_workfile) def rebuild_template(self): From 274585ced6e7a7c1c4582e0c28ddf0346b4a9039 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 6 Sep 2024 11:41:21 +0300 Subject: [PATCH 03/17] Optimize the code --- .../workfile/workfile_template_builder.py | 28 +++++++++++-------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 283408452e..abee71f8ec 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -521,19 +521,26 @@ def build_template( if create_first_version is None: create_first_version = preset["create_first_version"] - # check if first version is created + # Create, open and return the first workfile version. + # This only works if there are no existent files and + # create_first_version is enabled. created_version_workfile = create_first_version and self.create_first_workfile_version() - # Build the template - if ( - not self.host.get_current_workfile() or created_version_workfile - ): + # # Abort the process if workfile_creation_enabled. + # if workfile_creation_enabled: + # return + + # Build the template if the current scene is empty + # or if we have created new file. + # which basically avoids any + if not self.host.get_current_workfile() or created_version_workfile: + self.log.info(f"Building the workfile template: {template_path}") self.import_template(template_path) self.populate_scene_placeholders( level_limit, keep_placeholders) # save workfile if a workfile was created. - if workfile_creation_enabled and created_version_workfile: + if created_version_workfile: self.save_workfile(created_version_workfile) def rebuild_template(self): @@ -833,11 +840,10 @@ def get_template_preset(self): keep_placeholder = True if not path: - raise TemplateLoadFailed(( - "Template path is not set.\n" - "Path need to be set in {}\\Template Workfile Build " - "Settings\\Profiles" - ).format(host_name.title())) + self.log.info( + "Template path is not set." + ) + return # Try fill path with environments and anatomy roots anatomy = Anatomy(project_name) From df203db3d7fa5c9e2d8877f550372c96b8496616 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:16:28 +0200 Subject: [PATCH 04/17] Refactor the `build_template` function for readability --- .../workfile/workfile_template_builder.py | 68 +++++++++++-------- 1 file changed, 39 insertions(+), 29 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index abee71f8ec..c535173038 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -15,6 +15,7 @@ import re import collections import copy +import warnings from abc import ABC, abstractmethod from ayon_api import ( @@ -489,7 +490,7 @@ def build_template( level_limit=None, keep_placeholders=None, create_first_version=None, - workfile_creation_enabled=False + workfile_creation_enabled=None ): """Main callback for building workfile from template path. @@ -507,41 +508,49 @@ def build_template( hosts to decide if they want to remove placeholder after it is used. create_first_version (bool): create first version of a workfile - workfile_creation_enabled (bool): If True, it might create - first version but ignore - process if version is created + workfile_creation_enabled (Any): Deprecated unused variable. """ + + if workfile_creation_enabled is not None: + warnings.warn( + ( + "Using deprecated argument `workfile_creation_enabled`. " + "It has been removed because it remained unused." + ), + category=DeprecationWarning + ) + # Get default values if not provided - if template_path is None or keep_placeholders is None or create_first_version is None: + if ( + template_path is None + or keep_placeholders is None + or create_first_version is None + ): preset = self.get_template_preset() - template_path = template_path or preset["path"] + template_path: str = template_path or preset["path"] if keep_placeholders is None: - keep_placeholders = preset["keep_placeholder"] + keep_placeholders: bool = preset["keep_placeholder"] if create_first_version is None: - create_first_version = preset["create_first_version"] - - # Create, open and return the first workfile version. - # This only works if there are no existent files and - # create_first_version is enabled. - created_version_workfile = create_first_version and self.create_first_workfile_version() - - # # Abort the process if workfile_creation_enabled. - # if workfile_creation_enabled: - # return + create_first_version: bool = preset["create_first_version"] - # Build the template if the current scene is empty - # or if we have created new file. - # which basically avoids any - if not self.host.get_current_workfile() or created_version_workfile: + # Build the template if current workfile is a new unsaved file + # (that's detected by checking if it returns any current filepath) + if not self.host.get_current_workfile(): self.log.info(f"Building the workfile template: {template_path}") self.import_template(template_path) self.populate_scene_placeholders( level_limit, keep_placeholders) - # save workfile if a workfile was created. - if created_version_workfile: - self.save_workfile(created_version_workfile) + if not create_first_version: + # Do not save whatsoever + return + + # If there is no existing workfile, save the first version + workfile_path = self.get_first_workfile_version_to_create() + if workfile_path: + self.log.info("Saving first workfile: %s", workfile_path) + self.save_workfile(workfile_path) def rebuild_template(self): """Go through existing placeholders in scene and update them. @@ -595,7 +604,7 @@ def import_template(self, template_path): pass - def create_first_workfile_version(self): + def get_first_workfile_version_to_create(self): """ Create first version of workfile. @@ -605,7 +614,12 @@ def create_first_workfile_version(self): Args: template_path (str): Fullpath for current task and host's template file. + + Return: + Optional[str]: Filepath to save to, if we should save. """ + # AYON_LAST_WORKFILE will be set to the last existing workfile OR + # if none exist it will be set to the first version. last_workfile_path = os.environ.get("AYON_LAST_WORKFILE") self.log.info("__ last_workfile_path: {}".format(last_workfile_path)) if os.path.exists(last_workfile_path): @@ -613,10 +627,6 @@ def create_first_workfile_version(self): self.log.info("Workfile already exists, skipping creation.") return False - # Create first version - self.log.info("Creating first version of workfile.") - self.save_workfile(last_workfile_path) - # Confirm creation of first version return last_workfile_path From a653ed64e45a20f35f449e8d84a180d5651e4a78 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:31:24 +0200 Subject: [PATCH 05/17] :tada: `workfile_creation_enabled` argument was actually useful after all --- .../workfile/workfile_template_builder.py | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index c535173038..9986e8ddae 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -15,7 +15,6 @@ import re import collections import copy -import warnings from abc import ABC, abstractmethod from ayon_api import ( @@ -508,19 +507,12 @@ def build_template( hosts to decide if they want to remove placeholder after it is used. create_first_version (bool): create first version of a workfile - workfile_creation_enabled (Any): Deprecated unused variable. + workfile_creation_enabled (Any): Whether we are creating a new + workfile. If False, we assume we just want to build the + template in our current scene. """ - if workfile_creation_enabled is not None: - warnings.warn( - ( - "Using deprecated argument `workfile_creation_enabled`. " - "It has been removed because it remained unused." - ), - category=DeprecationWarning - ) - # Get default values if not provided if ( template_path is None @@ -542,6 +534,12 @@ def build_template( self.populate_scene_placeholders( level_limit, keep_placeholders) + if not workfile_creation_enabled: + # Do not consider saving a first workfile version, if this + # is not set to be a "workfile creation". Then we assume + # only the template should get build. + return + if not create_first_version: # Do not save whatsoever return From b470ff214d2c05dbd367e9bf6438caa768aaf39c Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:33:55 +0200 Subject: [PATCH 06/17] Elaborate `create_first_version` argument to differentiate from `workfile_creation_enabled` --- .../ayon_core/pipeline/workfile/workfile_template_builder.py | 5 ++++- 1 file changed, 4 insertions(+), 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 9986e8ddae..c28b156e46 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -506,7 +506,10 @@ def build_template( keep_placeholders (bool): Add flag to placeholder data for hosts to decide if they want to remove placeholder after it is used. - create_first_version (bool): create first version of a workfile + create_first_version (bool): Create first version of a workfile. + When set to True, this option initiates the saving of the + workfile for an initial version. It will skip saving if + a version already exists. workfile_creation_enabled (Any): Whether we are creating a new workfile. If False, we assume we just want to build the template in our current scene. From 0ca2e1044f0efdd3e25cde6ce391b2cd4ab6d8f7 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:35:43 +0200 Subject: [PATCH 07/17] Fix argument signature --- .../ayon_core/pipeline/workfile/workfile_template_builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index c28b156e46..e2c06db328 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -489,7 +489,7 @@ def build_template( level_limit=None, keep_placeholders=None, create_first_version=None, - workfile_creation_enabled=None + workfile_creation_enabled=False ): """Main callback for building workfile from template path. @@ -510,7 +510,7 @@ def build_template( When set to True, this option initiates the saving of the workfile for an initial version. It will skip saving if a version already exists. - workfile_creation_enabled (Any): Whether we are creating a new + workfile_creation_enabled (bool): Whether we are creating a new workfile. If False, we assume we just want to build the template in our current scene. From 0faaadab51b0e7b74c483a32e406f90b49f45636 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Fri, 6 Sep 2024 17:47:25 +0200 Subject: [PATCH 08/17] Fix case of explicit load import and improve docstring --- .../workfile/workfile_template_builder.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index b24a4ab653..8bd9c00773 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -511,8 +511,10 @@ def build_template( workfile for an initial version. It will skip saving if a version already exists. workfile_creation_enabled (bool): Whether we are creating a new - workfile. If False, we assume we just want to build the - template in our current scene. + workfile. If False, we assume we explicitly want to build the + template in our current scene. Otherwise we only build if the + current file is not an existing saved workfile but a "new" + file. """ @@ -531,7 +533,14 @@ def build_template( # Build the template if current workfile is a new unsaved file # (that's detected by checking if it returns any current filepath) - if not self.host.get_current_workfile(): + if ( + # If not a workfile creation, an explicit load template + # was requested, so we always want to build the template + not workfile_creation_enabled + # Or if workfile creation, but we're not in an active file + # we still need to build the "new workfile template" + or not self.host.get_current_workfile() + ): self.log.info(f"Building the workfile template: {template_path}") self.import_template(template_path) self.populate_scene_placeholders( From a27157f46d90b8f08fc858583dc4dd85ffc15940 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 15:58:20 +0200 Subject: [PATCH 09/17] Please @fabiaserra's eyes with better indentation --- .../pipeline/workfile/workfile_template_builder.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 8bd9c00773..aaa8a951c2 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -520,9 +520,9 @@ def build_template( # Get default values if not provided if ( - template_path is None - or keep_placeholders is None - or create_first_version is None + template_path is None + or keep_placeholders is None + or create_first_version is None ): preset = self.get_template_preset() template_path: str = template_path or preset["path"] From 3df68ef2a5b1e6c8bda457b96ebfe153480e1bbe Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 15:59:32 +0200 Subject: [PATCH 10/17] `workfile_creation_enabled` docstring, first explain the `True` case. --- .../pipeline/workfile/workfile_template_builder.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index aaa8a951c2..9537096794 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -511,10 +511,11 @@ def build_template( workfile for an initial version. It will skip saving if a version already exists. workfile_creation_enabled (bool): Whether we are creating a new - workfile. If False, we assume we explicitly want to build the - template in our current scene. Otherwise we only build if the - current file is not an existing saved workfile but a "new" - file. + workfile. When True, we only build if the current file is not + an existing saved workfile but a "new" file. When False, the + default value, we assume we explicitly want to build the + template in our current scene regardless of current scene + state. """ From e7f7eaba680a779323f1a4cd1b28d68d8c346593 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:01:57 +0200 Subject: [PATCH 11/17] Elaborate more --- .../workfile/workfile_template_builder.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 9537096794..86cb4b3f86 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -510,12 +510,15 @@ def build_template( When set to True, this option initiates the saving of the workfile for an initial version. It will skip saving if a version already exists. - workfile_creation_enabled (bool): Whether we are creating a new - workfile. When True, we only build if the current file is not - an existing saved workfile but a "new" file. When False, the - default value, we assume we explicitly want to build the - template in our current scene regardless of current scene - state. + workfile_creation_enabled (bool): Whether the call is part of + creating a new workfile. + When True, we only build if the current file is not + an existing saved workfile but a "new" file. Basically when + enabled we assume the user tries to load it only into a + "New File" (unsaved empty workfile). + When False, the default value, we assume we explicitly want to + build the template in our current scene regardless of current + scene state. """ From 522b205a92625eb5c2188f8f6e0d5b6a7bb6e72b Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:07:17 +0200 Subject: [PATCH 12/17] Refactor logic with better function names --- .../workfile/workfile_template_builder.py | 28 ++++++------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 86cb4b3f86..7ea69b3f8f 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -561,10 +561,14 @@ def build_template( return # If there is no existing workfile, save the first version - workfile_path = self.get_first_workfile_version_to_create() - if workfile_path: + workfile_path = self.get_workfile_path() + if not os.path.exists(workfile_path): self.log.info("Saving first workfile: %s", workfile_path) self.save_workfile(workfile_path) + else: + self.log.info( + "A workfile already exists. Skipping save of workfile as " + "initial version.") def rebuild_template(self): """Go through existing placeholders in scene and update them. @@ -618,30 +622,16 @@ def import_template(self, template_path): pass - def get_first_workfile_version_to_create(self): - """ - Create first version of workfile. - - Should load the content of template into scene so - 'populate_scene_placeholders' can be started. - - Args: - template_path (str): Fullpath for current task and - host's template file. + def get_workfile_path(self): + """Return last known workfile path or the first workfile path create. Return: - Optional[str]: Filepath to save to, if we should save. + str: Last workfile path, or first version to create if none exist. """ # AYON_LAST_WORKFILE will be set to the last existing workfile OR # if none exist it will be set to the first version. last_workfile_path = os.environ.get("AYON_LAST_WORKFILE") self.log.info("__ last_workfile_path: {}".format(last_workfile_path)) - if os.path.exists(last_workfile_path): - # ignore in case workfile existence - self.log.info("Workfile already exists, skipping creation.") - return False - - # Confirm creation of first version return last_workfile_path def save_workfile(self, workfile_path): From d65b84cf2fea40c615fdf04a14831175e1e37c59 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:09:21 +0200 Subject: [PATCH 13/17] Tweak comment to describe both the cases in the if statement --- .../ayon_core/pipeline/workfile/workfile_template_builder.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 7ea69b3f8f..8495529924 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -535,8 +535,8 @@ def build_template( if create_first_version is None: create_first_version: bool = preset["create_first_version"] - # Build the template if current workfile is a new unsaved file - # (that's detected by checking if it returns any current filepath) + # Build the template if we are explicitly requesting it or if it's + # an unsaved "new file". if ( # If not a workfile creation, an explicit load template # was requested, so we always want to build the template From cfcce2138347a0928e42021384960a87797bc567 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 16:14:25 +0200 Subject: [PATCH 14/17] Separate into variables for readability --- .../pipeline/workfile/workfile_template_builder.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 8495529924..673ca7922e 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -537,14 +537,9 @@ def build_template( # Build the template if we are explicitly requesting it or if it's # an unsaved "new file". - if ( - # If not a workfile creation, an explicit load template - # was requested, so we always want to build the template - not workfile_creation_enabled - # Or if workfile creation, but we're not in an active file - # we still need to build the "new workfile template" - or not self.host.get_current_workfile() - ): + is_new_file = not self.host.get_current_workfile() + explicit_build_requested = not workfile_creation_enabled + if is_new_file or explicit_build_requested: self.log.info(f"Building the workfile template: {template_path}") self.import_template(template_path) self.populate_scene_placeholders( From 057a5fffcf96a6c7dc48efb845e21c47de935d6a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Mon, 9 Sep 2024 17:23:26 +0200 Subject: [PATCH 15/17] Simplify logic --- .../pipeline/workfile/workfile_template_builder.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index 673ca7922e..026eacc19f 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -545,14 +545,9 @@ def build_template( self.populate_scene_placeholders( level_limit, keep_placeholders) - if not workfile_creation_enabled: - # Do not consider saving a first workfile version, if this - # is not set to be a "workfile creation". Then we assume - # only the template should get build. - return - - if not create_first_version: - # Do not save whatsoever + # Do not consider saving a first workfile version, if this is not set + # to be a "workfile creation" or `create_first_version` is disabled. + if explicit_build_requested or not create_first_version: return # If there is no existing workfile, save the first version From ab498dd7e1edd5f4db0003dcb314aa016dfa889a Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Thu, 12 Sep 2024 15:03:14 +0200 Subject: [PATCH 16/17] Update client/ayon_core/pipeline/workfile/workfile_template_builder.py Co-authored-by: Mustafa Jafar --- .../pipeline/workfile/workfile_template_builder.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/client/ayon_core/pipeline/workfile/workfile_template_builder.py b/client/ayon_core/pipeline/workfile/workfile_template_builder.py index a908e76222..17debdb2e8 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -844,10 +844,11 @@ def get_template_preset(self): keep_placeholder = True if not path: - self.log.info( - "Template path is not set." - ) - return + raise TemplateLoadFailed(( + "Template path is not set.\n" + "Path need to be set in {}\\Template Workfile Build " + "Settings\\Profiles" + ).format(host_name.title())) # Try to fill path with environments and anatomy roots anatomy = Anatomy(project_name) From 7298ddb745e003ca8e317eae3baccab246a2ad37 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Wed, 2 Oct 2024 12:27:32 +0300 Subject: [PATCH 17/17] add note about using more accurate variable names --- .../ayon_core/pipeline/workfile/workfile_template_builder.py | 4 +++- 1 file changed, 3 insertions(+), 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 17debdb2e8..4412e4489b 100644 --- a/client/ayon_core/pipeline/workfile/workfile_template_builder.py +++ b/client/ayon_core/pipeline/workfile/workfile_template_builder.py @@ -521,6 +521,9 @@ def build_template( scene state. """ + # More accurate variable name + # - logic related to workfile creation should be moved out in future + explicit_build_requested = not workfile_creation_enabled # Get default values if not provided if ( @@ -538,7 +541,6 @@ def build_template( # Build the template if we are explicitly requesting it or if it's # an unsaved "new file". is_new_file = not self.host.get_current_workfile() - explicit_build_requested = not workfile_creation_enabled if is_new_file or explicit_build_requested: self.log.info(f"Building the workfile template: {template_path}") self.import_template(template_path)