Commit: 7341ceb674b2fc5c01d4328f398516ef8f358ae5
Author: Campbell Barton
Date:   Mon Aug 17 17:46:06 2020 +1000
Branches: master
https://developer.blender.org/rB7341ceb674b2fc5c01d4328f398516ef8f358ae5

Cleanup: move Python script execution into BPY_extern_run.h

This commit renames 'execute' to 'run' because:

- This follows Python's "PyRun" which these functions wrap.
- Execution functions can use either exec/eval modes,
  making naming awkward (for future API refactoring).

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

M       source/blender/editors/interface/interface.c
M       source/blender/editors/interface/interface_context_menu.c
M       source/blender/editors/interface/interface_region_tooltip.c
M       source/blender/editors/space_script/script_edit.c
M       source/blender/editors/space_text/text_ops.c
M       source/blender/editors/util/numinput.c
M       source/blender/freestyle/intern/system/PythonInterpreter.h
M       source/blender/python/BPY_extern.h
A       source/blender/python/BPY_extern_run.h
M       source/blender/python/intern/CMakeLists.txt
M       source/blender/python/intern/bpy_interface.c
A       source/blender/python/intern/bpy_interface_run.c
M       source/blender/windowmanager/intern/wm.c
M       source/blender/windowmanager/intern/wm_files.c
M       source/creator/creator_args.c

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

diff --git a/source/blender/editors/interface/interface.c 
b/source/blender/editors/interface/interface.c
index 2ee1ecccd56..41e7db3a38c 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -69,7 +69,9 @@
 
 #include "RNA_access.h"
 
-#include "BPY_extern.h"
+#ifdef WITH_PYTHON
+#  include "BPY_extern_run.h"
+#endif
 
 #include "ED_numinput.h"
 #include "ED_screen.h"
@@ -2812,7 +2814,7 @@ char *ui_but_string_get_dynamic(uiBut *but, int 
*r_str_size)
 }
 
 /**
- * Report a generic error prefix when evaluating a string with 
#BPY_execute_string_as_number
+ * Report a generic error prefix when evaluating a string with 
#BPY_run_string_as_number
  * as the Python error on it's own doesn't provide enough context.
  */
 #define UI_NUMBER_EVAL_ERROR_PREFIX IFACE_("Error evaluating number, see Info 
editor for details")
@@ -2837,7 +2839,7 @@ static bool ui_number_from_string(bContext *C, const char 
*str, double *r_value)
 {
   bool ok;
 #ifdef WITH_PYTHON
-  ok = BPY_execute_string_as_number(C, NULL, str, UI_NUMBER_EVAL_ERROR_PREFIX, 
r_value);
+  ok = BPY_run_string_as_number(C, NULL, str, UI_NUMBER_EVAL_ERROR_PREFIX, 
r_value);
 #else
   UNUSED_VARS(C);
   *r_value = atof(str);
diff --git a/source/blender/editors/interface/interface_context_menu.c 
b/source/blender/editors/interface/interface_context_menu.c
index 46876fca9a5..59178e209db 100644
--- a/source/blender/editors/interface/interface_context_menu.c
+++ b/source/blender/editors/interface/interface_context_menu.c
@@ -47,7 +47,10 @@
 
 #include "RNA_access.h"
 
-#include "BPY_extern.h"
+#ifdef WITH_PYTHON
+#  include "BPY_extern.h"
+#  include "BPY_extern_run.h"
+#endif
 
 #include "WM_api.h"
 #include "WM_types.h"
@@ -407,7 +410,7 @@ static void ui_but_user_menu_add(bContext *C, uiBut *but, 
bUserMenu *um)
                    "'%s').label",
                    idname);
           char *expr_result = NULL;
-          if (BPY_execute_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
+          if (BPY_run_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
             STRNCPY(drawstr, expr_result);
             MEM_freeN(expr_result);
           }
diff --git a/source/blender/editors/interface/interface_region_tooltip.c 
b/source/blender/editors/interface/interface_region_tooltip.c
index 41b41cb3d75..c324e27dff9 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -63,7 +63,7 @@
 #include "BLT_translation.h"
 
 #ifdef WITH_PYTHON
-#  include "BPY_extern.h"
+#  include "BPY_extern_run.h"
 #endif
 
 #include "ED_screen.h"
@@ -433,7 +433,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext 
*C, uiBut *but, bool is
     if (has_valid_context == false) {
       expr_result = BLI_strdup(has_valid_context_error);
     }
-    else if (BPY_execute_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
+    else if (BPY_run_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
       if (STREQ(expr_result, "")) {
         MEM_freeN(expr_result);
         expr_result = NULL;
@@ -490,7 +490,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext 
*C, uiBut *but, bool is
     if (has_valid_context == false) {
       expr_result = BLI_strdup(has_valid_context_error);
     }
-    else if (BPY_execute_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
+    else if (BPY_run_string_as_string(C, expr_imports, expr, __func__, 
&expr_result)) {
       if (STREQ(expr_result, ".")) {
         MEM_freeN(expr_result);
         expr_result = NULL;
@@ -594,7 +594,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext 
*C, uiBut *but, bool is
         if (has_valid_context == false) {
           shortcut = BLI_strdup(has_valid_context_error);
         }
-        else if (BPY_execute_string_as_intptr(C, expr_imports, expr, __func__, 
&expr_result)) {
+        else if (BPY_run_string_as_intptr(C, expr_imports, expr, __func__, 
&expr_result)) {
           if (expr_result != 0) {
             wmKeyMap *keymap = (wmKeyMap *)expr_result;
             LISTBASE_FOREACH (wmKeyMapItem *, kmi, &keymap->items) {
@@ -658,7 +658,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext 
*C, uiBut *but, bool is
       if (has_valid_context == false) {
         /* pass */
       }
-      else if (BPY_execute_string_as_string_and_size(
+      else if (BPY_run_string_as_string_and_size(
                    C, expr_imports, expr, __func__, &expr_result, 
&expr_result_len)) {
         /* pass. */
       }
@@ -736,7 +736,7 @@ static uiTooltipData *ui_tooltip_data_from_tool(bContext 
*C, uiBut *but, bool is
     if (has_valid_context == false) {
       /* pass */
     }
-    else if (BPY_execute_string_as_intptr(C, expr_imports, expr, __func__, 
&expr_result)) {
+    else if (BPY_run_string_as_intptr(C, expr_imports, expr, __func__, 
&expr_result)) {
       if (expr_result != 0) {
         {
           uiTooltipField *field = text_field_add(data,
diff --git a/source/blender/editors/space_script/script_edit.c 
b/source/blender/editors/space_script/script_edit.c
index e9ed1cec228..f9d7e8371b2 100644
--- a/source/blender/editors/space_script/script_edit.c
+++ b/source/blender/editors/space_script/script_edit.c
@@ -42,7 +42,7 @@
 #include "script_intern.h"  // own include
 
 #ifdef WITH_PYTHON
-#  include "BPY_extern.h" /* BPY_script_exec */
+#  include "BPY_extern_run.h"
 #endif
 
 static int run_pyfile_exec(bContext *C, wmOperator *op)
@@ -50,7 +50,7 @@ static int run_pyfile_exec(bContext *C, wmOperator *op)
   char path[512];
   RNA_string_get(op->ptr, "filepath", path);
 #ifdef WITH_PYTHON
-  if (BPY_execute_filepath(C, path, op->reports)) {
+  if (BPY_run_filepath(C, path, op->reports)) {
     ARegion *region = CTX_wm_region(C);
     ED_region_tag_redraw(region);
     return OPERATOR_FINISHED;
@@ -120,8 +120,7 @@ static int script_reload_exec(bContext *C, wmOperator *op)
   /* TODO, this crashes on netrender and keying sets, need to look into why
    * disable for now unless running in debug mode */
   WM_cursor_wait(1);
-  BPY_execute_string(
-      C, (const char *[]){"bpy", NULL}, 
"bpy.utils.load_scripts(reload_scripts=True)");
+  BPY_run_string(C, (const char *[]){"bpy", NULL}, 
"bpy.utils.load_scripts(reload_scripts=True)");
   WM_cursor_wait(0);
   WM_event_add_notifier(C, NC_WINDOW, NULL);
   return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_text/text_ops.c 
b/source/blender/editors/space_text/text_ops.c
index 201f9dae5d5..688dce3c54e 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -55,6 +55,7 @@
 
 #ifdef WITH_PYTHON
 #  include "BPY_extern.h"
+#  include "BPY_extern_run.h"
 #endif
 
 #include "text_format.h"
@@ -756,7 +757,7 @@ static int text_run_script(bContext *C, ReportList *reports)
   void *curl_prev = text->curl;
   int curc_prev = text->curc;
 
-  if (BPY_execute_text(C, text, reports, !is_live)) {
+  if (BPY_run_text(C, text, reports, !is_live)) {
     if (is_live) {
       /* for nice live updates */
       WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
diff --git a/source/blender/editors/util/numinput.c 
b/source/blender/editors/util/numinput.c
index 384da6fb931..041b2fec00b 100644
--- a/source/blender/editors/util/numinput.c
+++ b/source/blender/editors/util/numinput.c
@@ -38,7 +38,7 @@
 #include "WM_types.h"
 
 #ifdef WITH_PYTHON
-#  include "BPY_extern.h"
+#  include "BPY_extern_run.h"
 #endif
 
 #include "ED_numinput.h"
@@ -294,10 +294,10 @@ bool user_string_to_number(bContext *C,
     bUnit_ReplaceString(
         str_unit_convert, sizeof(str_unit_convert), str, unit_scale, 
unit->system, type);
 
-    return BPY_execute_string_as_number(C, NULL, str_unit_convert, 
error_prefix, r_value);
+    return BPY_run_string_as_number(C, NULL, str_unit_convert, error_prefix, 
r_value);
   }
 
-  int success = BPY_execute_string_as_number(C, NULL, str, error_prefix, 
r_value);
+  int success = BPY_run_string_as_number(C, NULL, str, error_prefix, r_value);
   *r_value *= bUnit_PreferredInputUnitScalar(unit, type);
   *r_value /= unit_scale;
   return success;
diff --git a/source/blender/freestyle/intern/system/PythonInterpreter.h 
b/source/blender/freestyle/intern/system/PythonInterpreter.h
index bae69aa0a42..e2022c1de85 100644
--- a/source/blender/freestyle/intern/system/PythonInterpreter.h
+++ b/source/blender/freestyle/intern/system/PythonInterpreter.h
@@ -42,7 +42,7 @@ extern "C" {
 #include "BKE_report.h"
 #include "BKE_text.h"
 
-#include "BPY_extern.h"
+#include "BPY_extern_run.h"
 
 #include "bpy_capi_utils.h"
 
@@ -68,12 +68,12 @@ class PythonInterpreter : public Interpreter {
     BKE_reports_clear(reports);
     char *fn = const_cast<char *>(filename.c_str());
 #if 0
-    bool ok = BPY_execute_filepath(_context, fn, reports);
+    bool ok = BPY_run_filepath(_context, fn, reports);
 #else
     bool ok;
     Text *text = BKE_text_load(&_freestyle_bmain, fn, G_MAIN->name);
     if (text) {
-      ok = BPY_execute_text(_context, text, reports, false);
+      ok = BPY_run_text(_context, text, reports, false);
       BKE_id_delete(&_freestyle_bmain, text);
     }
     else {
@@ -102,7 +102,7 @@ class PythonInterpreter : public Interpreter {
 
     BKE_reports_clear(reports);
 
-    if (!BPY_execute_string(_context, NULL, str.c_str())) {
+    if (!BPY_run_string(_context, NULL, str.c_str())) {
       BPy_errors_to_report(reports);
       cerr << "\nError executing Python script from 
PythonInterpreter::interpretString" << endl;
       cerr << "Name: " << name << endl;
@@ -122,7 +122,7 @@ class PythonInterpreter : public Interpreter {
 
     BKE_reports_clear(reports);
 
-    if (!BPY_execute_text(_context, text, reports, false)) {
+    if (!BPY_run_text(_context, text, reports, false)) {
       cerr << "\nError executing Python script from 
PythonInterpreter::interpretText" << endl;
       cerr << "Name: " << name << endl;
       cerr << "Errors: " << endl;
diff --git a/source/blender/python/BPY_extern.h 
b/source/blender/python/BPY_extern.h
index 3fc4df270d5..e1e0d01055a 100644
--- a/source/blender/python/BPY_extern.h
+++ b/sou

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to