Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix running builder on start if scene is the default empty scene #871

Merged
merged 23 commits into from
Oct 2, 2024
Merged
Changes from 9 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
49448fc
fix running builder on start if scene is the default scene
MustafaJafar Sep 5, 2024
e4881e2
refactor and simplify `build_template` method
MustafaJafar Sep 5, 2024
274585c
Optimize the code
MustafaJafar Sep 6, 2024
df203db
Refactor the `build_template` function for readability
BigRoy Sep 6, 2024
a653ed6
:tada: `workfile_creation_enabled` argument was actually useful after…
BigRoy Sep 6, 2024
b470ff2
Elaborate `create_first_version` argument to differentiate from `work…
BigRoy Sep 6, 2024
c349f7e
Merge branch 'develop' into bugfix/workfile_builder_on_start
BigRoy Sep 6, 2024
0ca2e10
Fix argument signature
BigRoy Sep 6, 2024
cac1791
Merge branch 'bugfix/workfile_builder_on_start' of https://github.com…
BigRoy Sep 6, 2024
0faaada
Fix case of explicit load import and improve docstring
BigRoy Sep 6, 2024
a27157f
Please @fabiaserra's eyes with better indentation
BigRoy Sep 9, 2024
3df68ef
`workfile_creation_enabled` docstring, first explain the `True` case.
BigRoy Sep 9, 2024
e7f7eab
Elaborate more
BigRoy Sep 9, 2024
522b205
Refactor logic with better function names
BigRoy Sep 9, 2024
d65b84c
Tweak comment to describe both the cases in the if statement
BigRoy Sep 9, 2024
cfcce21
Separate into variables for readability
BigRoy Sep 9, 2024
057a5ff
Simplify logic
BigRoy Sep 9, 2024
5fd4815
Merge branch 'develop' into bugfix/workfile_builder_on_start
MustafaJafar Sep 10, 2024
1450bca
Merge branch 'develop' into bugfix/workfile_builder_on_start
MustafaJafar Sep 12, 2024
ab498dd
Update client/ayon_core/pipeline/workfile/workfile_template_builder.py
BigRoy Sep 12, 2024
c6ffc0f
Merge branch 'develop' into bugfix/workfile_builder_on_start
MustafaJafar Sep 24, 2024
7298ddb
add note about using more accurate variable names
MustafaJafar Oct 2, 2024
8bd0c9c
Merge branch 'develop' into bugfix/workfile_builder_on_start
MustafaJafar Oct 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 43 additions & 46 deletions client/ayon_core/pipeline/workfile/workfile_template_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,55 +506,52 @@ 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
workfile_creation_enabled (bool): If True, it might create
first version but ignore
process if version is created
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 (bool): Whether we are creating a new
workfile. If False, we assume we just want to build the
template in our current scene.

"""
if any(
value is None
for value in [
template_path,
keep_placeholders,
create_first_version,
]

# Get default values if not provided
if (
template_path is None
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
or keep_placeholders is None
or create_first_version is None
):
template_preset = self.get_template_preset()
if template_path is None:
template_path = template_preset["path"]
preset = self.get_template_preset()
template_path: str = template_path or preset["path"]
if keep_placeholders is None:
keep_placeholders = template_preset["keep_placeholder"]
keep_placeholders: bool = preset["keep_placeholder"]
if create_first_version is None:
create_first_version = template_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()
create_first_version: bool = preset["create_first_version"]

# if first version is created, import template
# and populate placeholders
if (
create_first_version
and workfile_creation_enabled
and created_version_workfile
):
# Build the template if current workfile is a new unsaved file
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# (that's detected by checking if it returns any current filepath)
if not self.host.get_current_workfile():
MustafaJafar marked this conversation as resolved.
Show resolved Hide resolved
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 after template is populated
self.save_workfile(created_version_workfile)
if not workfile_creation_enabled:
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# Do not consider saving a first workfile version, if this
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
# is not set to be a "workfile creation". Then we assume
# only the template should get build.
return

# ignore process if first workfile is enabled
# but a version is already created
if workfile_creation_enabled:
if not create_first_version:
# Do not save whatsoever
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
return

self.import_template(template_path)
self.populate_scene_placeholders(
level_limit, keep_placeholders)
# If there is no existing workfile, save the first version
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
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.
Expand Down Expand Up @@ -608,7 +605,7 @@ def import_template(self, template_path):

pass

def create_first_workfile_version(self):
def get_first_workfile_version_to_create(self):
BigRoy marked this conversation as resolved.
Show resolved Hide resolved
"""
Create first version of workfile.

Expand All @@ -618,18 +615,19 @@ 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):
# ignore in case workfile existence
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

Expand Down Expand Up @@ -853,11 +851,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
BigRoy marked this conversation as resolved.
Show resolved Hide resolved

# Try fill path with environments and anatomy roots
anatomy = Anatomy(project_name)
Expand Down