From fecce683f1a47e7434a2921d60f17a2d5dea4bbc Mon Sep 17 00:00:00 2001 From: Roy Nieterau Date: Wed, 15 Jan 2025 10:55:55 +0100 Subject: [PATCH] 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 | 31 +++++++++++---------- 1 file changed, 17 insertions(+), 14 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 re import shutil +import tempfile + import pyblish.api -import re from ayon_core.lib import is_in_tests +from ayon_core.pipeline import PublishError class CleanUp(pyblish.api.InstancePlugin): @@ -48,17 +51,15 @@ def process(self, instance): 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 @@ def process(self, instance): 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)