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.startswith('Cura.gui'):
18 if dirname == 'Cura.util.pymclevel':
20 if dirname == 'Cura.util.Power':
22 if dirname == 'Cura.plugins':
24 if dirname == 'Cura.resouces':
26 for moduleName in filter(lambda f: f.endswith('.py'), fnames):
27 moduleName = moduleName[:-3]
28 if moduleName == '__init__':
30 fullName = '%s.%s' % (dirname, moduleName)
32 module = __import__(fullName, fromlist=['Cura'], level=1)
33 moduleList.append(module)
35 #traceback.print_exc()
36 print "Failed to load: %s" % (fullName)
40 Main doctest function.
41 Calculate how many things are documented and not documented yet.
42 And report a random selection of undocumented functions/ modules.
45 os.path.walk("Cura", treeWalk, moduleList)
54 for module in moduleList:
55 if inspect.getdoc(module):
58 undocList.append(module.__name__)
59 for name in dir(module):
60 a = getattr(module, name)
62 if not inspect.getfile(a).startswith('Cura'):
66 if type(a) is types.FunctionType:
71 undocList.append('%s.%s' % (module.__name__, name))
72 elif type(a) is types.TypeType:
77 undocList.append('%s.%s' % (module.__name__, name))
79 a2 = getattr(a, name2)
80 if type(a2) is types.MethodType:
81 if hasattr(a.__bases__[0], name2):
84 if inspect.getdoc(a2):
87 # undocList.append('%s.%s.%s' % (module.__name__, name, name2))
89 print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
90 print '%d/%d types have documentation.' % (typeDocCount, typeCount)
91 print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
92 print '%d/%d member functions have documentation.' % (memberDocCount, memberCount)
93 print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount + memberDocCount) / float(len(moduleList) + functionCount + typeCount + memberCount) * 100.0)
95 print 'You might want to document:'
96 for n in xrange(0, 10):
97 print random.Random().choice(undocList)
99 if __name__ == '__main__':