|
Blender V4.3
|
#include <cstdio>#include <Python.h>#include "MEM_guardedalloc.h"#include "BLI_fileops.h"#include "BLI_listbase.h"#include "BLI_path_utils.hh"#include "BLI_string.h"#include "BKE_context.hh"#include "BKE_main.hh"#include "BKE_report.hh"#include "BKE_text.h"#include "DNA_text_types.h"#include "BPY_extern_run.hh"#include "bpy_capi_utils.hh"#include "bpy_intern_string.hh"#include "bpy_traceback.hh"#include "../generic/py_capi_utils.hh"Go to the source code of this file.
Functions | |
Private Utilities | |
| static void | python_script_error_jump_text (Text *text, const char *filepath) |
| static void | bpy_text_filepath_get (char *filepath, const size_t filepath_maxncpy, const Main *bmain, const Text *text) |
| static PyObject * | python_compat_wrapper_PyRun_FileExFlags (FILE *fp, const char *filepath, const int start, PyObject *globals, PyObject *locals, const int closeit, PyCompilerFlags *flags) |
| static bool | python_script_exec (bContext *C, const char *filepath, Text *text, ReportList *reports, const bool do_jump) |
Run Text / Filename / String | |
| bool | BPY_run_filepath (bContext *C, const char *filepath, ReportList *reports) |
| bool | BPY_run_text (bContext *C, Text *text, ReportList *reports, const bool do_jump) |
| static bool | bpy_run_string_impl (bContext *C, const char *imports[], const char *expr, const int mode) |
| bool | BPY_run_string_eval (bContext *C, const char *imports[], const char *expr) |
| bool | BPY_run_string_exec (bContext *C, const char *imports[], const char *expr) |
Run Python & Evaluate Utilities | |
Return values as plain C types, useful to run Python scripts in code that doesn't deal with Python data-types. | |
| static void | run_string_handle_error (BPy_RunErrInfo *err_info) |
| bool | BPY_run_string_as_number (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, double *r_value) |
| bool | BPY_run_string_as_string_and_len (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len) |
| bool | BPY_run_string_as_string (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) |
| bool | BPY_run_string_as_string_and_len_or_none (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_len) |
| bool | BPY_run_string_as_string_or_none (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, char **r_value) |
| bool | BPY_run_string_as_intptr (bContext *C, const char *imports[], const char *expr, BPy_RunErrInfo *err_info, intptr_t *r_value) |
| bool BPY_run_filepath | ( | bContext * | C, |
| const char * | filepath, | ||
| ReportList * | reports ) |
Definition at line 232 of file bpy_interface_run.cc.
References python_script_exec().
| bool BPY_run_string_as_intptr | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| intptr_t * | r_value ) |
Definition at line 456 of file bpy_interface_run.cc.
References bpy_context_clear(), bpy_context_set(), PyC_RunString_AsIntPtr(), and run_string_handle_error().
| bool BPY_run_string_as_number | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| double * | r_value ) |
Definition at line 357 of file bpy_interface_run.cc.
References bpy_context_clear(), bpy_context_set(), PyC_RunString_AsNumber(), and run_string_handle_error().
| bool BPY_run_string_as_string | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| char ** | r_value ) |
Definition at line 412 of file bpy_interface_run.cc.
References BPY_run_string_as_string_and_len().
| bool BPY_run_string_as_string_and_len | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| char ** | r_value, | ||
| size_t * | r_value_len ) |
Definition at line 384 of file bpy_interface_run.cc.
References bpy_context_clear(), bpy_context_set(), PyC_RunString_AsStringAndSize(), and run_string_handle_error().
Referenced by BPY_run_string_as_string().
| bool BPY_run_string_as_string_and_len_or_none | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| char ** | r_value, | ||
| size_t * | r_value_len ) |
Definition at line 419 of file bpy_interface_run.cc.
References bpy_context_clear(), bpy_context_set(), PyC_RunString_AsStringAndSizeOrNone(), and run_string_handle_error().
Referenced by BPY_run_string_as_string_or_none().
| bool BPY_run_string_as_string_or_none | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr, | ||
| BPy_RunErrInfo * | err_info, | ||
| char ** | r_value ) |
Definition at line 448 of file bpy_interface_run.cc.
References BPY_run_string_as_string_and_len_or_none().
| bool BPY_run_string_eval | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr ) |
Run an expression, matches: exec(compile(..., "eval")).
| C | Optional context (may be null), used for bpy.context and reporting errors to CTX_wm_reports(C). |
Definition at line 293 of file bpy_interface_run.cc.
References bpy_run_string_impl().
Referenced by arg_handle_python_console_run(), BPY_python_start(), Freestyle::PythonInterpreter::interpretString(), script_reload_exec(), WM_exit_ex(), wm_file_read_post(), wm_homefile_read_ex(), wm_init_scripts_extensions_once(), and WM_keyconfig_reload().
| bool BPY_run_string_exec | ( | bContext * | C, |
| const char * | imports[], | ||
| const char * | expr ) |
Run an entire script, matches: exec(compile(..., "exec"))
| C | Optional context (may be null), used for bpy.context and reporting errors to CTX_wm_reports(C). |
Definition at line 298 of file bpy_interface_run.cc.
References bpy_run_string_impl().
Referenced by arg_handle_addons_set(), arg_handle_python_expr_run(), script_reload_exec(), and wm_file_read_post().
|
static |
| mode | Passed to #PyRun_String, matches Python's compile functions mode argument. #Py_eval_input for eval, #Py_file_input for exec. |
Definition at line 246 of file bpy_interface_run.cc.
References BLI_assert, bpy_context_clear(), bpy_context_set(), BPy_errors_to_report(), CTX_wm_reports(), PyC_DefaultNameSpace(), PyC_MainModule_Backup(), PyC_MainModule_Restore(), and PyC_NameSpace_ImportArray().
Referenced by BPY_run_string_eval(), and BPY_run_string_exec().
| bool BPY_run_text | ( | bContext * | C, |
| Text * | text, | ||
| ReportList * | reports, | ||
| const bool | do_jump ) |
Definition at line 237 of file bpy_interface_run.cc.
References python_script_exec().
|
static |
Generate a filepath from a text-block so we can tell what file a text block comes from.
Definition at line 55 of file bpy_interface_run.cc.
References BLI_snprintf(), ID_BLEND_PATH, and SEP.
Referenced by python_script_exec().
|
static |
Compatibility wrapper for #PyRun_FileExFlags.
Definition at line 71 of file bpy_interface_run.cc.
References BLI_assert, BLI_file_read_data_as_mem_from_handle(), MEM_freeN(), PyC_UnicodeFromBytes(), and UNLIKELY.
Referenced by python_script_exec().
|
static |
Definition at line 39 of file bpy_interface_run.cc.
References python_script_error_jump(), and txt_move_to().
Referenced by python_script_exec().
|
static |
Execute a file-path or text-block.
| reports | Report exceptions as errors (may be nullptr). |
| do_jump | See BPY_run_text. |
The __file__ added into the name-space.
Definition at line 130 of file bpy_interface_run.cc.
References BLI_assert, BLI_findindex(), BLI_fopen(), BLI_fstat(), bpy_context_clear(), bpy_context_set(), BPy_errors_to_report(), bpy_text_filepath_get(), CTX_data_main(), FILE_MAX, MEM_freeN(), PyC_DefaultNameSpace(), PyC_MainModule_Backup(), PyC_MainModule_Restore(), PyC_UnicodeFromBytes(), python_compat_wrapper_PyRun_FileExFlags(), python_script_error_jump_text(), S_ISDIR, Main::texts, and txt_to_buf().
Referenced by BPY_run_filepath(), and BPY_run_text().
|
static |
Definition at line 312 of file bpy_interface_run.cc.
References BKE_report(), BKE_reportf(), BKE_reports_print_test(), BLI_assert, BLI_strdup(), PyC_ExceptionBuffer(), PyC_ExceptionBuffer_Simple(), BPy_RunErrInfo::r_string, BPy_RunErrInfo::report_prefix, BPy_RunErrInfo::reports, RPT_ERROR, and BPy_RunErrInfo::use_single_line_error.
Referenced by BPY_run_string_as_intptr(), BPY_run_string_as_number(), BPY_run_string_as_string_and_len(), and BPY_run_string_as_string_and_len_or_none().