source: misc/tools/dependency_graphs/anuga_depgraph2dot.py @ 6115

Last change on this file since 6115 was 6115, checked in by ole, 15 years ago

Customised dependency graphs for ANUGA. This more or less addresses ticket:84.
Now the task is to act on these graphs and restructure ANUGA accordingly.

File size: 2.7 KB
Line 
1"""ANUGA specific dependency graph
2
3Usage:
4    python anuga_dependencies.py <anuga_script>
5"""
6
7from depgraph2dot import pydepgraphdot
8import sys, imp
9
10class 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. omitting them means
32            # that main floats to the top of the page
33            return 1
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        #if type in [imp.PKG_DIRECTORY] and s.startswith('anuga'):
38            # Only consider ANUGA source modules and packages
39           
40            if s.startswith('anuga.config'): return True # Except config.py
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        if I[0] == 'anuga':
76            I = I[1:]
77       
78        return '\\.\\n'.join(I)
79
80           
81       
82def main():
83    ANUGAdepgraph().main(sys.argv[1:])
84
85if __name__=='__main__':
86    main()
87
Note: See TracBrowser for help on using the repository browser.