Blender  V3.3
Classes
bpy_interface_run.c File Reference
#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)
 

Macro Definition Documentation

◆ PYMODULE_CLEAR_WORKAROUND

#define PYMODULE_CLEAR_WORKAROUND

Definition at line 68 of file bpy_interface_run.c.

Function Documentation

◆ BPY_run_filepath()

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().

◆ BPY_run_string_as_intptr()

bool BPY_run_string_as_intptr ( bContext C,
const char *  imports[],
const char *  expr,
struct 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,
struct 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,
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.

◆ BPY_run_string_as_string_and_size()

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 
)

◆ BPY_run_string_eval()

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

◆ BPY_run_string_exec()

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

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().

◆ bpy_run_string_impl()

static bool bpy_run_string_impl ( bContext C,
const char *  imports[],
const char *  expr,
const int  mode 
)
static

◆ BPY_run_text()

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().

◆ bpy_text_filepath_get()

static void bpy_text_filepath_get ( char *  filepath,
const size_t  filepath_maxlen,
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 54 of file bpy_interface_run.c.

References BLI_snprintf(), Text::id, ID_BLEND_PATH, ID::name, and SEP.

Referenced by python_script_exec().

◆ python_script_error_jump_text()

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

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().

◆ python_script_exec()

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

Execute a file-path or text-block.

Parameters
reportsReport exceptions as errors (may be NULL).
do_jumpSee BPY_run_text.
Note
Share a function for this since setup/cleanup logic is the same.

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().

◆ run_string_handle_error()

static void run_string_handle_error ( struct BPy_RunErrInfo err_info)
static