From c40f97795938140a47c7936e11e82cf3836fa2ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Maurice=20Hern=C3=A9?= <maurice.herne@rwth-aachen.de>
Date: Mon, 28 Oct 2024 13:00:07 +0100
Subject: [PATCH] Adds new built-in action to clear cell outputs

---
 src/Notebook_Processor/desired_state/cell_modifier.py | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/src/Notebook_Processor/desired_state/cell_modifier.py b/src/Notebook_Processor/desired_state/cell_modifier.py
index 39f40c0..b543437 100644
--- a/src/Notebook_Processor/desired_state/cell_modifier.py
+++ b/src/Notebook_Processor/desired_state/cell_modifier.py
@@ -124,6 +124,14 @@ class CellModifier(BaseModel):
                 kwargs.setdefault("metadata", cell.metadata)
             return cell_class(**kwargs)
 
+        @staticmethod
+        def clear_outputs(cell: NotebookCellAnnotation, **kwargs) -> NotebookCellAnnotation:
+            """
+            Clear the output of the cell
+            """
+            cell.outputs = []
+            return cell
+
         # I don't want to remove this yet but I am unsure of the value of this function.
         # It is currently also broken due to isinstance not being able to handle complex annotations.
         # @staticmethod
@@ -188,6 +196,7 @@ class CellModifier(BaseModel):
 
         DELETE = delete
         CLEAR = clear
+        CLEAR_OUTPUTS = clear_outputs
         # REPLACE_FIELDS = replace_fields
         REPLACE_IN_SOURCE = replace_in_source
         UPDATE_METADATA = update_metadata
-- 
GitLab