chiark / gitweb /
Add more documentation...
[cura.git] / Cura / doctest.py
1 """
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.'
4 """
5 import os
6 import traceback
7 import glob
8 import sys
9 import inspect
10 import types
11 import random
12
13 def treeWalk(moduleList, dirname, fnames):
14         dirname = dirname.replace("\\", ".").replace("/", ".")
15         if dirname == 'Cura.util.pymclevel':
16                 return
17         if dirname == 'Cura.util.Power':
18                 return
19         if dirname == 'Cura.plugins':
20                 return
21         if dirname == 'Cura.resouces':
22                 return
23         for moduleName in filter(lambda f: f.endswith('.py'), fnames):
24                 moduleName = moduleName[:-3]
25                 if moduleName == '__init__':
26                         continue
27                 fullName = '%s.%s' % (dirname, moduleName)
28                 try:
29                         module = __import__(fullName, fromlist=['Cura'], level=1)
30                         moduleList.append(module)
31                 except:
32                         #traceback.print_exc()
33                         print "Failed to load: %s" % (fullName)
34
35 def main():
36         moduleList = []
37         os.path.walk("Cura", treeWalk, moduleList)
38         moduleDocCount = 0
39         functionCount = 0
40         functionDocCount = 0
41         typeCount = 0
42         typeDocCount = 0
43         undocList = []
44         for module in moduleList:
45                 if inspect.getdoc(module):
46                         moduleDocCount += 1
47                 else:
48                         undocList.append(module.__name__)
49                 for name in dir(module):
50                         a = getattr(module, name)
51                         if type(a) is types.FunctionType:
52                                 functionCount += 1
53                                 if inspect.getdoc(a):
54                                         functionDocCount += 1
55                                 # else:
56                                 #       undocList.append('%s.%s' % (module.__name__, name))
57                         elif type(a) is types.TypeType:
58                                 typeCount += 1
59                                 if inspect.getdoc(a):
60                                         typeDocCount += 1
61                                 # else:
62                                 #       undocList.append('%s.%s' % (module.__name__, name))
63                                 for name2 in dir(a):
64                                         a2 = getattr(a, name2)
65                                         if type(a2) is types.MethodType:
66                                                 if hasattr(a.__bases__[0], name2):
67                                                         continue
68                                                 functionCount += 1
69                                                 if inspect.getdoc(a2):
70                                                         functionDocCount += 1
71                                                 # else:
72                                                 #       undocList.append('%s.%s.%s' % (module.__name__, name, name2))
73
74         print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
75         print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
76         print '%d/%d types have documentation.' % (typeDocCount, typeCount)
77         print ''
78         print 'You might want to document:'
79         for n in xrange(0, 10):
80                 print random.Random().choice(undocList)
81
82 if __name__ == '__main__':
83         main()