Blender
V3.3
|
#include <stdio.h>
#include <Python.h>
#include "MEM_guardedalloc.h"
#include "BLI_fileops.h"
#include "BLI_listbase.h"
#include "BLI_path_util.h"
#include "BLI_string.h"
#include "BKE_context.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_text.h"
#include "DNA_text_types.h"
#include "BPY_extern.h"
#include "BPY_extern_run.h"
#include "bpy_capi_utils.h"
#include "bpy_intern_string.h"
#include "bpy_traceback.h"
#include "../generic/py_capi_utils.h"
Go to the source code of this file.
Classes | |
struct | PyModuleObject |
Functions | |
Run Text / Filename / String | |
bool | BPY_run_filepath (bContext *C, const char *filepath, struct ReportList *reports) |
bool | BPY_run_text (bContext *C, struct Text *text, struct 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 (struct BPy_RunErrInfo *err_info) |
bool | BPY_run_string_as_number (bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, double *r_value) |
bool | BPY_run_string_as_string_and_size (bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value, size_t *r_value_size) |
bool | BPY_run_string_as_string (bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, char **r_value) |
bool | BPY_run_string_as_intptr (bContext *C, const char *imports[], const char *expr, struct BPy_RunErrInfo *err_info, intptr_t *r_value) |
Private Utilities | |
#define | PYMODULE_CLEAR_WORKAROUND |
static void | python_script_error_jump_text (Text *text, const char *filepath) |
static void | bpy_text_filepath_get (char *filepath, const size_t filepath_maxlen, const Main *bmain, const Text *text) |
static bool | python_script_exec (bContext *C, const char *filepath, struct Text *text, struct ReportList *reports, const bool do_jump) |
#define PYMODULE_CLEAR_WORKAROUND |
Definition at line 68 of file bpy_interface_run.c.
bool BPY_run_filepath | ( | bContext * | C, |
const char * | filepath, | ||
struct ReportList * | reports | ||
) |
Definition at line 227 of file bpy_interface_run.c.
References C, NULL, and python_script_exec().
bool BPY_run_string_as_intptr | ( | bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
intptr_t * | r_value | ||
) |
Definition at line 429 of file bpy_interface_run.c.
References bpy_context_clear(), bpy_context_set(), C, PyC_RunString_AsIntPtr(), and run_string_handle_error().
bool BPY_run_string_as_number | ( | bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
double * | r_value | ||
) |
Definition at line 364 of file bpy_interface_run.c.
References bpy_context_clear(), bpy_context_set(), C, PyC_RunString_AsNumber(), and run_string_handle_error().
bool BPY_run_string_as_string | ( | bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
char ** | r_value | ||
) |
Definition at line 419 of file bpy_interface_run.c.
References BPY_run_string_as_string_and_size(), and C.
bool BPY_run_string_as_string_and_size | ( | bContext * | C, |
const char * | imports[], | ||
const char * | expr, | ||
struct BPy_RunErrInfo * | err_info, | ||
char ** | r_value, | ||
size_t * | r_value_size | ||
) |
Definition at line 391 of file bpy_interface_run.c.
References bpy_context_clear(), bpy_context_set(), C, NULL, PyC_RunString_AsStringAndSize(), and run_string_handle_error().
Referenced by BPY_run_string_as_string().
Run an expression, matches: exec(compile(..., "eval"))
.
Definition at line 302 of file bpy_interface_run.c.
References bpy_run_string_impl(), and C.
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(), and WM_keyconfig_reload().
Run an entire script, matches: exec(compile(..., "exec"))
Definition at line 307 of file bpy_interface_run.c.
References bpy_run_string_impl(), and C.
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 241 of file bpy_interface_run.c.
References BKE_reports_clear(), BKE_reports_init(), BKE_reports_print(), BKE_reports_print_test(), BLI_assert, BLI_movelisttolist(), bpy_context_clear(), bpy_context_set(), BPy_errors_to_report(), C, CTX_wm_reports(), ReportList::list, NULL, PyC_DefaultNameSpace(), PyC_MainModule_Backup(), PyC_MainModule_Restore(), PyC_NameSpace_ImportArray(), RPT_ERROR, and RPT_STORE.
Referenced by BPY_run_string_eval(), and BPY_run_string_exec().
bool BPY_run_text | ( | bContext * | C, |
struct Text * | text, | ||
struct ReportList * | reports, | ||
const bool | do_jump | ||
) |
Definition at line 232 of file bpy_interface_run.c.
References C, NULL, and 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 54 of file bpy_interface_run.c.
References BLI_snprintf(), Text::id, ID_BLEND_PATH, ID::name, and SEP.
Referenced by python_script_exec().
Definition at line 38 of file bpy_interface_run.c.
References offset, 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 NULL). |
do_jump | See BPY_run_text. |
The __file__
added into the name-space.
Definition at line 88 of file bpy_interface_run.c.
References BLI_assert, BLI_findindex(), BLI_fopen(), bpy_context_clear(), bpy_context_set(), BPy_errors_to_report(), bpy_intern_str___main__, bpy_text_filepath_get(), BPY_text_free_code(), C, Text::compiled, CTX_data_main(), FILE_MAX, PyModuleObject::md_dict, MEM_freeN, NULL, PyC_DefaultNameSpace(), PyC_MainModule_Backup(), PyC_MainModule_Restore(), PyC_UnicodeFromByte(), python_script_error_jump_text(), Main::texts, and txt_to_buf().
Referenced by BPY_run_filepath(), and BPY_run_text().
|
static |
Definition at line 321 of file bpy_interface_run.c.
References BKE_report(), BKE_reportf(), BKE_reports_print_test(), BLI_strdup(), NULL, 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(), and BPY_run_string_as_string_and_size().