[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [22573] branches/blender2.5/blender/source /blender/python/epy_doc_gen.py: rna reference doc generation

Campbell Barton ideasman42 at gmail.com
Mon Aug 17 19:26:54 CEST 2009


Revision: 22573
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=22573
Author:   campbellbarton
Date:     2009-08-17 19:26:54 +0200 (Mon, 17 Aug 2009)

Log Message:
-----------
rna reference doc generation
- rna classes,  only include props and functions that are not inherited (epydoc then gives inheritance info)
- include function arguments and return values for in cross reference

Modified Paths:
--------------
    branches/blender2.5/blender/source/blender/python/epy_doc_gen.py

Modified: branches/blender2.5/blender/source/blender/python/epy_doc_gen.py
===================================================================
--- branches/blender2.5/blender/source/blender/python/epy_doc_gen.py	2009-08-17 17:14:37 UTC (rev 22572)
+++ branches/blender2.5/blender/source/blender/python/epy_doc_gen.py	2009-08-17 17:26:54 UTC (rev 22573)
@@ -89,7 +89,7 @@
 		rna_prop_type = rna_prop.type.lower() # enum, float, int, boolean
 		
 		
-		# only for rna funcions, operators should not get pointers as args
+		# only for rna functions, operators should not get pointers as args
 		if rna_prop_type=='pointer':
 			rna_prop_type_refine = "L{%s}" % rna_prop.fixed_type.identifier
 		else:
@@ -200,6 +200,7 @@
 	
 	# Use for faster lookups
 	# use rna_struct.identifier as the key for each dict
+	rna_struct_dict =		{}  # store identifier:rna lookups
 	rna_full_path_dict =	{}	# store the result of full_rna_struct_path(rna_struct)
 	rna_children_dict =		{}	# store all rna_structs nested from here
 	rna_references_dict =	{}	# store a list of rna path strings that reference this type
@@ -216,8 +217,12 @@
 		
 		if rna_base:
 			out.write(ident+ 'class %s(%s):\n' % (identifier, rna_base.identifier))
+			rna_base_prop_keys = rna_base.properties.keys() # could be cached
+			rna_base_func_keys = [f.identifier for f in rna_base.functions]
 		else:
 			out.write(ident+ 'class %s:\n' % identifier)
+			rna_base_prop_keys = []
+			rna_base_func_keys = []
 		
 		out.write(ident+ '\t"""\n')
 		
@@ -249,12 +254,10 @@
 		
 		for rna_prop_identifier, rna_prop in rna_struct.properties.items():
 			
-			if rna_prop_identifier=='RNA':
-				continue
+			if rna_prop_identifier=='RNA':					continue
+			if rna_prop_identifier=='rna_type':				continue
+			if rna_prop_identifier in rna_base_prop_keys:	continue # does this prop exist in our parent class, if so skip
 			
-			if rna_prop_identifier=='rna_type':
-				continue
-			
 			rna_desc = rna_prop.description.strip()
 			
 			if rna_desc: rna_words.update(rna_desc.split())
@@ -308,7 +311,8 @@
 		# Write functions 
 		# for rna_func in rna_struct.functions: # Better ignore inherited (line below)
 		for rna_func in rna_functions_dict[identifier]:
-			write_func(rna_func, ident+'\t', out, 'FUNCTION')
+			if rna_func not in rna_base_func_keys:
+				write_func(rna_func, ident+'\t', out, 'FUNCTION')
 		
 		out.write('\n')
 		
@@ -331,14 +335,19 @@
 	structs = []
 	for rna_type_name in dir(bpy.types):
 		rna_type = getattr(bpy.types, rna_type_name)
-		if hasattr(rna_type, '__rna__'):
+		
+		try:		rna_struct = rna_type.__rna__
+		except:	rna_struct = None
+		
+		if rna_struct:
 			#if not rna_type_name.startswith('__'):
-			rna_struct = rna_type.__rna__
+			
 			identifier = rna_struct.identifier
 			structs.append( (base_id(rna_struct), identifier, rna_struct) )	
 			
+			# Simple lookup
+			rna_struct_dict[identifier] = rna_struct
 			
-			
 			# Store full rna path 'GameObjectSettings' -> 'Object.GameObjectSettings'
 			rna_full_path_dict[identifier] = full_rna_struct_path(rna_struct)
 			
@@ -395,16 +404,21 @@
 	# precalc vars to avoid a lot of looping
 	for (rna_base, identifier, rna_struct) in structs:
 		
+		if rna_base:
+			rna_base_prop_keys = rna_struct_dict[rna_base].properties.keys() # could cache
+			rna_base_func_keys = [f.identifier for f in rna_struct_dict[rna_base].functions]
+		else:
+			rna_base_prop_keys = []
+			rna_base_func_keys= []
 		
 		# rna_struct_path = full_rna_struct_path(rna_struct)
 		rna_struct_path = rna_full_path_dict[identifier]
 		
 		for rna_prop_identifier, rna_prop in rna_struct.properties.items():
-			if rna_prop_identifier=='RNA':
-				continue
 			
-			if rna_prop_identifier=='rna_type':
-				continue
+			if rna_prop_identifier=='RNA':					continue
+			if rna_prop_identifier=='rna_type':				continue
+			if rna_prop_identifier in rna_base_prop_keys:	continue
 			
 			try:		rna_prop_ptr = rna_prop.fixed_type
 			except:	rna_prop_ptr = None
@@ -413,8 +427,22 @@
 			if rna_prop_ptr:
 				rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_prop_identifier) )
 		
+		for rna_func in rna_struct.functions:
+			for rna_prop_identifier, rna_prop in rna_func.parameters.items():
+				
+				if rna_prop_identifier=='RNA':					continue
+				if rna_prop_identifier=='rna_type':				continue
+				if rna_prop_identifier in rna_base_func_keys:	continue
+					
+				
+				try:		rna_prop_ptr = rna_prop.fixed_type
+				except:	rna_prop_ptr = None
+				
+				# Does this property point to me?
+				if rna_prop_ptr:
+					rna_references_dict[rna_prop_ptr.identifier].append( "%s.%s" % (rna_struct_path, rna_func.identifier) )
+			
 		
-		
 		# Store nested children
 		nested = rna_struct.nested
 		if nested:





More information about the Bf-blender-cvs mailing list