Merge pull request #1141 from ynput/bugfix/1139-version_up_current_workfile-doesnt-return-the-first-workfile-name-if-there-are-no-workfiles

Host: Version up current workfile handles empty workdir
This commit is contained in:
Mustafa Jafar 2025-04-08 17:49:34 +02:00 committed by GitHub
commit a652c0da87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 22 additions and 3 deletions

View file

@ -27,7 +27,8 @@ from .workfile import (
get_workdir, get_workdir,
get_custom_workfile_template_by_string_context, get_custom_workfile_template_by_string_context,
get_workfile_template_key_from_context, get_workfile_template_key_from_context,
get_last_workfile get_last_workfile,
MissingWorkdirError,
) )
from . import ( from . import (
register_loader_plugin_path, register_loader_plugin_path,
@ -251,7 +252,7 @@ def uninstall_host():
pyblish.api.deregister_discovery_filter(filter_pyblish_plugins) pyblish.api.deregister_discovery_filter(filter_pyblish_plugins)
deregister_loader_plugin_path(LOAD_PATH) deregister_loader_plugin_path(LOAD_PATH)
deregister_inventory_action_path(INVENTORY_PATH) deregister_inventory_action_path(INVENTORY_PATH)
log.info("Global plug-ins unregistred") log.info("Global plug-ins unregistered")
deregister_host() deregister_host()
@ -617,7 +618,18 @@ def version_up_current_workfile():
last_workfile_path = get_last_workfile( last_workfile_path = get_last_workfile(
work_root, file_template, data, extensions, True work_root, file_template, data, extensions, True
) )
new_workfile_path = version_up(last_workfile_path) # `get_last_workfile` will return the first expected file version
# if no files exist yet. In that case, if they do not exist we will
# want to save v001
new_workfile_path = last_workfile_path
if os.path.exists(new_workfile_path): if os.path.exists(new_workfile_path):
new_workfile_path = version_up(new_workfile_path) new_workfile_path = version_up(new_workfile_path)
# Raise an error if the parent folder doesn't exist as `host.save_workfile`
# is not supposed/able to create missing folders.
parent_folder = os.path.dirname(new_workfile_path)
if not os.path.exists(parent_folder):
raise MissingWorkdirError(
f"Work area directory '{parent_folder}' does not exist.")
host.save_workfile(new_workfile_path) host.save_workfile(new_workfile_path)

View file

@ -16,6 +16,7 @@ from .path_resolving import (
from .utils import ( from .utils import (
should_use_last_workfile_on_launch, should_use_last_workfile_on_launch,
should_open_workfiles_tool_on_launch, should_open_workfiles_tool_on_launch,
MissingWorkdirError,
) )
from .build_workfile import BuildWorkfile from .build_workfile import BuildWorkfile
@ -46,6 +47,7 @@ __all__ = (
"should_use_last_workfile_on_launch", "should_use_last_workfile_on_launch",
"should_open_workfiles_tool_on_launch", "should_open_workfiles_tool_on_launch",
"MissingWorkdirError",
"BuildWorkfile", "BuildWorkfile",

View file

@ -2,6 +2,11 @@ from ayon_core.lib import filter_profiles
from ayon_core.settings import get_project_settings from ayon_core.settings import get_project_settings
class MissingWorkdirError(Exception):
"""Raised when accessing a work directory not found on disk."""
pass
def should_use_last_workfile_on_launch( def should_use_last_workfile_on_launch(
project_name, project_name,
host_name, host_name,