2 A helper file to check which parts of the code have documentation and which are lacking documentation.
3 This because much of the Cura code is currently undocumented which needs to be improved.'
13 def treeWalk(moduleList, dirname, fnames):
14 """ Callback from the os.path.walk function, see if the given path is a module and import it to put it in the moduleList """
15 dirname = dirname.replace("\\", ".").replace("/", ".")
16 if dirname == 'Cura.util.pymclevel':
18 if dirname == 'Cura.util.Power':
20 if dirname == 'Cura.plugins':
22 if dirname == 'Cura.resouces':
24 for moduleName in filter(lambda f: f.endswith('.py'), fnames):
25 moduleName = moduleName[:-3]
26 if moduleName == '__init__':
28 fullName = '%s.%s' % (dirname, moduleName)
30 module = __import__(fullName, fromlist=['Cura'], level=1)
31 moduleList.append(module)
33 #traceback.print_exc()
34 print "Failed to load: %s" % (fullName)
38 Main doctest function.
39 Calculate how many things are documented and not documented yet.
40 And report a random selection of undocumented functions/ modules.
43 os.path.walk("Cura", treeWalk, moduleList)
50 for module in moduleList:
51 if inspect.getdoc(module):
54 undocList.append(module.__name__)
55 for name in dir(module):
56 a = getattr(module, name)
58 if not inspect.getfile(a).startswith('Cura'):
62 if type(a) is types.FunctionType:
67 # undocList.append('%s.%s' % (module.__name__, name))
68 elif type(a) is types.TypeType:
73 # undocList.append('%s.%s' % (module.__name__, name))
75 a2 = getattr(a, name2)
76 if type(a2) is types.MethodType:
77 if hasattr(a.__bases__[0], name2):
80 if inspect.getdoc(a2):
83 # undocList.append('%s.%s.%s' % (module.__name__, name, name2))
85 print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
86 print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
87 print '%d/%d types have documentation.' % (typeDocCount, typeCount)
88 print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount) / float(len(moduleList) + functionCount + typeCount) * 100.0)
90 print 'You might want to document:'
91 for n in xrange(0, 10):
92 print random.Random().choice(undocList)
94 if __name__ == '__main__':