1 | """ANUGA specific dependency graph |
---|
2 | |
---|
3 | Usage: |
---|
4 | python anuga_dependencies.py <anuga_script> |
---|
5 | """ |
---|
6 | |
---|
7 | import sys |
---|
8 | import os.path |
---|
9 | import imp |
---|
10 | from depgraph2dot import pydepgraphdot |
---|
11 | |
---|
12 | class ANUGAdepgraph(pydepgraphdot): |
---|
13 | |
---|
14 | def toocommon(self,s,type): |
---|
15 | """ Return true if references to this module are uninteresting. |
---|
16 | Such references do not get drawn. This is ANUGA specific. |
---|
17 | """ |
---|
18 | |
---|
19 | if s=='__main__': |
---|
20 | # references *to* __main__ are never interesting. |
---|
21 | # Omitting them means that __main__ floats to the top of the page |
---|
22 | return False |
---|
23 | return True |
---|
24 | |
---|
25 | #if type in [imp.PY_SOURCE, imp.C_EXTENSION] and s.startswith('anuga'): |
---|
26 | if s.startswith('anuga.utilities'): |
---|
27 | return True |
---|
28 | elif s.startswith('anuga.caching'): |
---|
29 | return True |
---|
30 | elif type in [imp.PY_SOURCE, imp.PKG_DIRECTORY] and s.startswith('anuga'): |
---|
31 | # Only consider ANUGA source modules and packages |
---|
32 | |
---|
33 | if s.startswith('anuga.config'): return True # Except config.py |
---|
34 | if s == 'anuga': return True # Except the anuga root itself |
---|
35 | |
---|
36 | # sys.stderr.write('Draw dependency to %s\n' % s) |
---|
37 | return False |
---|
38 | else: |
---|
39 | return True |
---|
40 | |
---|
41 | |
---|
42 | def weight(self,a,b): |
---|
43 | # Return the weight of the dependency from a to b. Higher weights |
---|
44 | # usually have shorter straighter edges. Return 1 if it has normal weight. |
---|
45 | # A value of 4 is usually good for ensuring that a related pair of modules |
---|
46 | # are drawn next to each other. This is a default policy - please override. |
---|
47 | # |
---|
48 | if b.split('.')[-1].startswith('_'): |
---|
49 | # A module that starts with an underscore. You need a special reason to |
---|
50 | # import these (for example random imports _random), so draw them close |
---|
51 | # together |
---|
52 | return 4 |
---|
53 | |
---|
54 | # if a nd b exist in the same directory, draw closer together |
---|
55 | a_dir = os.path.basename(os.path.dirname(a)) |
---|
56 | b_dir = os.path.basename(os.path.dirname(b)) |
---|
57 | if a_dir == b_dir: |
---|
58 | return 4 |
---|
59 | |
---|
60 | return 3 |
---|
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 | |
---|