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 18 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
114 changes: 52 additions & 62 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,59 @@ 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 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.

"""
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"]
if keep_placeholders is None:
keep_placeholders = template_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()

# if first version is created, import template
# and populate placeholders
# Get default values if not provided
if (
create_first_version
and workfile_creation_enabled
and created_version_workfile
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"]
if keep_placeholders is None:
keep_placeholders: bool = preset["keep_placeholder"]
if create_first_version is None:
create_first_version: bool = preset["create_first_version"]

# 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
MustafaJafar marked this conversation as resolved.
Show resolved Hide resolved
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(
level_limit, keep_placeholders)

# save workfile after template is populated
self.save_workfile(created_version_workfile)

# ignore process if first workfile is enabled
# but a version is already created
if workfile_creation_enabled:
# 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

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_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.
Expand Down Expand Up @@ -608,29 +612,16 @@ def import_template(self, template_path):

pass

def create_first_workfile_version(self):
"""
Create first version of workfile.
def get_workfile_path(self):
"""Return last known workfile path or the first workfile path create.

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.
Return:
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

# 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

def save_workfile(self, workfile_path):
Expand Down Expand Up @@ -853,11 +844,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 to fill path with environments and anatomy roots
anatomy = Anatomy(project_name)
Expand Down