From c47990f41c7364058a72f5f162e5cdc06bce0adc Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 25 Feb 2021 12:00:45 +1100 Subject: PyAPI: expose imbuf.types.ImBuf, include in API docs Without this, the ImBuf type wasn't part of documentation. --- doc/python_api/sphinx_doc_gen.py | 2 ++ source/blender/python/generic/imbuf_py_api.c | 48 ++++++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 3 deletions(-) diff --git a/doc/python_api/sphinx_doc_gen.py b/doc/python_api/sphinx_doc_gen.py index ee9b9df5bef..9eeab6d82bc 100644 --- a/doc/python_api/sphinx_doc_gen.py +++ b/doc/python_api/sphinx_doc_gen.py @@ -228,6 +228,7 @@ else: "blf", "bl_math", "imbuf", + "imbuf.types", "bmesh", "bmesh.ops", "bmesh.types", @@ -1976,6 +1977,7 @@ def write_rst_importable_modules(basepath): "aud": "Audio System", "blf": "Font Drawing", "imbuf": "Image Buffer", + "imbuf.types": "Image Buffer Types", "gpu": "GPU Shader Module", "gpu.types": "GPU Types", "gpu.matrix": "GPU Matrix", diff --git a/source/blender/python/generic/imbuf_py_api.c b/source/blender/python/generic/imbuf_py_api.c index fe72f267a5d..5b4a4fd237e 100644 --- a/source/blender/python/generic/imbuf_py_api.c +++ b/source/blender/python/generic/imbuf_py_api.c @@ -40,6 +40,8 @@ #include #include +static PyObject *BPyInit_imbuf_types(void); + static PyObject *Py_ImBuf_CreatePyObject(ImBuf *ibuf); /* -------------------------------------------------------------------- */ @@ -522,7 +524,7 @@ static PyObject *M_imbuf_write(PyObject *UNUSED(self), PyObject *args, PyObject /** \} */ /* -------------------------------------------------------------------- */ -/** \name Module Definition +/** \name Module Definition (`imbuf`) * \{ */ static PyMethodDef IMB_methods[] = { @@ -547,11 +549,51 @@ static struct PyModuleDef IMB_module_def = { PyObject *BPyInit_imbuf(void) { + PyObject *mod; PyObject *submodule; + PyObject *sys_modules = PyImport_GetModuleDict(); + + mod = PyModule_Create(&IMB_module_def); + + /* `imbuf.types` */ + PyModule_AddObject(mod, "types", (submodule = BPyInit_imbuf_types())); + PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule); + + return mod; +} - submodule = PyModule_Create(&IMB_module_def); +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Module Definition (`imbuf.types`) + * + * `imbuf.types` module, only include this to expose access to `imbuf.types.ImBuf` + * for docs and the ability to use with built-ins such as `isinstance`, `issubclass`. + * \{ */ + +PyDoc_STRVAR(IMB_types_doc, "This module provides access to image buffer types."); + +static struct PyModuleDef IMB_types_module_def = { + PyModuleDef_HEAD_INIT, + "imbuf.types", /* m_name */ + IMB_types_doc, /* m_doc */ + 0, /* m_size */ + NULL, /* m_methods */ + NULL, /* m_reload */ + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL, /* m_free */ +}; + +PyObject *BPyInit_imbuf_types(void) +{ + PyObject *submodule = PyModule_Create(&IMB_types_module_def); + + if (PyType_Ready(&Py_ImBuf_Type) < 0) { + return NULL; + } - PyType_Ready(&Py_ImBuf_Type); + PyModule_AddType(submodule, &Py_ImBuf_Type); return submodule; } -- cgit v1.2.3