From 1de8e300c78850a59d028104139c8bd93e834a96 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Tue, 11 Feb 2025 20:07:16 +0200 Subject: [PATCH 01/12] fix a typo --- client/ayon_core/pipeline/context_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index b9ae906ab4..386c7ba737 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -251,7 +251,7 @@ def uninstall_host(): pyblish.api.deregister_discovery_filter(filter_pyblish_plugins) deregister_loader_plugin_path(LOAD_PATH) deregister_inventory_action_path(INVENTORY_PATH) - log.info("Global plug-ins unregistred") + log.info("Global plug-ins unregistered") deregister_host() From bba0df9c0eac4e92b2eb2852736bfd183603657c Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Tue, 11 Feb 2025 20:07:37 +0200 Subject: [PATCH 02/12] don't `version_up` twice --- client/ayon_core/pipeline/context_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index 386c7ba737..a809261fa2 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -617,7 +617,7 @@ def version_up_current_workfile(): last_workfile_path = get_last_workfile( work_root, file_template, data, extensions, True ) - new_workfile_path = version_up(last_workfile_path) + new_workfile_path = last_workfile_path if os.path.exists(new_workfile_path): new_workfile_path = version_up(new_workfile_path) host.save_workfile(new_workfile_path) From 99f60e10125489c4863f1d905fef9c1c6644c10e Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Tue, 11 Feb 2025 20:28:03 +0200 Subject: [PATCH 03/12] replace `os.listdir` by `os.scandir` --- client/ayon_core/lib/path_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index 31baac168c..3826f1383e 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -136,8 +136,8 @@ def version_up(filepath): index += len(new_label) clash_basename = clash_basename[:index] - for file in os.listdir(dirname): - if file.endswith(ext) and file.startswith(clash_basename): + for file in os.scandir(dirname): + if file.name.endswith(ext) and file.name.startswith(clash_basename): log.info("Skipping existing version %s" % new_label) return version_up(new_filename) From 9791f591f579e3f7106f1616293f0e034f66cd8a Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Tue, 11 Feb 2025 20:30:26 +0200 Subject: [PATCH 04/12] use `f` instead of `file` --- client/ayon_core/lib/path_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index 3826f1383e..f3c35d998b 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -136,8 +136,8 @@ def version_up(filepath): index += len(new_label) clash_basename = clash_basename[:index] - for file in os.scandir(dirname): - if file.name.endswith(ext) and file.name.startswith(clash_basename): + for f in os.scandir(dirname): + if f.name.endswith(ext) and f.name.startswith(clash_basename): log.info("Skipping existing version %s" % new_label) return version_up(new_filename) From cee3219304697cc3852e167650b7c40e87912a95 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Sat, 15 Feb 2025 00:49:22 +0200 Subject: [PATCH 05/12] revert using `os.scandir` inside `version_up` --- client/ayon_core/lib/path_tools.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/lib/path_tools.py b/client/ayon_core/lib/path_tools.py index f3c35d998b..31baac168c 100644 --- a/client/ayon_core/lib/path_tools.py +++ b/client/ayon_core/lib/path_tools.py @@ -136,8 +136,8 @@ def version_up(filepath): index += len(new_label) clash_basename = clash_basename[:index] - for f in os.scandir(dirname): - if f.name.endswith(ext) and f.name.startswith(clash_basename): + for file in os.listdir(dirname): + if file.endswith(ext) and file.startswith(clash_basename): log.info("Skipping existing version %s" % new_label) return version_up(new_filename) From 65d7404d428229e8573169040cb5fec4b5f4e522 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Sat, 15 Feb 2025 01:03:34 +0200 Subject: [PATCH 06/12] add a note about `get_last_workfile` --- client/ayon_core/pipeline/context_tools.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index a809261fa2..beb62755f5 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -617,6 +617,9 @@ def version_up_current_workfile(): last_workfile_path = get_last_workfile( work_root, file_template, data, extensions, True ) + # `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): new_workfile_path = version_up(new_workfile_path) From 817e4dc3380ba66e93465cf28262f8f96eb07a1f Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Sat, 15 Feb 2025 01:08:52 +0200 Subject: [PATCH 07/12] `version_up_current_workfile`: Raise error if parent folder of the workfile doesn't exist. --- client/ayon_core/pipeline/context_tools.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index beb62755f5..a2732d2c55 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -623,4 +623,12 @@ def version_up_current_workfile(): new_workfile_path = last_workfile_path if os.path.exists(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 AssertionError( + f"Folder {parent_folder} does not exist yet.") + host.save_workfile(new_workfile_path) From 26acd0efad991f8296c142f682dc3f11b450d6be Mon Sep 17 00:00:00 2001 From: Mustafa Jafar Date: Thu, 27 Feb 2025 15:24:16 +0200 Subject: [PATCH 08/12] update log message Co-authored-by: Roy Nieterau --- client/ayon_core/pipeline/context_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index a2732d2c55..3951a4d6e9 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -629,6 +629,6 @@ def version_up_current_workfile(): parent_folder = os.path.dirname(new_workfile_path) if not os.path.exists(parent_folder): raise AssertionError( - f"Folder {parent_folder} does not exist yet.") + f"Work area directory '{parent_folder}' does not exist yet.") host.save_workfile(new_workfile_path) From 1f571e65c168eb0f481ce7704638082b46fafaa1 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 7 Mar 2025 14:17:13 +0200 Subject: [PATCH 09/12] implement `MissingWorkdirError` --- client/ayon_core/pipeline/context_tools.py | 5 +++-- client/ayon_core/pipeline/workfile/__init__.py | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index 3951a4d6e9..2f002ae2c8 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -27,7 +27,8 @@ from .workfile import ( get_workdir, get_custom_workfile_template_by_string_context, get_workfile_template_key_from_context, - get_last_workfile + get_last_workfile, + MissingWorkdirError, ) from . import ( register_loader_plugin_path, @@ -628,7 +629,7 @@ def version_up_current_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 AssertionError( + raise MissingWorkdirError( f"Work area directory '{parent_folder}' does not exist yet.") host.save_workfile(new_workfile_path) diff --git a/client/ayon_core/pipeline/workfile/__init__.py b/client/ayon_core/pipeline/workfile/__init__.py index 05f939024c..aa7e150bca 100644 --- a/client/ayon_core/pipeline/workfile/__init__.py +++ b/client/ayon_core/pipeline/workfile/__init__.py @@ -16,6 +16,7 @@ from .path_resolving import ( from .utils import ( should_use_last_workfile_on_launch, should_open_workfiles_tool_on_launch, + MissingWorkdirError, ) from .build_workfile import BuildWorkfile @@ -46,6 +47,7 @@ __all__ = ( "should_use_last_workfile_on_launch", "should_open_workfiles_tool_on_launch", + "MissingWorkdirError", "BuildWorkfile", From 8f45e20c2ac5d7d3a1ed58f3bda62faf9023d499 Mon Sep 17 00:00:00 2001 From: MustafaJafar Date: Fri, 7 Mar 2025 14:17:37 +0200 Subject: [PATCH 10/12] use `MissingWorkdirError` --- client/ayon_core/pipeline/workfile/utils.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/ayon_core/pipeline/workfile/utils.py b/client/ayon_core/pipeline/workfile/utils.py index 53de3269b2..1a5ecdff4a 100644 --- a/client/ayon_core/pipeline/workfile/utils.py +++ b/client/ayon_core/pipeline/workfile/utils.py @@ -2,6 +2,10 @@ from ayon_core.lib import filter_profiles from ayon_core.settings import get_project_settings +class MissingWorkdirError(Exception): + pass + + def should_use_last_workfile_on_launch( project_name, host_name, From bfb24435ab24beaa66e810113088c3c833b1c2bf Mon Sep 17 00:00:00 2001 From: Mustafa Jafar Date: Sun, 9 Mar 2025 01:19:30 +0200 Subject: [PATCH 11/12] Update log message Co-authored-by: Roy Nieterau --- client/ayon_core/pipeline/context_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/context_tools.py b/client/ayon_core/pipeline/context_tools.py index 2f002ae2c8..66556bbb35 100644 --- a/client/ayon_core/pipeline/context_tools.py +++ b/client/ayon_core/pipeline/context_tools.py @@ -630,6 +630,6 @@ def version_up_current_workfile(): 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 yet.") + f"Work area directory '{parent_folder}' does not exist.") host.save_workfile(new_workfile_path) From c05c5045246aedfa20d662bee9e87a0ea814291d Mon Sep 17 00:00:00 2001 From: Mustafa Jafar Date: Sun, 9 Mar 2025 01:20:41 +0200 Subject: [PATCH 12/12] add doc string to `MissingWorkdirError` Co-authored-by: Roy Nieterau --- client/ayon_core/pipeline/workfile/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/client/ayon_core/pipeline/workfile/utils.py b/client/ayon_core/pipeline/workfile/utils.py index 1a5ecdff4a..25be061dec 100644 --- a/client/ayon_core/pipeline/workfile/utils.py +++ b/client/ayon_core/pipeline/workfile/utils.py @@ -3,6 +3,7 @@ from ayon_core.settings import get_project_settings class MissingWorkdirError(Exception): + """Raised when accessing a work directory not found on disk.""" pass