update sphinx docgen
authorCampbell Barton <ideasman42@gmail.com>
Mon, 29 Apr 2013 16:20:49 +0000 (16:20 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Mon, 29 Apr 2013 16:20:49 +0000 (16:20 +0000)
was missing context property attributes - context.mode for example. add RNA properties into context docs.

also minor updates
- exclude freestyle if its not enabled.
- add missing context member.

doc/python_api/sphinx_doc_gen.py

index d71c76b469ccbf32106b7272ca4773497468d374..d844b04dce5d7c4108dbb05539994a5505e3dfd3 100644 (file)
@@ -70,6 +70,14 @@ except:
 
 import rna_info     # blender module
 
+
+def rna_info_BuildRNAInfo_cache():
+    if rna_info_BuildRNAInfo_cache.ret is None:
+        rna_info_BuildRNAInfo_cache.ret = rna_info.BuildRNAInfo()
+    return rna_info_BuildRNAInfo_cache.ret
+rna_info_BuildRNAInfo_cache.ret = None
+# --- end rna_info cache
+
 # import rpdb2; rpdb2.start_embedded_debugger('test')
 import os
 import sys
@@ -302,6 +310,12 @@ except ImportError:
     BPY_LOGGER.debug("Warning: Built without 'aud' module, docs incomplete...")
     EXCLUDE_MODULES = list(EXCLUDE_MODULES) + ["aud"]
 
+try:
+    __import__("freestyle")
+except ImportError:
+    BPY_LOGGER.debug("Warning: Built without 'freestyle' module, docs incomplete...")
+    EXCLUDE_MODULES = list(EXCLUDE_MODULES) + ["freestyle"]
+
 # examples
 EXAMPLES_DIR = os.path.abspath(os.path.join(SCRIPT_DIR, "examples"))
 EXAMPLE_SET = set()
@@ -986,6 +1000,7 @@ context_type_map = {
     "texture": ("Texture", False),
     "texture_slot": ("MaterialTextureSlot", False),
     "texture_user": ("ID", False),
+    "texture_user_property": ("Property", False),
     "vertex_paint_object": ("Object", False),
     "visible_bases": ("ObjectBase", True),
     "visible_bones": ("EditBone", True),
@@ -1009,6 +1024,47 @@ def pycontext2sphinx(basepath):
     fw("\n")
     fw("Note that all context values are readonly, but may be modified through the data api or by running operators\n\n")
 
+    def write_contex_cls():
+
+        fw(title_string("Global Context", "-"))
+        fw("These properties are avilable in any contexts.\n\n")
+
+        # very silly. could make these global and only access once.
+        # structs, funcs, ops, props = rna_info.BuildRNAInfo()
+        structs, funcs, ops, props = rna_info_BuildRNAInfo_cache()
+        struct = structs[("", "Context")]
+        struct_blacklist = RNA_BLACKLIST.get(struct.identifier, ())
+        del structs, funcs, ops, props
+
+        sorted_struct_properties = struct.properties[:]
+        sorted_struct_properties.sort(key=lambda prop: prop.identifier)
+
+        # First write RNA
+        for prop in sorted_struct_properties:
+            # support blacklisting props
+            if prop.identifier in struct_blacklist:
+                continue
+
+            type_descr = prop.get_type_description(class_fmt=":class:`%s`", collection_id=_BPY_PROP_COLLECTION_ID)
+            fw(".. data:: %s\n\n" % prop.identifier)
+            if prop.description:
+                fw("   %s\n\n" % prop.description)
+
+            # special exception, cant use genric code here for enums
+            if prop.type == "enum":
+                enum_text = pyrna_enum2sphinx(prop)
+                if enum_text:
+                    write_indented_lines("   ", fw, enum_text)
+                    fw("\n")
+                del enum_text
+            # end enum exception
+
+            fw("   :type: %s\n\n" % type_descr)
+
+    write_contex_cls()
+    del write_contex_cls
+    # end
+
     # nasty, get strings directly from blender because there is no other way to get it
     import ctypes
 
@@ -1079,7 +1135,9 @@ def pyrna_enum2sphinx(prop, use_empty_descriptions=False):
 def pyrna2sphinx(basepath):
     """ bpy.types and bpy.ops
     """
-    structs, funcs, ops, props = rna_info.BuildRNAInfo()
+    # structs, funcs, ops, props = rna_info.BuildRNAInfo()
+    structs, funcs, ops, props = rna_info_BuildRNAInfo_cache()
+
     if FILTER_BPY_TYPES is not None:
         structs = {k: v for k, v in structs.items() if k[1] in FILTER_BPY_TYPES}