From fecce683f1a47e7434a2921d60f17a2d5dea4bbc Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 15 Jan 2025 10:55:55 +0100 Subject: [PATCH 1/4] Some code cleanup for `CleanUp` plugin - Use `PublishError` instead of assertion - Optimize the 'check for errors' - Optimize the product type check + log debug message when skipped due to that - Move imports to top --- client/ayon_core/plugins/publish/cleanup.py | 33 +++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/client/ayon_core/plugins/publish/cleanup.py b/client/ayon_core/plugins/publish/cleanup.py index 57ef803352..109dc55c1d 100644 --- a/client/ayon_core/plugins/publish/cleanup.py +++ b/client/ayon_core/plugins/publish/cleanup.py @@ -1,11 +1,14 @@ # -*- coding: utf-8 -*- """Cleanup leftover files from publish.""" import os -import shutil -import pyblish.api import re +import shutil +import tempfile + +import pyblish.api from ayon_core.lib import is_in_tests +from ayon_core.pipeline import PublishError class CleanUp(pyblish.api.InstancePlugin): @@ -48,17 +51,15 @@ class CleanUp(pyblish.api.InstancePlugin): if is_in_tests(): # let automatic test process clean up temporary data return - # Get the errored instances - failed = [] + + # If instance has errors, do not clean up for result in instance.context.data["results"]: - if (result["error"] is not None and result["instance"] is not None - and result["instance"] not in failed): - failed.append(result["instance"]) - assert instance not in failed, ( - "Result of '{}' instance were not success".format( - instance.data["name"] - ) - ) + if result["error"] is not None and result["instance"] is instance: + raise PublishError( + "Result of '{}' instance were not success".format( + instance.data["name"] + ) + ) _skip_cleanup_filepaths = instance.context.data.get( "skipCleanupFilepaths" @@ -71,10 +72,12 @@ class CleanUp(pyblish.api.InstancePlugin): self.log.debug("Cleaning renders new...") self.clean_renders(instance, skip_cleanup_filepaths) - if [ef for ef in self.exclude_families - if instance.data["productType"] in ef]: + product_type = instance.data["productType"] + if product_type in self.exclude_families: + self.log.debug( + "Skipping cleanup for instance because product " + f"type is excluded from cleanup: {product_type}") return - import tempfile temp_root = tempfile.gettempdir() staging_dir = instance.data.get("stagingDir", None) From 1b3a08af0189d649ab7eb413bf8b526784405401 Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 27 May 2025 10:07:55 +0200 Subject: [PATCH 2/4] Revert exclude family check to maintain old behavior --- client/ayon_core/plugins/publish/cleanup.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/client/ayon_core/plugins/publish/cleanup.py b/client/ayon_core/plugins/publish/cleanup.py index 109dc55c1d..53f1dea071 100644 --- a/client/ayon_core/plugins/publish/cleanup.py +++ b/client/ayon_core/plugins/publish/cleanup.py @@ -72,8 +72,13 @@ class CleanUp(pyblish.api.InstancePlugin): self.log.debug("Cleaning renders new...") self.clean_renders(instance, skip_cleanup_filepaths) + # TODO: Figure out whether this could be refactored to just a + # product_type in self.exclude_families check. product_type = instance.data["productType"] - if product_type in self.exclude_families: + if any( + exclude_family in product_type + for exclude_family in self.exclude_families + ): self.log.debug( "Skipping cleanup for instance because product " f"type is excluded from cleanup: {product_type}") From d5b9e814a732236b0b9dd153772e29195036abad Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 27 May 2025 10:08:43 +0200 Subject: [PATCH 3/4] Fix indent --- client/ayon_core/plugins/publish/cleanup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/ayon_core/plugins/publish/cleanup.py b/client/ayon_core/plugins/publish/cleanup.py index 53f1dea071..4daeacf754 100644 --- a/client/ayon_core/plugins/publish/cleanup.py +++ b/client/ayon_core/plugins/publish/cleanup.py @@ -76,8 +76,8 @@ class CleanUp(pyblish.api.InstancePlugin): # product_type in self.exclude_families check. product_type = instance.data["productType"] if any( - exclude_family in product_type - for exclude_family in self.exclude_families + exclude_family in product_type + for exclude_family in self.exclude_families ): self.log.debug( "Skipping cleanup for instance because product " From bf9c5b61a5c83d23f43dc05be861bc9fb6829fab Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Tue, 27 May 2025 10:13:43 +0200 Subject: [PATCH 4/4] Update client/ayon_core/plugins/publish/cleanup.py Co-authored-by: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> --- client/ayon_core/plugins/publish/cleanup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/ayon_core/plugins/publish/cleanup.py b/client/ayon_core/plugins/publish/cleanup.py index 4daeacf754..681fe700a3 100644 --- a/client/ayon_core/plugins/publish/cleanup.py +++ b/client/ayon_core/plugins/publish/cleanup.py @@ -76,7 +76,7 @@ class CleanUp(pyblish.api.InstancePlugin): # product_type in self.exclude_families check. product_type = instance.data["productType"] if any( - exclude_family in product_type + product_type in exclude_family for exclude_family in self.exclude_families ): self.log.debug(