14#define PY_SSIZE_T_CLEAN
30#include "RNA_prototypes.hh"
73 ".. function:: script_paths()\n"
75 " Return 2 paths to blender scripts directories.\n"
77 " :return: (system, user) strings will be empty when not found.\n"
78 " :rtype: tuple[str, str]\n");
81 PyObject *
ret = PyTuple_New(2);
87 PyTuple_SET_ITEM(
ret, 0, item);
91 PyTuple_SET_ITEM(
ret, 1, item);
101 PyObject *py_list =
static_cast<PyObject *
>(bpath_data->
user_data);
109 ".. function:: blend_paths(*, absolute=False, packed=False, local=False)\n"
111 " Returns a list of paths to external files referenced by the loaded .blend file.\n"
113 " :param absolute: When true the paths returned are made absolute.\n"
114 " :type absolute: bool\n"
115 " :param packed: When true include file paths for packed data.\n"
116 " :type packed: bool\n"
117 " :param local: When true skip linked library paths.\n"
118 " :type local: bool\n"
119 " :return: path list.\n"
120 " :rtype: list[str]\n");
130 static const char *_keywords[] = {
"absolute",
"packed",
"local",
nullptr};
131 static _PyArg_Parser _parser = {
140 if (!_PyArg_ParseTupleAndKeywordsFast(args,
163 list = PyList_New(0);
168 path_data.
flag = flag;
178 ".. function:: flip_name(name, *, strip_digits=False)\n"
180 " Flip a name between left/right sides, useful for \n"
181 " mirroring bone names.\n"
183 " :param name: Bone name to flip.\n"
185 " :param strip_digits: Whether to remove ``.###`` suffix.\n"
186 " :type strip_digits: bool\n"
187 " :return: The flipped name.\n"
191 const char *name_src =
nullptr;
192 Py_ssize_t name_src_len;
193 bool strip_digits =
false;
195 static const char *_keywords[] = {
"",
"strip_digits",
nullptr};
196 static _PyArg_Parser _parser = {
204 if (!_PyArg_ParseTupleAndKeywordsFast(
205 args, kw, &_parser, &name_src, &name_src_len,
PyC_ParseBool, &strip_digits))
212 const size_t size = name_src_len + 2;
213 char *name_dst =
static_cast<char *
>(PyMem_MALLOC(size));
216 PyObject *
result = PyUnicode_FromStringAndSize(name_dst, name_dst_len);
218 PyMem_FREE(name_dst);
236 static const char *_keywords[] = {
"type",
"path",
nullptr};
237 static _PyArg_Parser _parser = {
245 if (!_PyArg_ParseTupleAndKeywordsFast(args,
267 bpy_system_resource_doc,
268 ".. function:: system_resource(type, *, path=\"\")\n"
270 " Return a system resource path.\n"
272 " :param type: string in ['DATAFILES', 'SCRIPTS', 'EXTENSIONS', 'PYTHON'].\n"
274 " :param path: Optional subdirectory.\n"
275 " :type path: str | bytes\n");
289 static const char *_keywords[] = {
"type",
"path",
nullptr};
290 static _PyArg_Parser _parser = {
298 if (!_PyArg_ParseTupleAndKeywordsFast(args,
317 bpy_resource_path_doc,
318 ".. function:: resource_path(type, *, major=None, minor=None)\n"
320 " Return the base path for storing system files.\n"
322 " :param type: The resource type.\n"
323 " :type type: Literal['USER', 'LOCAL', 'SYSTEM', 'SYSTEM_LIBS']\n"
324 " :param major: Major version. None (the default) uses ``bpy.app.version[0]``.\n"
325 " :type major: int | None\n"
326 " :param minor: Minor version. None (the default) uses ``bpy.app.version[1]``.\n"
327 " :type minor: int | None\n"
328 " :return: the resource path (not necessarily existing).\n"
333 " ``SYSTEM_LIBS`` mirrors ``SYSTEM`` "
334 "but resolves to the directory for architecture-dependent libraries "
335 "(typically under ``/usr/lib/...`` rather than ``/usr/share/...``). "
336 "It is an empty string on builds without a separate library directory, "
337 "such as portable builds and the Python module.\n");
349 std::optional<int> major;
350 std::optional<int> minor;
352 static const char *_keywords[] = {
"type",
"major",
"minor",
nullptr};
353 static _PyArg_Parser _parser = {
362 if (!_PyArg_ParseTupleAndKeywordsFast(args,
388 bpy_driver_secure_code_test_doc,
389 ".. function:: _driver_secure_code_test(code, *, namespace=None, verbose=False)\n"
391 " Test if the script should be considered trusted.\n"
393 " :param code: The code to test.\n"
394 " :type code: code\n"
395 " :param namespace: The namespace of values which are allowed.\n"
396 " :type namespace: dict[str, Any] | None\n"
397 " :param verbose: Print the reason for considering insecure to the ``stderr``.\n"
398 " :type verbose: bool\n"
399 " :return: True when the script is considered trusted.\n"
404 PyObject *py_namespace =
nullptr;
405 PyC_TypeOrNone py_namespace_or_none = {&PyDict_Type, &py_namespace};
406 bool verbose =
false;
407 static const char *_keywords[] = {
"code",
"namespace",
"verbose",
nullptr};
408 static _PyArg_Parser _parser = {
413 ":driver_secure_code_test",
417 if (!_PyArg_ParseTupleAndKeywordsFast(args,
423 &py_namespace_or_none,
434 bpy_escape_identifier_doc,
435 ".. function:: escape_identifier(string)\n"
437 " Simple string escaping function used for animation paths.\n"
439 " :param string: text\n"
440 " :type string: str\n"
441 " :return: The escaped string.\n"
445 Py_ssize_t value_str_len;
446 const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
448 if (value_str ==
nullptr) {
449 PyErr_SetString(PyExc_TypeError,
"expected a string");
453 const size_t size = (value_str_len * 2) + 1;
454 char *value_escape_str =
static_cast<char *
>(PyMem_MALLOC(size));
455 const Py_ssize_t value_escape_str_len =
BLI_str_escape(value_escape_str, value_str, size);
457 PyObject *value_escape;
458 if (value_escape_str_len == value_str_len) {
460 value_escape = value;
463 value_escape = PyUnicode_FromStringAndSize(value_escape_str, value_escape_str_len);
466 PyMem_FREE(value_escape_str);
473 bpy_unescape_identifier_doc,
474 ".. function:: unescape_identifier(string)\n"
476 " Simple string un-escape function used for animation paths.\n"
477 " This performs the reverse of :func:`escape_identifier`.\n"
479 " :param string: text\n"
480 " :type string: str\n"
481 " :return: The un-escaped string.\n"
485 Py_ssize_t value_str_len;
486 const char *value_str = PyUnicode_AsUTF8AndSize(value, &value_str_len);
488 if (value_str ==
nullptr) {
489 PyErr_SetString(PyExc_TypeError,
"expected a string");
493 const size_t size = value_str_len + 1;
494 char *value_unescape_str =
static_cast<char *
>(PyMem_MALLOC(size));
496 value_unescape_str, value_str, value_str_len);
498 PyObject *value_unescape;
499 if (value_unescape_str_len == value_str_len) {
501 value_unescape = value;
504 value_unescape = PyUnicode_FromStringAndSize(value_unescape_str, value_unescape_str_len);
507 PyMem_FREE(value_unescape_str);
509 return value_unescape;
527 bpy_context_members_doc,
528 ".. function:: context_members()\n"
530 " :return: A dict where the key is the context and the value is a tuple of it's members.\n"
531 " :rtype: dict[str, tuple[str]]\n");
538 } context_members_all[] = {
551 for (
int context_index = 0; context_index <
ARRAY_SIZE(context_members_all); context_index++) {
552 const char *name = context_members_all[context_index].name;
553 const char **dir = context_members_all[context_index].dir;
555 for (i = 0; dir[i]; i++) {
558 PyObject *members = PyTuple_New(i);
559 for (i = 0; dir[i]; i++) {
560 PyTuple_SET_ITEM(members, i, PyUnicode_FromString(dir[i]));
562 PyDict_SetItemString(
result, name, members);
575 bpy_rna_enum_items_static_doc,
576 ".. function:: rna_enum_items_static()\n"
578 " :return: A dict where the key the name of the enum, the value is a tuple of enum items.\n"
579 " :rtype: dict[str, tuple[:class:`bpy.types.EnumPropertyItem`]]\n");
580static PyObject *bpy_rna_enum_items_static(PyObject * )
582#define DEF_ENUM(id) {STRINGIFY(id), id},
590 for (
int i = 0; i <
ARRAY_SIZE(enum_info); i++) {
594 PyObject *value = PyTuple_New(items_count);
595 for (
int item_index = 0; item_index < items_count; item_index++) {
597 nullptr, RNA_EnumPropertyItem, (
void *)&items[item_index]);
600 PyDict_SetItemString(
result, enum_info[i].
id, value);
609 bpy_ghost_backend_doc,
610 ".. function:: _ghost_backend()\n"
612 " :return: An identifier for the GHOST back-end.\n"
628 bpy_wm_capabilities_doc,
629 ".. function:: _wm_capabilities()\n"
631 " :return: A dictionary of capabilities (string keys, boolean values).\n"
632 " :rtype: dict[str, bool]\n");
635 PyObject *py_id_capabilities = PyUnicode_FromString(
"_wm_capabilities_");
636 PyObject *
result =
nullptr;
637 switch (PyObject_GetOptionalAttr(self, py_id_capabilities, &
result)) {
647#define SetFlagItem(x) \
648 PyDict_SetItemString(result, STRINGIFY(x), ((WM_CAPABILITY_##x) & flag) ? Py_True : Py_False);
657 PyObject_SetAttr(self, py_id_capabilities,
result);
666 Py_DECREF(py_id_capabilities);
672# pragma clang diagnostic push
673# pragma clang diagnostic ignored "-Wcast-function-type"
675# pragma GCC diagnostic push
676# pragma GCC diagnostic ignored "-Wcast-function-type"
684 bpy_script_paths_doc},
687 METH_VARARGS | METH_KEYWORDS,
688 bpy_blend_paths_doc},
691 METH_VARARGS | METH_KEYWORDS,
695 METH_VARARGS | METH_KEYWORDS,
699 METH_VARARGS | METH_KEYWORDS,
700 bpy_system_resource_doc},
703 METH_VARARGS | METH_KEYWORDS,
704 bpy_resource_path_doc},
705 {
"escape_identifier",
708 bpy_escape_identifier_doc},
709 {
"unescape_identifier",
712 bpy_unescape_identifier_doc},
716 bpy_context_members_doc},
717 {
"rna_enum_items_static",
718 reinterpret_cast<PyCFunction
>(bpy_rna_enum_items_static),
720 bpy_rna_enum_items_static_doc},
723 {
"_driver_secure_code_test",
725 METH_VARARGS | METH_KEYWORDS,
726 bpy_driver_secure_code_test_doc},
730 bpy_ghost_backend_doc},
734 bpy_wm_capabilities_doc},
736 {
nullptr,
nullptr, 0,
nullptr},
741# pragma clang diagnostic pop
743# pragma GCC diagnostic pop
749 PyObject *
mod = PyImport_ImportModuleLevel(modname,
nullptr,
nullptr,
nullptr, 0);
768 if (modpath.has_value()) {
770 PyObject *sys_path = PySys_GetObject(
"path");
772 PyList_Insert(sys_path, 0, py_modpath);
773 Py_DECREF(py_modpath);
776 printf(
"bpy: couldn't find 'scripts/modules', blender probably won't start.\n");
785 mod = PyModule_New(
"_bpy");
788 PyDict_SetItemString(PyImport_GetModuleDict(),
"_bpy",
mod);
796 PyModule_AddObject(
mod,
"types", bpy_types);
809 PyObject *bpy_types_dict_dummy = PyDict_New();
813 BLI_assert(PyDict_GET_SIZE(bpy_types_dict_dummy) == 0);
814 Py_DECREF(bpy_types_dict_dummy);
816 PyObject *bpy_types_module_py_dict = PyModule_GetDict(bpy_types_module_py);
836#define PYMODULE_ADD_METHOD(mod, meth) \
837 PyModule_AddObject(mod, (meth)->ml_name, (PyObject *)PyCFunction_New(meth, mod))
842 BLI_assert((m->ml_flags & (METH_CLASS | METH_STATIC)) == 0);
857#undef PYMODULE_ADD_METHOD
PyObject * Freestyle_Init()
#define PYMODULE_ADD_METHOD(mod, meth)
btMatrix3x3 absolute() const
Return the matrix with all values non negative.
VecBase< float, D > constexpr mod(VecOp< float, D >, VecOp< float, D >) RET
static PyObject * bpy_resource_path(PyObject *, PyObject *args, PyObject *kw)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
const char * file_context_dir[]
const char * node_context_dir[]
static PyObject * bpy_wm_capabilities(PyObject *self)
const char * WM_ghost_backend()
int PyC_ParseBool(PyObject *o, void *p)
static bool bpy_blend_foreach_path_cb(BPathForeachPathData *bpath_data, char *, size_t, const char *path_src)
PyObject * BPY_rna_module()
void IDPropertyUIData_Init_Types()
bool BPY_rna_gizmo_module(PyObject *mod_par)
BPy_StructRNA * bpy_context_module
PyMethodDef meth_bpy_owner_id_set
const char * image_context_dir[]
void BKE_bpath_foreach_path_main(BPathForeachPathData *bpath_data)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static PyObject * bpy_driver_secure_code_test(PyObject *, PyObject *args, PyObject *kw)
const char * buttons_context_dir[]
PyObject * bpy_package_py
PyObject * BPY_operator_module()
static PyObject * bpy_system_resource(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_context_members(PyObject *)
uint RNA_enum_items_count(const EnumPropertyItem *item)
void BPY_rna_types_dict_set(PyObject *dict)
PyObject * pyrna_struct_CreatePyObject(PointerRNA *ptr)
@ BLENDER_RESOURCE_PATH_SYSTEM_LIBS
@ BLENDER_RESOURCE_PATH_SYSTEM
@ BLENDER_RESOURCE_PATH_USER
@ BLENDER_RESOURCE_PATH_LOCAL
PyMethodDef meth_bpy_unregister_class
PyObject * PyC_UnicodeFromBytes(const char *str)
PyObject * BPyInit_blend_data_path_meta_type()
PyObject * BPyInit_geometry_set_type()
void BPY_rna_types_finalize_external_types(PyObject *submodule)
bool BPY_driver_secure_bytecode_test(PyObject *expr_code, PyObject *py_namespace, const bool verbose)
std::optional< std::string > BKE_appdir_folder_id(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
static PyObject * bpy_ghost_backend(PyObject *)
PyObject * BPY_utils_units()
PyObject * BPY_utils_previews_module()
PyMethodDef meth_bpy_register_class
int BPY_library_load_type_ready()
PyObject * BPyInit_inline_shader_nodes_type()
char char size_t BLI_str_escape(char *__restrict dst, StringRef src, size_t dst_maxncpy) ATTR_NONNULL(1)
PyObject * BPY_msgbus_module()
PyMethodDef BPY_cli_command_register_def
constexpr size_t ARRAY_SIZE(const T(&arg)[N]) noexcept
PyObject * BPY_rna_types()
int PyC_ParseOptionalInt(PyObject *o, void *p)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
int PyC_ParseUnicodeAsBytesAndSize(PyObject *o, void *p)
const char * clip_context_dir[]
static PyObject * bpy_escape_identifier(PyObject *, PyObject *value)
const char * view3d_context_dir[]
const char * text_context_dir[]
static PyObject * bpy_blend_paths(PyObject *, PyObject *args, PyObject *kw)
std::optional< std::string > BKE_appdir_folder_id_user_notest(int folder_id, const char *subfolder) ATTR_WARN_UNUSED_RESULT
static PyObject * bpy_import_test(const char *modname)
static PyMethodDef bpy_methods[]
@ BKE_BPATH_FOREACH_PATH_SKIP_PACKED
@ BKE_BPATH_FOREACH_PATH_ABSOLUTE
@ BKE_BPATH_FOREACH_PATH_SKIP_LINKED
void BPy_init_modules(bContext *C)
eWM_CapabilitiesFlag WM_capabilities_flag()
std::optional< std::string > BKE_appdir_resource_path_id_with_version(int folder_id, bool check_is_dir, int version)
size_t size_t BLI_str_unescape(char *__restrict dst, const char *__restrict src, size_t src_len) ATTR_NONNULL(1
PyObject * PyC_UnicodeFromStdStr(const std::string &str)
const char * screen_context_dir[]
static PyObject * bpy_unescape_identifier(PyObject *, PyObject *value)
int PyC_ParseStringEnum(PyObject *o, void *p)
static PyObject * bpy_flip_name(PyObject *, PyObject *args, PyObject *kw)
@ BLENDER_SYSTEM_EXTENSIONS
@ BLENDER_USER_EXTENSIONS
@ BLENDER_SYSTEM_DATAFILES
void BPY_rna_types_extend_capi(PyObject *bpy_types)
PyMethodDef BPY_cli_command_unregister_def
int PyC_ParseTypeOrNone(PyObject *o, void *p)
PyMethodDef meth_bpy_owner_id_get
static PyObject * bpy_user_resource(PyObject *, PyObject *args, PyObject *kw)
static PyObject * bpy_script_paths(PyObject *)
int BPY_rna_data_context_type_ready()
const char * sequencer_context_dir[]
PyObject * BPY_rna_props()
PyObject * BPY_app_struct()
size_t BLI_string_flip_side_name(char *name_dst, const char *name_src, bool strip_number, size_t name_dst_maxncpy) ATTR_NONNULL(1
header-only compatibility defines.
BPathForeachPathFunctionCallback callback_function