Welcome to mirror list, hosted at ThFree Co, Russian Federation.

doctest.py « Cura - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: a96f26263f17e7e16beb7793ba430d75dd37f65d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
A helper file to check which parts of the code have documentation and which are lacking documentation.
This because much of the Cura code is currently undocumented which needs to be improved.
"""
import os
import traceback
import glob
import sys
import inspect
import types
import random

def treeWalk(moduleList, dirname, fnames):
	""" Callback from the os.path.walk function, see if the given path is a module and import it to put it in the moduleList """
	dirname = dirname.replace("\\", ".").replace("/", ".")
	if dirname.startswith('Cura.gui'):
		return
	if dirname == 'Cura.util.pymclevel':
		return
	if dirname == 'Cura.util.Power':
		return
	if dirname == 'Cura.plugins':
		return
	if dirname == 'Cura.resouces':
		return
	for moduleName in filter(lambda f: f.endswith('.py'), fnames):
		moduleName = moduleName[:-3]
		if moduleName == '__init__':
			continue
		fullName = '%s.%s' % (dirname, moduleName)
		try:
			module = __import__(fullName, fromlist=['Cura'], level=1)
			moduleList.append(module)
		except:
			#traceback.print_exc()
			print "Failed to load: %s" % (fullName)

def main():
	"""
	Main doctest function.
	Calculate how many things are documented and not documented yet.
	And report a random selection of undocumented functions/ modules.
	"""
	moduleList = []
	os.path.walk("Cura", treeWalk, moduleList)
	moduleDocCount = 0
	functionCount = 0
	functionDocCount = 0
	memberCount = 0
	memberDocCount = 0
	typeCount = 0
	typeDocCount = 0
	undocList = []
	for module in moduleList:
		if inspect.getdoc(module):
			moduleDocCount += 1
		else:
			undocList.append(module.__name__)
		for name in dir(module):
			a = getattr(module, name)
			try:
				if not inspect.getfile(a).startswith('Cura'):
					continue
			except:
				continue
			if type(a) is types.FunctionType:
				functionCount += 1
				if inspect.getdoc(a):
					functionDocCount += 1
				else:
					undocList.append('%s.%s' % (module.__name__, name))
			elif type(a) is types.TypeType:
				typeCount += 1
				if inspect.getdoc(a):
					typeDocCount += 1
				else:
					undocList.append('%s.%s' % (module.__name__, name))
				for name2 in dir(a):
					a2 = getattr(a, name2)
					if type(a2) is types.MethodType:
						if hasattr(a.__bases__[0], name2):
							continue
						memberCount += 1
						if inspect.getdoc(a2):
							memberDocCount += 1
						# else:
						# 	undocList.append('%s.%s.%s' % (module.__name__, name, name2))

	print '%d/%d modules have documentation.' % (moduleDocCount, len(moduleList))
	print '%d/%d types have documentation.' % (typeDocCount, typeCount)
	print '%d/%d functions have documentation.' % (functionDocCount, functionCount)
	print '%d/%d member functions have documentation.' % (memberDocCount, memberCount)
	print '%.1f%% documented.' % (float(moduleDocCount + functionDocCount + typeDocCount + memberDocCount) / float(len(moduleList) + functionCount + typeCount + memberCount) * 100.0)
	print ''
	print 'You might want to document:'
	for n in xrange(0, 10):
		print random.Random().choice(undocList)

if __name__ == '__main__':
	main()