From b7822123289e789776c91b19a0a69b4fa3757a5c Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:04:20 +0200 Subject: [PATCH 01/20] Extracted gap filling from last version --- client/ayon_core/lib/plugin_tools.py | 97 +++++++++++++++++++ .../plugins/publish/extract_review.py | 91 +---------------- 2 files changed, 99 insertions(+), 89 deletions(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 654bc7ac4a..1bc5824b86 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -4,6 +4,15 @@ import os import logging import re import collections +from typing import Optional, Any, Tuple +import clique +import speedcopy + +import ayon_api +import pyblish.api + +from ayon_api import get_last_version_by_product_name, get_representations + log = logging.getLogger(__name__) @@ -151,3 +160,91 @@ def source_hash(filepath, *args): time = str(os.path.getmtime(filepath)) size = str(os.path.getsize(filepath)) return "|".join([file_name, time, size] + list(args)).replace(".", ",") + + +def fill_sequence_gaps_with_previous( + collection: str, + staging_dir: str, + instance: pyblish.plugin.Instance, + current_repre_name: str, + start_frame: int, + end_frame: int +) -> Tuple[dict[str, Any], Optional[dict[int, str]]]: + """Tries to replace missing frames from ones from last version""" + used_version_entity, repre_file_paths = _get_last_version_files( + instance, current_repre_name + ) + if repre_file_paths is None: + # issues in getting last version files + return (None, None) + + prev_collection = clique.assemble( + repre_file_paths, + patterns=[clique.PATTERNS["frames"]], + minimum_items=1 + )[0][0] + prev_col_format = prev_collection.format("{head}{padding}{tail}") + + added_files = {} + anatomy = instance.context.data["anatomy"] + col_format = collection.format("{head}{padding}{tail}") + for frame in range(start_frame, end_frame + 1): + if frame in collection.indexes: + continue + hole_fpath = os.path.join(staging_dir, col_format % frame) + + previous_version_path = prev_col_format % frame + previous_version_path = anatomy.fill_root(previous_version_path) + if not os.path.exists(previous_version_path): + log.warning( + "Missing frame should be replaced from " + f"'{previous_version_path}' but that doesn't exist. " + "Falling back to filling from currently last rendered." + ) + return (None, None) + + log.warning( + f"Replacing missing '{hole_fpath}' with " + f"'{previous_version_path}'" + ) + speedcopy.copyfile(previous_version_path, hole_fpath) + added_files[frame] = hole_fpath + + return (used_version_entity, added_files) + + +def _get_last_version_files( + instance: pyblish.plugin.Instance, + current_repre_name: str, +): + product_name = instance.data["productName"] + project_name = instance.data["projectEntity"]["name"] + folder_entity = instance.data["folderEntity"] + + version_entity = get_last_version_by_product_name( + project_name, + product_name, + folder_entity["id"], + fields={"id"} + ) + + if not version_entity: + return (None, None) + + matching_repres = get_representations( + project_name, + version_ids=[version_entity["id"]], + representation_names=[current_repre_name], + fields={"files"} + ) + + if not matching_repres: + return None + matching_repre = list(matching_repres)[0] + + repre_file_paths = [ + file_info["path"] + for file_info in matching_repre["files"] + ] + + return (version_entity, repre_file_paths) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index 04e534054e..535f8ab6cf 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -13,14 +13,13 @@ import clique import speedcopy import pyblish.api -from ayon_api import get_last_version_by_product_name, get_representations - from ayon_core.lib import ( get_ffmpeg_tool_args, filter_profiles, path_to_subprocess_arg, run_subprocess, ) +from ayon_core.lib.plugin_tools import fill_sequence_gaps_with_previous from ayon_core.lib.transcoding import ( IMAGE_EXTENSIONS, get_ffprobe_streams, @@ -511,7 +510,7 @@ class ExtractReview(pyblish.api.InstancePlugin): temp_data=temp_data ) elif fill_missing_frames == "previous_version": - new_frame_files = self.fill_sequence_gaps_with_previous( + _, new_frame_files = fill_sequence_gaps_with_previous( collection=collection, staging_dir=new_repre["stagingDir"], instance=instance, @@ -1050,92 +1049,6 @@ class ExtractReview(pyblish.api.InstancePlugin): return all_args - def fill_sequence_gaps_with_previous( - self, - collection: str, - staging_dir: str, - instance: pyblish.plugin.Instance, - current_repre_name: str, - start_frame: int, - end_frame: int - ) -> Optional[dict[int, str]]: - """Tries to replace missing frames from ones from last version""" - repre_file_paths = self._get_last_version_files( - instance, current_repre_name) - if repre_file_paths is None: - # issues in getting last version files, falling back - return None - - prev_collection = clique.assemble( - repre_file_paths, - patterns=[clique.PATTERNS["frames"]], - minimum_items=1 - )[0][0] - prev_col_format = prev_collection.format("{head}{padding}{tail}") - - added_files = {} - anatomy = instance.context.data["anatomy"] - col_format = collection.format("{head}{padding}{tail}") - for frame in range(start_frame, end_frame + 1): - if frame in collection.indexes: - continue - hole_fpath = os.path.join(staging_dir, col_format % frame) - - previous_version_path = prev_col_format % frame - previous_version_path = anatomy.fill_root(previous_version_path) - if not os.path.exists(previous_version_path): - self.log.warning( - "Missing frame should be replaced from " - f"'{previous_version_path}' but that doesn't exist. " - "Falling back to filling from currently last rendered." - ) - return None - - self.log.warning( - f"Replacing missing '{hole_fpath}' with " - f"'{previous_version_path}'" - ) - speedcopy.copyfile(previous_version_path, hole_fpath) - added_files[frame] = hole_fpath - - return added_files - - def _get_last_version_files( - self, - instance: pyblish.plugin.Instance, - current_repre_name: str, - ): - product_name = instance.data["productName"] - project_name = instance.data["projectEntity"]["name"] - folder_entity = instance.data["folderEntity"] - - version_entity = get_last_version_by_product_name( - project_name, - product_name, - folder_entity["id"], - fields={"id"} - ) - if not version_entity: - return None - - matching_repres = get_representations( - project_name, - version_ids=[version_entity["id"]], - representation_names=[current_repre_name], - fields={"files"} - ) - - if not matching_repres: - return None - matching_repre = list(matching_repres)[0] - - repre_file_paths = [ - file_info["path"] - for file_info in matching_repre["files"] - ] - - return repre_file_paths - def fill_sequence_gaps_with_blanks( self, collection: str, From a7209e68f0b0142d138f18e88656470354f8ad0b Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:05:04 +0200 Subject: [PATCH 02/20] Push through reuseLastVersion value to deadline metadata --- client/ayon_core/pipeline/farm/pyblish_functions.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 0d8e70f9d2..4e9f9ed601 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -249,7 +249,8 @@ def create_skeleton_instance( # map inputVersions `ObjectId` -> `str` so json supports it "inputVersions": list(map(str, data.get("inputVersions", []))), "colorspace": data.get("colorspace"), - "hasExplicitFrames": data.get("hasExplicitFrames") + "hasExplicitFrames": data.get("hasExplicitFrames") or False, + "reuseLastVersion": data.get("reuseLastVersion") or False } if data.get("renderlayer"): From 3a0ba21117d53fc8120f29a6c5a90f7da3df6e9c Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:17:31 +0200 Subject: [PATCH 03/20] Return attrib for frameStart query --- client/ayon_core/lib/plugin_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 1bc5824b86..1ee8f673e0 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -225,7 +225,7 @@ def _get_last_version_files( project_name, product_name, folder_entity["id"], - fields={"id"} + fields={"id", "attrib"} ) if not version_entity: From 98d8417c737ba5faaecab2dd5adfb78c4300af35 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:36:44 +0200 Subject: [PATCH 04/20] Removed confusing message --- client/ayon_core/lib/plugin_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 1ee8f673e0..ec7668bdbf 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -199,7 +199,6 @@ def fill_sequence_gaps_with_previous( log.warning( "Missing frame should be replaced from " f"'{previous_version_path}' but that doesn't exist. " - "Falling back to filling from currently last rendered." ) return (None, None) From 29baac0d306969973226f7e20a20682a6e86b8b4 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:38:43 +0200 Subject: [PATCH 05/20] Moved message where it makes sense --- client/ayon_core/plugins/publish/extract_review.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index 535f8ab6cf..fac68a511a 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -520,6 +520,10 @@ class ExtractReview(pyblish.api.InstancePlugin): ) # fallback to original workflow if new_frame_files is None: + self.log.warning( + "Falling back to filling from currently " + "last rendered." + ) new_frame_files = ( self.fill_sequence_gaps_from_existing( collection=collection, From c046588ea8e6a1caf9d610ae6569bda3e3cd4e6d Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Fri, 10 Oct 2025 16:40:38 +0200 Subject: [PATCH 06/20] Ruff --- client/ayon_core/lib/plugin_tools.py | 1 - 1 file changed, 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index ec7668bdbf..117083a9c9 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -8,7 +8,6 @@ from typing import Optional, Any, Tuple import clique import speedcopy -import ayon_api import pyblish.api from ayon_api import get_last_version_by_product_name, get_representations From ef0af72632b74170f1bf7b381dac093b234f4f9b Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:33:12 +0200 Subject: [PATCH 07/20] Updated typin Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 117083a9c9..122d61c726 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -168,7 +168,7 @@ def fill_sequence_gaps_with_previous( current_repre_name: str, start_frame: int, end_frame: int -) -> Tuple[dict[str, Any], Optional[dict[int, str]]]: +) -> tuple[Optional[dict[str, Any]], Optional[dict[int, str]]]: """Tries to replace missing frames from ones from last version""" used_version_entity, repre_file_paths = _get_last_version_files( instance, current_repre_name From 951ea6286b1babfef3ab46e28fa88d8a574e1273 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:33:32 +0200 Subject: [PATCH 08/20] Removed unneeded import Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 122d61c726..3931e98777 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -4,7 +4,7 @@ import os import logging import re import collections -from typing import Optional, Any, Tuple +from typing import Optional, Any import clique import speedcopy From afe863e36b0d86b60676b226badc7e23e88cac73 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:34:07 +0200 Subject: [PATCH 09/20] Removed unnecessary parentheses Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 3931e98777..eff66fecfe 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -227,7 +227,7 @@ def _get_last_version_files( ) if not version_entity: - return (None, None) + return None, None matching_repres = get_representations( project_name, From 9a0f4b72e3e7fe2220202c4236fa848314bd89cb Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:34:53 +0200 Subject: [PATCH 10/20] Formatting change Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/farm/pyblish_functions.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/farm/pyblish_functions.py b/client/ayon_core/pipeline/farm/pyblish_functions.py index 4e9f9ed601..a5053844b9 100644 --- a/client/ayon_core/pipeline/farm/pyblish_functions.py +++ b/client/ayon_core/pipeline/farm/pyblish_functions.py @@ -249,8 +249,8 @@ def create_skeleton_instance( # map inputVersions `ObjectId` -> `str` so json supports it "inputVersions": list(map(str, data.get("inputVersions", []))), "colorspace": data.get("colorspace"), - "hasExplicitFrames": data.get("hasExplicitFrames") or False, - "reuseLastVersion": data.get("reuseLastVersion") or False + "hasExplicitFrames": data.get("hasExplicitFrames", False), + "reuseLastVersion": data.get("reuseLastVersion", False), } if data.get("renderlayer"): From c3de53ae5e85a367487dc7a9d0cda3ab699589e7 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:35:09 +0200 Subject: [PATCH 11/20] Removed import Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index eff66fecfe..3b39567207 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -8,8 +8,6 @@ from typing import Optional, Any import clique import speedcopy -import pyblish.api - from ayon_api import get_last_version_by_product_name, get_representations From 1f88b90cbabbcaaaa53392a9c1ad40a3e9ceddd0 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:35:28 +0200 Subject: [PATCH 12/20] Added return type Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 3b39567207..dc371a9ed1 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -212,7 +212,7 @@ def fill_sequence_gaps_with_previous( def _get_last_version_files( instance: pyblish.plugin.Instance, current_repre_name: str, -): +) -> tuple[Optional[dict[str, Any], Optional[list[str]]]: product_name = instance.data["productName"] project_name = instance.data["projectEntity"]["name"] folder_entity = instance.data["folderEntity"] From 1da4abc9bd87aefed1fadd2cb5a219c9c86a56fc Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:35:46 +0200 Subject: [PATCH 13/20] Fixed return Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/lib/plugin_tools.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index dc371a9ed1..676d3e43b5 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -234,9 +234,10 @@ def _get_last_version_files( fields={"files"} ) - if not matching_repres: - return None - matching_repre = list(matching_repres)[0] + matching_repre = next(matching_repres, None) + if not matching_repre: + return None, None + repre_file_paths = [ file_info["path"] From bd4381fe9b22ede0b70bbb4b0343c9e19caa3d73 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:45:24 +0200 Subject: [PATCH 14/20] Moved fill_sequence_gaps_with_previous --- client/ayon_core/lib/plugin_tools.py | 96 ------------------------ client/ayon_core/pipeline/publish/lib.py | 95 ++++++++++++++++++++++- 2 files changed, 94 insertions(+), 97 deletions(-) diff --git a/client/ayon_core/lib/plugin_tools.py b/client/ayon_core/lib/plugin_tools.py index 676d3e43b5..b19fe1e200 100644 --- a/client/ayon_core/lib/plugin_tools.py +++ b/client/ayon_core/lib/plugin_tools.py @@ -1,17 +1,9 @@ # -*- coding: utf-8 -*- """AYON plugin tools.""" import os -import logging import re import collections -from typing import Optional, Any -import clique -import speedcopy -from ayon_api import get_last_version_by_product_name, get_representations - - -log = logging.getLogger(__name__) CAPITALIZE_REGEX = re.compile(r"[a-zA-Z0-9]") @@ -157,91 +149,3 @@ def source_hash(filepath, *args): time = str(os.path.getmtime(filepath)) size = str(os.path.getsize(filepath)) return "|".join([file_name, time, size] + list(args)).replace(".", ",") - - -def fill_sequence_gaps_with_previous( - collection: str, - staging_dir: str, - instance: pyblish.plugin.Instance, - current_repre_name: str, - start_frame: int, - end_frame: int -) -> tuple[Optional[dict[str, Any]], Optional[dict[int, str]]]: - """Tries to replace missing frames from ones from last version""" - used_version_entity, repre_file_paths = _get_last_version_files( - instance, current_repre_name - ) - if repre_file_paths is None: - # issues in getting last version files - return (None, None) - - prev_collection = clique.assemble( - repre_file_paths, - patterns=[clique.PATTERNS["frames"]], - minimum_items=1 - )[0][0] - prev_col_format = prev_collection.format("{head}{padding}{tail}") - - added_files = {} - anatomy = instance.context.data["anatomy"] - col_format = collection.format("{head}{padding}{tail}") - for frame in range(start_frame, end_frame + 1): - if frame in collection.indexes: - continue - hole_fpath = os.path.join(staging_dir, col_format % frame) - - previous_version_path = prev_col_format % frame - previous_version_path = anatomy.fill_root(previous_version_path) - if not os.path.exists(previous_version_path): - log.warning( - "Missing frame should be replaced from " - f"'{previous_version_path}' but that doesn't exist. " - ) - return (None, None) - - log.warning( - f"Replacing missing '{hole_fpath}' with " - f"'{previous_version_path}'" - ) - speedcopy.copyfile(previous_version_path, hole_fpath) - added_files[frame] = hole_fpath - - return (used_version_entity, added_files) - - -def _get_last_version_files( - instance: pyblish.plugin.Instance, - current_repre_name: str, -) -> tuple[Optional[dict[str, Any], Optional[list[str]]]: - product_name = instance.data["productName"] - project_name = instance.data["projectEntity"]["name"] - folder_entity = instance.data["folderEntity"] - - version_entity = get_last_version_by_product_name( - project_name, - product_name, - folder_entity["id"], - fields={"id", "attrib"} - ) - - if not version_entity: - return None, None - - matching_repres = get_representations( - project_name, - version_ids=[version_entity["id"]], - representation_names=[current_repre_name], - fields={"files"} - ) - - matching_repre = next(matching_repres, None) - if not matching_repre: - return None, None - - - repre_file_paths = [ - file_info["path"] - for file_info in matching_repre["files"] - ] - - return (version_entity, repre_file_paths) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index 3b82d961f8..4d555ae48b 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -7,7 +7,10 @@ import copy import warnings import hashlib import xml.etree.ElementTree -from typing import TYPE_CHECKING, Optional, Union, List +from typing import TYPE_CHECKING, Optional, Union, List, Any +import clique +import speedcopy +import logging import ayon_api import pyblish.util @@ -27,6 +30,7 @@ from .constants import ( DEFAULT_PUBLISH_TEMPLATE, DEFAULT_HERO_PUBLISH_TEMPLATE, ) +from ayon_api import get_last_version_by_product_name, get_representations if TYPE_CHECKING: from ayon_core.pipeline.traits import Representation @@ -34,6 +38,8 @@ if TYPE_CHECKING: TRAIT_INSTANCE_KEY: str = "representations_with_traits" +log = logging.getLogger(__name__) + def get_template_name_profiles( project_name, project_settings=None, logger=None @@ -1143,3 +1149,90 @@ def get_trait_representations( """ return instance.data.get(TRAIT_INSTANCE_KEY, []) + + +def fill_sequence_gaps_with_previous( + collection: str, + staging_dir: str, + instance: pyblish.plugin.Instance, + current_repre_name: str, + start_frame: int, + end_frame: int +) -> tuple[Optional[dict[str, Any]], Optional[dict[int, str]]]: + """Tries to replace missing frames from ones from last version""" + used_version_entity, repre_file_paths = _get_last_version_files( + instance, current_repre_name + ) + if repre_file_paths is None: + # issues in getting last version files + return (None, None) + + prev_collection = clique.assemble( + repre_file_paths, + patterns=[clique.PATTERNS["frames"]], + minimum_items=1 + )[0][0] + prev_col_format = prev_collection.format("{head}{padding}{tail}") + + added_files = {} + anatomy = instance.context.data["anatomy"] + col_format = collection.format("{head}{padding}{tail}") + for frame in range(start_frame, end_frame + 1): + if frame in collection.indexes: + continue + hole_fpath = os.path.join(staging_dir, col_format % frame) + + previous_version_path = prev_col_format % frame + previous_version_path = anatomy.fill_root(previous_version_path) + if not os.path.exists(previous_version_path): + log.warning( + "Missing frame should be replaced from " + f"'{previous_version_path}' but that doesn't exist. " + ) + return (None, None) + + log.warning( + f"Replacing missing '{hole_fpath}' with " + f"'{previous_version_path}'" + ) + speedcopy.copyfile(previous_version_path, hole_fpath) + added_files[frame] = hole_fpath + + return (used_version_entity, added_files) + + +def _get_last_version_files( + instance: pyblish.plugin.Instance, + current_repre_name: str, +) -> tuple[Optional[dict[str, Any]], Optional[list[str]]]: + product_name = instance.data["productName"] + project_name = instance.data["projectEntity"]["name"] + folder_entity = instance.data["folderEntity"] + + version_entity = get_last_version_by_product_name( + project_name, + product_name, + folder_entity["id"], + fields={"id", "attrib"} + ) + + if not version_entity: + return None, None + + matching_repres = get_representations( + project_name, + version_ids=[version_entity["id"]], + representation_names=[current_repre_name], + fields={"files"} + ) + + matching_repre = next(matching_repres, None) + if not matching_repre: + return None, None + + repre_file_paths = [ + file_info["path"] + for file_info in matching_repre["files"] + ] + + return (version_entity, repre_file_paths) From 949cfc75a61b5a1c14eeec40d9153e56c7da4331 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 13:47:14 +0200 Subject: [PATCH 15/20] Renamed fill_sequence_gaps_with_previous --- client/ayon_core/pipeline/publish/lib.py | 2 +- client/ayon_core/plugins/publish/extract_review.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index 4d555ae48b..657a57226d 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -1151,7 +1151,7 @@ def get_trait_representations( return instance.data.get(TRAIT_INSTANCE_KEY, []) -def fill_sequence_gaps_with_previous( +def fill_sequence_gaps_with_previous_version( collection: str, staging_dir: str, instance: pyblish.plugin.Instance, diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index fac68a511a..fe0e7d4e3b 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -19,7 +19,7 @@ from ayon_core.lib import ( path_to_subprocess_arg, run_subprocess, ) -from ayon_core.lib.plugin_tools import fill_sequence_gaps_with_previous +from ayon_core.pipeline.publish.lib import fill_sequence_gaps_with_previous_version from ayon_core.lib.transcoding import ( IMAGE_EXTENSIONS, get_ffprobe_streams, @@ -510,7 +510,7 @@ class ExtractReview(pyblish.api.InstancePlugin): temp_data=temp_data ) elif fill_missing_frames == "previous_version": - _, new_frame_files = fill_sequence_gaps_with_previous( + _, new_frame_files = fill_sequence_gaps_with_previous_version( collection=collection, staging_dir=new_repre["stagingDir"], instance=instance, From f3300a67e42dac2698ca2a153f1e2cd220f88a85 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 13 Oct 2025 15:51:35 +0200 Subject: [PATCH 16/20] Formatting change Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/plugins/publish/extract_review.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index fe0e7d4e3b..89926d2235 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -19,7 +19,9 @@ from ayon_core.lib import ( path_to_subprocess_arg, run_subprocess, ) -from ayon_core.pipeline.publish.lib import fill_sequence_gaps_with_previous_version +from ayon_core.pipeline.publish.lib import ( + fill_sequence_gaps_with_previous_version, +) from ayon_core.lib.transcoding import ( IMAGE_EXTENSIONS, get_ffprobe_streams, From 0dc8bbe0a651f5c9a783163b7b43e2239f4005b3 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 14 Oct 2025 14:13:50 +0200 Subject: [PATCH 17/20] Reorder imports Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/pipeline/publish/lib.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index 657a57226d..96ab76f963 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -7,12 +7,13 @@ import copy import warnings import hashlib import xml.etree.ElementTree +import logging from typing import TYPE_CHECKING, Optional, Union, List, Any + import clique import speedcopy -import logging - import ayon_api +from ayon_api import get_last_version_by_product_name, get_representations import pyblish.util import pyblish.plugin import pyblish.api From 0d96e40d4075695c47905fbbf69268793388eaeb Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 14 Oct 2025 15:14:07 +0200 Subject: [PATCH 18/20] Ruff --- client/ayon_core/plugins/publish/extract_review.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index fe0e7d4e3b..8a46b93060 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -507,10 +507,10 @@ class ExtractReview(pyblish.api.InstancePlugin): resolution_width=temp_data.resolution_width, resolution_height=temp_data.resolution_height, extension=temp_data.input_ext, - temp_data=temp_data + temp_data=temp_data, ) elif fill_missing_frames == "previous_version": - _, new_frame_files = fill_sequence_gaps_with_previous_version( + fill_output = fill_sequence_gaps_with_previous_version( collection=collection, staging_dir=new_repre["stagingDir"], instance=instance, @@ -518,6 +518,7 @@ class ExtractReview(pyblish.api.InstancePlugin): start_frame=temp_data.frame_start, end_frame=temp_data.frame_end, ) + _, new_frame_files = fill_output # fallback to original workflow if new_frame_files is None: self.log.warning( From bb1fed3dbc59eb5f226656c8b934323fa7373c3c Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Tue, 14 Oct 2025 15:16:49 +0200 Subject: [PATCH 19/20] Ruff --- client/ayon_core/pipeline/publish/lib.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/client/ayon_core/pipeline/publish/lib.py b/client/ayon_core/pipeline/publish/lib.py index 657a57226d..7152ec78fa 100644 --- a/client/ayon_core/pipeline/publish/lib.py +++ b/client/ayon_core/pipeline/publish/lib.py @@ -12,11 +12,15 @@ import clique import speedcopy import logging -import ayon_api import pyblish.util import pyblish.plugin import pyblish.api +from ayon_api import ( + get_server_api_connection, + get_representations, + get_last_version_by_product_name +) from ayon_core.lib import ( import_filepath, Logger, @@ -30,7 +34,6 @@ from .constants import ( DEFAULT_PUBLISH_TEMPLATE, DEFAULT_HERO_PUBLISH_TEMPLATE, ) -from ayon_api import get_last_version_by_product_name, get_representations if TYPE_CHECKING: from ayon_core.pipeline.traits import Representation @@ -1036,7 +1039,7 @@ def main_cli_publish( # NOTE: ayon-python-api does not have public api function to find # out if is used service user. So we need to have try > except # block. - con = ayon_api.get_server_api_connection() + con = get_server_api_connection() try: con.set_default_service_username(username) except ValueError: From 99a9541f27cf6c26117cae17b6129be20d5397c5 Mon Sep 17 00:00:00 2001 From: Petr Kalis Date: Mon, 20 Oct 2025 14:55:03 +0200 Subject: [PATCH 20/20] Ruff --- client/ayon_core/plugins/publish/extract_review.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/plugins/publish/extract_review.py b/client/ayon_core/plugins/publish/extract_review.py index 8a46b93060..0111d02cb3 100644 --- a/client/ayon_core/plugins/publish/extract_review.py +++ b/client/ayon_core/plugins/publish/extract_review.py @@ -19,7 +19,9 @@ from ayon_core.lib import ( path_to_subprocess_arg, run_subprocess, ) -from ayon_core.pipeline.publish.lib import fill_sequence_gaps_with_previous_version +from ayon_core.pipeline.publish.lib import ( + fill_sequence_gaps_with_previous_version +) from ayon_core.lib.transcoding import ( IMAGE_EXTENSIONS, get_ffprobe_streams,