[Bf-blender-cvs] [d26220d97ab] master: Fix reports printing twice when called from Python in background-mode

Campbell Barton noreply at git.blender.org
Wed Sep 14 07:21:41 CEST 2022


Commit: d26220d97ab13f39b791468728a6089500d22caa
Author: Campbell Barton
Date:   Wed Sep 14 14:06:44 2022 +1000
Branches: master
https://developer.blender.org/rBd26220d97ab13f39b791468728a6089500d22caa

Fix reports printing twice when called from Python in background-mode

Calling operators in background-mode always printed with the
assumption that output should never be hidden.
However operators called from `bpy.ops` were also printing reports to
the `stdout` (needed for the Python console and generally useful).

Resolve by adding a flag to signal that the owner of the ReportList
is responsible for printing to the `stdout`.

===================================================================

M	source/blender/blenkernel/intern/report.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/python/intern/bpy_operator.c

===================================================================

diff --git a/source/blender/blenkernel/intern/report.c b/source/blender/blenkernel/intern/report.c
index 6d654730bca..ccec9c346a8 100644
--- a/source/blender/blenkernel/intern/report.c
+++ b/source/blender/blenkernel/intern/report.c
@@ -258,10 +258,20 @@ char *BKE_reports_string(ReportList *reports, eReportType level)
 
 bool BKE_reports_print_test(const ReportList *reports, eReportType type)
 {
+  if (reports == NULL) {
+    return true;
+  }
+  if (reports->flag & RPT_PRINT_HANDLED_BY_OWNER) {
+    return false;
+  }
   /* In background mode always print otherwise there are cases the errors won't be displayed,
-   * but still add to the report list since this is used for python exception handling. */
-  return (G.background || (reports == NULL) ||
-          ((reports->flag & RPT_PRINT) && (type >= reports->printlevel)));
+   * but still add to the report list since this is used for Python exception handling. */
+  if (G.background) {
+    return true;
+  }
+
+  /* Common case. */
+  return (reports->flag & RPT_PRINT) && (type >= reports->printlevel);
 }
 
 void BKE_reports_print(ReportList *reports, eReportType level)
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 47b7aee54d1..1c71129a3c7 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -70,6 +70,8 @@ enum ReportListFlags {
   RPT_STORE = (1 << 1),
   RPT_FREE = (1 << 2),
   RPT_OP_HOLD = (1 << 3), /* don't move them into the operator global list (caller will use) */
+  /** Don't print (the owner of the #ReportList will handle printing to the `stdout`). */
+  RPT_PRINT_HANDLED_BY_OWNER = (1 << 4),
 };
 
 /* These two Lines with # tell makesdna this struct can be excluded. */
diff --git a/source/blender/python/intern/bpy_operator.c b/source/blender/python/intern/bpy_operator.c
index 95879b02295..2db8c08cfd4 100644
--- a/source/blender/python/intern/bpy_operator.c
+++ b/source/blender/python/intern/bpy_operator.c
@@ -289,7 +289,7 @@ static PyObject *pyop_call(PyObject *UNUSED(self), PyObject *args)
       reports = MEM_mallocN(sizeof(ReportList), "wmOperatorReportList");
 
       /* Own so these don't move into global reports. */
-      BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD);
+      BKE_reports_init(reports, RPT_STORE | RPT_OP_HOLD | RPT_PRINT_HANDLED_BY_OWNER);
 
 #ifdef BPY_RELEASE_GIL
       /* release GIL, since a thread could be started from an operator



More information about the Bf-blender-cvs mailing list