[Bf-blender-cvs] [c47990f41c7] master: PyAPI: expose imbuf.types.ImBuf, include in API docs

Campbell Barton noreply at git.blender.org
Thu Feb 25 02:06:17 CET 2021


Commit: c47990f41c7364058a72f5f162e5cdc06bce0adc
Author: Campbell Barton
Date:   Thu Feb 25 12:00:45 2021 +1100
Branches: master
https://developer.blender.org/rBc47990f41c7364058a72f5f162e5cdc06bce0adc

PyAPI: expose imbuf.types.ImBuf, include in API docs

Without this, the ImBuf type wasn't part of documentation.

===================================================================

M	doc/python_api/sphinx_doc_gen.py
M	source/blender/python/generic/imbuf_py_api.c

===================================================================

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 <errno.h>
 #include <fcntl.h>
 
+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;
 }



More information about the Bf-blender-cvs mailing list