Blender V4.5
bpy_interface_run.cc File Reference
#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_library.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_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)

Function Documentation

◆ BPY_run_filepath()

bool BPY_run_filepath ( bContext * C,
const char * filepath,
ReportList * reports )

Definition at line 235 of file bpy_interface_run.cc.

References BPY_run_filepath(), C, python_script_exec(), and reports.

◆ BPY_run_string_as_intptr()

bool BPY_run_string_as_intptr ( bContext * C,
const char * imports[],
const char * expr,
BPy_RunErrInfo * err_info,
intptr_t * r_value )

◆ BPY_run_string_as_number()

bool BPY_run_string_as_number ( bContext * C,
const char * imports[],
const char * expr,
BPy_RunErrInfo * err_info,
double * r_value )

◆ BPY_run_string_as_string()

bool BPY_run_string_as_string ( bContext * C,
const char * imports[],
const char * expr,
BPy_RunErrInfo * err_info,
char ** r_value )

◆ 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 )

◆ BPY_run_string_as_string_and_len_or_none()

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 )

◆ 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 )

◆ BPY_run_string_eval()

bool BPY_run_string_eval ( bContext * C,
const char * imports[],
const char * expr )

Run an expression, matches: exec(compile(..., "eval")).

Parameters
COptional context (may be null), used for bpy.context and reporting errors to CTX_wm_reports(C).

Definition at line 296 of file bpy_interface_run.cc.

References BPY_run_string_eval(), bpy_run_string_impl(), and C.

Referenced by arg_handle_python_console_run(), BPY_python_start(), BPY_run_string_eval(), BPY_run_text(), 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().

◆ BPY_run_string_exec()

bool BPY_run_string_exec ( bContext * C,
const char * imports[],
const char * expr )

Run an entire script, matches: exec(compile(..., "exec"))

Parameters
COptional context (may be null), used for bpy.context and reporting errors to CTX_wm_reports(C).

Definition at line 301 of file bpy_interface_run.cc.

References BPY_run_string_exec(), bpy_run_string_impl(), and C.

Referenced by arg_handle_addons_set(), arg_handle_python_expr_run(), BPY_run_string_exec(), BPY_run_text(), script_reload_exec(), and wm_file_read_post().

◆ bpy_run_string_impl()

bool bpy_run_string_impl ( bContext * C,
const char * imports[],
const char * expr,
const int mode )
static
Parameters
modePassed to #PyRun_String, matches Python's compile functions mode argument. #Py_eval_input for eval, #Py_file_input for exec.

Definition at line 249 of file bpy_interface_run.cc.

References BLI_assert, bpy_context_clear(), bpy_context_set(), BPy_errors_to_report(), bpy_run_string_impl(), C, CTX_wm_reports(), PyC_DefaultNameSpace(), PyC_MainModule_Backup(), PyC_MainModule_Restore(), and PyC_NameSpace_ImportArray().

Referenced by BPY_run_string_eval(), BPY_run_string_exec(), and bpy_run_string_impl().

◆ BPY_run_text()

bool BPY_run_text ( bContext * C,
Text * text,
ReportList * reports,
const bool do_jump )

Definition at line 240 of file bpy_interface_run.cc.

References BPY_run_text(), C, python_script_exec(), and reports.

◆ bpy_text_filepath_get()

void bpy_text_filepath_get ( char * filepath,
const size_t filepath_maxncpy,
const Main * bmain,
const Text * text )
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(), bpy_text_filepath_get(), Text::id, ID_BLEND_PATH, ID::name, and SEP.

Referenced by bpy_text_filepath_get(), and python_script_exec().

◆ python_compat_wrapper_PyRun_FileExFlags()

PyObject * python_compat_wrapper_PyRun_FileExFlags ( FILE * fp,
const char * filepath,
const int start,
PyObject * globals,
PyObject * locals,
const int closeit,
PyCompilerFlags * flags )
static

◆ python_script_error_jump_text()

void python_script_error_jump_text ( Text * text,
const char * filepath )
static

◆ python_script_exec()

bool python_script_exec ( bContext * C,
const char * filepath,
Text * text,
ReportList * reports,
const bool do_jump )
static

◆ run_string_handle_error()