Templated Builder: Options to allow profile to be disabled#1907
Templated Builder: Options to allow profile to be disabled#1907moonyuet wants to merge 40 commits into
Conversation
BigRoy
left a comment
There was a problem hiding this comment.
@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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This seems like an odd check for is_new_file? should this variable be is_app_launch_empty_file or whatever?
| 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"] |
There was a problem hiding this comment.
apply_to_empty_scene and apply_on_app_launch probably won't be available for old addons?
There was a problem hiding this comment.
| apply_to_empty_scene: bool = preset["apply_to_empty_scene"] | |
| apply_to_empty_scene: bool = preset.get("apply_to_empty_scene", False) |
|
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 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"] |
There was a problem hiding this comment.
| 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, |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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_sceneis duplicate ofworkfile_creation_enabled.apply_on_app_launchcannot be resolved in any way shape or form in workfile builder logic, it is used only for the import (again, duplicate ofworkfile_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.
There was a problem hiding this comment.
I have two questions with this:
- Isn't that we have discussed with @BigRoy about using dataclass for the return value? Or we dont need this now(Kinda offtrack though)
- Aren't
keep_placeholderandcreate_first_versionalready part of the profiles? So, I believeapply_to_empty_sceneandapply_on_app_launchshould be part of the profile settings?
There was a problem hiding this comment.
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).
…e knobs stated in the settings
…3_Template-builder-always-work-on-star
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>
…d break the host setting up AYON for some DCCs
…3_Template-builder-always-work-on-star
LiborBatek
left a comment
There was a problem hiding this comment.
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 |
| folder_entity, | ||
| task_entity, | ||
| self.host_name, | ||
| project_settings, |
There was a problem hiding this comment.
| 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) |
There was a problem hiding this comment.
| 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() |
| 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() | ||
|
|
There was a problem hiding this comment.
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.
| 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() |


Changelog Description
This PR is to add some more options to allow templated builder to be enabled in several scenarios:
Additional info
Resolve #1040
You can test with blender as starting point: ynput/ayon-blender#313
Testing notes: