PyAPI: use bpy_rna_types_capi.c to set type methods

Remove use of '_bpy' as an intermediate module to store functions
which were then assigned in bpy_types.py.
This commit is contained in:
Campbell Barton
2020-05-29 14:50:29 +10:00
parent e115b7b06d
commit 654fde2dd2
9 changed files with 86 additions and 63 deletions

View File

@@ -25,12 +25,7 @@ StructRNA = bpy_types.bpy_struct
StructMetaPropGroup = bpy_types.bpy_struct_meta_idprop
# StructRNA = bpy_types.Struct
bpy_types.BlendDataLibraries.load = _bpy._library_load
bpy_types.BlendDataLibraries.write = _bpy._library_write
bpy_types.BlendData.user_map = _bpy._rna_id_collection_user_map
bpy_types.BlendData.batch_remove = _bpy._rna_id_collection_batch_remove
bpy_types.BlendData.orphans_purge = _bpy._rna_id_collection_orphans_purge
# Note that methods extended in C are defined in: 'bpy_rna_types_capi.c'
class Context(StructRNA):
__slots__ = ()

View File

@@ -71,6 +71,7 @@ extern StructRNA RNA_BackgroundImage;
extern StructRNA RNA_BevelModifier;
extern StructRNA RNA_BezierSplinePoint;
extern StructRNA RNA_BlendData;
extern StructRNA RNA_BlendDataLibraries;
extern StructRNA RNA_BlendTexture;
extern StructRNA RNA_BlenderRNA;
extern StructRNA RNA_BoidRule;

View File

@@ -380,10 +380,7 @@ void BPy_init_modules(void)
PyModule_AddObject(mod, "types", BPY_rna_types());
/* needs to be first so bpy_types can run */
BPY_library_load_module(mod);
BPY_library_write_module(mod);
BPY_rna_id_collection_module(mod);
BPY_library_load_type_ready();
BPY_rna_gizmo_module(mod);

View File

@@ -21,7 +21,9 @@
#ifndef __BPY_LIBRARY_H__
#define __BPY_LIBRARY_H__
int BPY_library_load_module(PyObject *mod_par);
int BPY_library_write_module(PyObject *mod_par);
int BPY_library_load_type_ready(void);
extern PyMethodDef BPY_library_load_method_def;
extern PyMethodDef BPY_library_write_method_def;
#endif /* __BPY_LIBRARY_H__ */

View File

@@ -459,15 +459,15 @@ static PyObject *bpy_lib_dir(BPy_Library *self)
return PyDict_Keys(self->dict);
}
int BPY_library_load_module(PyObject *mod_par)
PyMethodDef BPY_library_load_method_def = {
"load",
(PyCFunction)bpy_lib_load,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_lib_load_doc,
};
int BPY_library_load_type_ready(void)
{
static PyMethodDef load_meth = {
"load",
(PyCFunction)bpy_lib_load,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_lib_load_doc,
};
PyModule_AddObject(mod_par, "_library_load", PyCFunction_New(&load_meth, NULL));
/* some compilers don't like accessing this directly, delay assignment */
bpy_lib_Type.tp_getattro = PyObject_GenericGetAttr;

View File

@@ -204,16 +204,9 @@ finally:
return ret;
}
int BPY_library_write_module(PyObject *mod_par)
{
static PyMethodDef write_meth = {
"write",
(PyCFunction)bpy_lib_write,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_lib_write_doc,
};
PyModule_AddObject(mod_par, "_library_write", PyCFunction_New(&write_meth, NULL));
return 0;
}
PyMethodDef BPY_library_write_method_def = {
"write",
(PyCFunction)bpy_lib_write,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_lib_write_doc,
};

View File

@@ -385,32 +385,21 @@ static PyObject *bpy_orphans_purge(PyObject *UNUSED(self),
return Py_None;
}
int BPY_rna_id_collection_module(PyObject *mod_par)
{
static PyMethodDef user_map = {
"user_map", (PyCFunction)bpy_user_map, METH_VARARGS | METH_KEYWORDS, bpy_user_map_doc};
PyModule_AddObject(mod_par, "_rna_id_collection_user_map", PyCFunction_New(&user_map, NULL));
static PyMethodDef batch_remove = {
"batch_remove",
(PyCFunction)bpy_batch_remove,
METH_VARARGS | METH_KEYWORDS,
bpy_batch_remove_doc,
};
PyModule_AddObject(
mod_par, "_rna_id_collection_batch_remove", PyCFunction_New(&batch_remove, NULL));
static PyMethodDef orphans_purge = {
"orphans_purge",
(PyCFunction)bpy_orphans_purge,
METH_VARARGS | METH_KEYWORDS,
bpy_orphans_purge_doc,
};
PyModule_AddObject(
mod_par, "_rna_id_collection_orphans_purge", PyCFunction_New(&orphans_purge, NULL));
return 0;
}
PyMethodDef BPY_rna_id_collection_user_map_method_def = {
"user_map",
(PyCFunction)bpy_user_map,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_user_map_doc,
};
PyMethodDef BPY_rna_id_collection_batch_remove_method_def = {
"batch_remove",
(PyCFunction)bpy_batch_remove,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_batch_remove_doc,
};
PyMethodDef BPY_rna_id_collection_orphans_purge_method_def = {
"orphans_purge",
(PyCFunction)bpy_orphans_purge,
METH_STATIC | METH_VARARGS | METH_KEYWORDS,
bpy_orphans_purge_doc,
};

View File

@@ -21,6 +21,8 @@
#ifndef __BPY_RNA_ID_COLLECTION_H__
#define __BPY_RNA_ID_COLLECTION_H__
int BPY_rna_id_collection_module(PyObject *);
extern PyMethodDef BPY_rna_id_collection_user_map_method_def;
extern PyMethodDef BPY_rna_id_collection_batch_remove_method_def;
extern PyMethodDef BPY_rna_id_collection_orphans_purge_method_def;
#endif /* __BPY_RNA_ID_COLLECTION_H__ */

View File

@@ -33,8 +33,10 @@
#include "BLI_utildefines.h"
#include "bpy_library.h"
#include "bpy_rna.h"
#include "bpy_rna_callback.h"
#include "bpy_rna_id_collection.h"
#include "bpy_rna_types_capi.h"
#include "../generic/py_capi_utils.h"
@@ -45,6 +47,31 @@
#include "WM_api.h"
/* -------------------------------------------------------------------- */
/** \name Blend Data
* \{ */
static struct PyMethodDef pyrna_blenddata_methods[] = {
{NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_user_map_method_def */
{NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_batch_remove_method_def */
{NULL, NULL, 0, NULL}, /* #BPY_rna_id_collection_orphans_purge_method_def */
{NULL, NULL, 0, NULL},
};
/** \} */
/* -------------------------------------------------------------------- */
/** \name Blend Data Libraries
* \{ */
static struct PyMethodDef pyrna_blenddatalibraries_methods[] = {
{NULL, NULL, 0, NULL}, /* #BPY_library_load_method_def */
{NULL, NULL, 0, NULL}, /* #BPY_library_write_method_def */
{NULL, NULL, 0, NULL},
};
/** \} */
/* -------------------------------------------------------------------- */
/** \name Window Manager Clipboard Property
*
@@ -164,7 +191,24 @@ static struct PyMethodDef pyrna_space_methods[] = {
void BPY_rna_types_extend_capi(void)
{
/* BlendData */
ARRAY_SET_ITEMS(pyrna_blenddata_methods,
BPY_rna_id_collection_user_map_method_def,
BPY_rna_id_collection_batch_remove_method_def,
BPY_rna_id_collection_orphans_purge_method_def);
BLI_assert(ARRAY_SIZE(pyrna_blenddata_methods) == 4);
pyrna_struct_type_extend_capi(&RNA_BlendData, pyrna_blenddata_methods, NULL);
/* BlendDataLibraries */
ARRAY_SET_ITEMS(
pyrna_blenddatalibraries_methods, BPY_library_load_method_def, BPY_library_write_method_def);
BLI_assert(ARRAY_SIZE(pyrna_blenddatalibraries_methods) == 3);
pyrna_struct_type_extend_capi(&RNA_BlendDataLibraries, pyrna_blenddatalibraries_methods, NULL);
/* Space */
pyrna_struct_type_extend_capi(&RNA_Space, pyrna_space_methods, NULL);
/* WindowManager */
pyrna_struct_type_extend_capi(
&RNA_WindowManager, pyrna_windowmanager_methods, pyrna_windowmanager_getset);
}