1 | """ANUGA specific dependency graph |
---|
2 | |
---|
3 | Usage: |
---|
4 | python anuga_dependencies.py <anuga_script> |
---|
5 | """ |
---|
6 | |
---|
7 | from depgraph2dot import pydepgraphdot |
---|
8 | import sys, imp |
---|
9 | |
---|
10 | class ANUGAdepgraph(pydepgraphdot): |
---|
11 | |
---|
12 | def toocommon(self,s,type): |
---|
13 | """ Return true if references to this module are uninteresting. |
---|
14 | Such references do not get drawn. This is ANUGA specific. |
---|
15 | """ |
---|
16 | |
---|
17 | #imp types: |
---|
18 | #C_BUILTIN = 6 |
---|
19 | #C_EXTENSION = 3 |
---|
20 | #IMP_HOOK = 9 |
---|
21 | #PKG_DIRECTORY = 5 |
---|
22 | #PY_CODERESOURCE = 8 |
---|
23 | #PY_COMPILED = 2 |
---|
24 | #PY_FROZEN = 7 |
---|
25 | #PY_RESOURCE = 4 |
---|
26 | #PY_SOURCE = 1 |
---|
27 | #SEARCH_ERROR = 0 |
---|
28 | |
---|
29 | |
---|
30 | if s=='__main__': |
---|
31 | # references *to* __main__ are never interesting. |
---|
32 | # Omitting them means that __main__ floats to the top of the page |
---|
33 | return True |
---|
34 | |
---|
35 | #if type in [imp.PY_SOURCE, imp.C_EXTENSION] and s.startswith('anuga'): |
---|
36 | if type in [imp.PY_SOURCE, imp.PKG_DIRECTORY] and s.startswith('anuga'): |
---|
37 | # Only consider ANUGA source modules and packages |
---|
38 | |
---|
39 | if s.startswith('anuga.config'): return True # Except config.py |
---|
40 | if s == 'anuga': return True # Except the anuga root itself |
---|
41 | |
---|
42 | sys.stderr.write('Draw dependency to %s\n' % s) |
---|
43 | return False |
---|
44 | |
---|
45 | else: |
---|
46 | return True |
---|
47 | |
---|
48 | |
---|
49 | def weight(self,a,b): |
---|
50 | # Return the weight of the dependency from a to b. Higher weights |
---|
51 | # usually have shorter straighter edges. Return 1 if it has normal weight. |
---|
52 | # A value of 4 is usually good for ensuring that a related pair of modules |
---|
53 | # are drawn next to each other. This is a default policy - please override. |
---|
54 | # |
---|
55 | if b.split('.')[-1].startswith('_'): |
---|
56 | # A module that starts with an underscore. You need a special reason to |
---|
57 | # import these (for example random imports _random), so draw them close |
---|
58 | # together |
---|
59 | return 4 |
---|
60 | return 1 |
---|
61 | |
---|
62 | def alien(self,a,b): |
---|
63 | # Return non-zero if references to this module are strange, and should be drawn |
---|
64 | # extra-long. the value defines the length, in rank. This is also good for putting some |
---|
65 | # vertical space between seperate subsystems. This is a default policy - please override. |
---|
66 | # |
---|
67 | return 0 |
---|
68 | |
---|
69 | def label(self,s): |
---|
70 | # Convert a module name to a formatted node label. |
---|
71 | # |
---|
72 | |
---|
73 | # Remove leading 'anuga' in label |
---|
74 | I = s.split('.') |
---|
75 | |
---|
76 | if len(I) > 1: |
---|
77 | if I[0] == 'anuga': |
---|
78 | I = I[1:] |
---|
79 | |
---|
80 | return '\\.\\n'.join(I) |
---|
81 | |
---|
82 | |
---|
83 | |
---|
84 | def main(): |
---|
85 | ANUGAdepgraph().main(sys.argv[1:]) |
---|
86 | |
---|
87 | if __name__=='__main__': |
---|
88 | main() |
---|
89 | |
---|