Skip to content

Templated Builder: Options to allow profile to be disabled#1907

Draft
moonyuet wants to merge 40 commits into
developfrom
enhancement/AY-7243_Template-builder-always-work-on-star
Draft

Templated Builder: Options to allow profile to be disabled#1907
moonyuet wants to merge 40 commits into
developfrom
enhancement/AY-7243_Template-builder-always-work-on-star

Conversation

@moonyuet

Copy link
Copy Markdown
Member

Changelog Description

This PR is to add some more options to allow templated builder to be enabled in several scenarios:

  1. Official Enabled
  2. Template Always apply to empty scene (act as 'new file' template)
  3. Apply on application launch if no workfile exists yet

Additional info

Resolve #1040
You can test with blender as starting point: ynput/ayon-blender#313

Testing notes:

  1. Build workfile as followed in the host PR above

@moonyuet moonyuet requested review from BigRoy and LiborBatek June 24, 2026 09:35
@moonyuet moonyuet self-assigned this Jun 24, 2026
@moonyuet moonyuet added type: enhancement Improvement of existing functionality or minor addition sponsored This is directly sponsored by a client or community member labels Jun 24, 2026
@ynbot ynbot added the size/XS label Jun 24, 2026

@BigRoy BigRoy left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iLLiCiTiT shall we discuss this code? Because I think you had bigger remarks to begin with?

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.
apply_to_empty_scene (bool): Whether to apply the template

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this apply_on_new_file?

if is_new_file or explicit_build_requested:
is_new_file = (
not self.host.get_current_workfile()
and apply_on_app_launch

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like an odd check for is_new_file? should this variable be is_app_launch_empty_file or whatever?

Comment thread client/ayon_core/pipeline/workfile/workfile_template_builder.py Outdated
@ynbot ynbot moved this to Review In Progress in PR reviewing Jun 24, 2026
if create_first_version is None:
create_first_version: bool = preset["create_first_version"]
if apply_to_empty_scene is None:
apply_to_empty_scene: bool = preset["apply_to_empty_scene"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply_to_empty_scene and apply_on_app_launch probably won't be available for old addons?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apply_to_empty_scene: bool = preset["apply_to_empty_scene"]
apply_to_empty_scene: bool = preset.get("apply_to_empty_scene", False)

@iLLiCiTiT

Copy link
Copy Markdown
Member

Isn't this trying to resolve same thing as the other PR that did not raise an error if preset does not have file?

Right now we do expect that all values from get_template_preset are always returned and validated, at multiple places. As I said at the other PR, we have to refactor the logic to handle that correctly, we can't just return None at method that is expected to always return validated values without handling it at all.

When we'd do that I'd rather do it properly.

Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
if apply_to_empty_scene is None:
apply_to_empty_scene: bool = preset["apply_to_empty_scene"]
if apply_on_app_launch is None:
apply_on_app_launch: bool = preset["apply_on_app_launch"]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
apply_on_app_launch: bool = preset["apply_on_app_launch"]
apply_on_app_launch: bool = preset.get("apply_on_app_launch", False)

keep_placeholders=None,
create_first_version=None,
apply_to_empty_scene=None,
apply_on_app_launch=None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think apply_on_app_launch is something this method can't resolve. It probably is duplicate of workfile_creation_enabled.

"create_first_version": create_first_version
"create_first_version": create_first_version,
"apply_to_empty_scene": apply_to_empty_scene,
"apply_on_app_launch": apply_on_app_launch,

@iLLiCiTiT iLLiCiTiT Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Idea:
"apply_to_empty_scene" and "apply_on_app_launch" really don't make sense (from my point of view) to be resolved within the logic of workfile builder.

Rather store the profile to the output, and use correct arguments in build_template based on host logic:

  • apply_to_empty_scene is duplicate of workfile_creation_enabled.
  • apply_on_app_launch cannot be resolved in any way shape or form in workfile builder logic, it is used only for the import (again, duplicate of workfile_creation_enabled).
return {
    "path": resolved_path,
    "keep_placeholder": keep_placeholder,
    "create_first_version": create_first_version,
    "profile": profile,
}

Then you can do

# Somehow find out
just_lauched = ...

host = registered_host()
builder = TemplateBuilder(host)

preset = builder.get_template_preset()
profile = preset["profile"]
is_new_workfile = False
is_new_file = not self.host.get_current_workfile()
if just_lauched:
    is_new_workfile = profile["apply_to_empty_scene"]
elif is_new_file:
    is_new_workfile = profile["apply_on_app_launch"]
    
builder.build_template(
    template_path=preset["path"],
    keep_placeholder=preset["keep_placeholder"],
    create_first_version=preset["create_first_version"],
    workfile_creation_enabled=is_new_file,
)

I know this means the code has to be duplicated in each host that would want to do that, but this is the least affecting invasive code changes to avoid being even more blocked with future enhancements. Both values do affect the workfile template builder, but are not really related to the workfile builder. And yes we do have already the is_new_file logic, but why to add more to the pile.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have two questions with this:

  1. Isn't that we have discussed with @BigRoy about using dataclass for the return value? Or we dont need this now(Kinda offtrack though)
  2. Aren't keep_placeholder and create_first_version already part of the profiles? So, I believe apply_to_empty_scene and apply_on_app_launch should be part of the profile settings?
image

@iLLiCiTiT iLLiCiTiT Jun 24, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I believe apply_to_empty_scene and apply_on_app_launch should be part of the profile settings?

They can be part of the profile, but it doesn't make sense to have them as part of the workfile build preset. The workfile builder has nothing to do with the values. It is additional values that describe context before the workfile builder is being used.

The point is that the workfile template builder really needs more refactoring and adding more stuff that is at the end not used by the builder will only complicate future possible enhancements.

Apply to empty scene and on application launch cannot be handled by the workfile builder, it even should not be handled by the builder, you as someone who explicitly do trigger the builder know it, and you should pass that information to the build method, for both options and cases there already is argument that does handle that as far as I understand. If the same method is triggered manually from action the values from the preset should have no value, because at that moment it is not triggered on launch, or on empty workfile, and it should not apply the same logic (you can still trigger the builder manually).

@moonyuet moonyuet marked this pull request as draft June 24, 2026 14:03
@moonyuet moonyuet requested review from BigRoy and iLLiCiTiT June 26, 2026 06:44
Comment thread client/ayon_core/pipeline/workfile/workfile_template_builder.py Outdated
moonyuet and others added 11 commits July 6, 2026 16:34
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com>
@moonyuet moonyuet requested a review from iLLiCiTiT July 6, 2026 10:04

@LiborBatek LiborBatek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Create First Workfile still fails to save the workfile as the very first version but the rest of the options works fine...

@github-project-automation github-project-automation Bot moved this from Review In Progress to Change Requested in PR reviewing Jul 8, 2026
@moonyuet

moonyuet commented Jul 8, 2026

Copy link
Copy Markdown
Member Author

The Create First Workfile still fails to save the workfile as the very first version but the rest of the options works fine...

Fixed in bcb9413

@moonyuet moonyuet requested a review from LiborBatek July 8, 2026 09:39

@LiborBatek LiborBatek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The menu action works and saves the first workfile...

Image

but the addons default option for first workfile creation fails still

Image

@ynbot ynbot moved this from Change Requested to Review In Progress in PR reviewing Jul 8, 2026
folder_entity,
task_entity,
self.host_name,
project_settings,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
project_settings,
project_settings=project_settings,

if preset is None:
preset = self.get_template_preset()
self.build_template(preset=preset)
self.save_next_workfile_version(preset=preset)

@iLLiCiTiT iLLiCiTiT Jul 8, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
self.save_next_workfile_version(preset=preset)
if preset.create_first_version:
workfile_path = self.get_workfile_path()
if not os.path.exists(workfile_path):
self.log.info("Saving first workfile: %s", workfile_path)
save_next_version()

Comment on lines +1104 to +1121
def save_next_workfile_version(self, preset: TemplatePreset) -> None:
"""Save the next version of the workfile if the preset allows it.

Args:
preset (TemplatePreset): The template preset to use for
building the workfile template.
"""
if not preset.create_first_version:
return

workfile_path = self.get_workfile_path()
if os.path.exists(workfile_path):
self.log.info("Workfile path to save is not available.")
return

self.log.info("Saving first workfile: %s", workfile_path)
save_next_version()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed with https://github.com/ynput/ayon-core/pull/1907/changes#r3544181182 . The method does not do what the name says and there is save_next_version helper function in workfiles api already, so there is no point of having the method here.

Suggested change
def save_next_workfile_version(self, preset: TemplatePreset) -> None:
"""Save the next version of the workfile if the preset allows it.
Args:
preset (TemplatePreset): The template preset to use for
building the workfile template.
"""
if not preset.create_first_version:
return
workfile_path = self.get_workfile_path()
if os.path.exists(workfile_path):
self.log.info("Workfile path to save is not available.")
return
self.log.info("Saving first workfile: %s", workfile_path)
save_next_version()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XS sponsored This is directly sponsored by a client or community member type: enhancement Improvement of existing functionality or minor addition

Projects

Status: Review In Progress

Development

Successfully merging this pull request may close these issues.

AY-7243_Template builder always work on start

6 participants