mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / depgraph.mdwn
1 [[!template id=gitrepo repo=depgraph]]
2
3 This set of scripts scans a Python file for module dependencies, and
4 generates code for [Graphviz dot][graphviz].  See [[call_graph]] for a
5 script that generates dependency graphs *within* a module.
6
7 Originally by Toby Dickenson, the scripts are good for giving you the
8 "long view" on how your project is organized.  I've altered the
9 [originals][] a bit.
10
11 My [py2depgraph.py][] also prints out path information for each
12 module, so that you can show or hide module nodes based on those
13 paths.  For example, ignoring system modules to focus on your
14 additions.
15
16 My [depgraph2dot.py][] has an added method
17 `depgraph2dot.invalidpath(module_name, path)` that you can override to
18 determine the paths you like.
19
20 I've also added the `depgraph2dot` methods 
21
22 * `is_Cext(module_name, path)`,
23 * `Cext_depends(module_name, path)`,
24 * `Cext_edge_attributes(module_name, Cext_name)`,
25 * `Cext_node_attributes(Cext_name)`, and
26 * `Cext_depcolor(Cext_name)`
27
28 to detect and configure the shared C libraries extending Python, so
29 you know where to look for the code your Python depends on.
30
31 [[!template id=gitrepo repo=unfold_protein]]
32
33 As example, here is the depgraph of my protein unfolding program `unfold.py`
34
35     $ python py2depgraph.py unfold.py | python depgraph2dot.py | dot -T png -o depgraph.png
36
37 with standard python modules in orange,
38 python packages in hash-based colors,
39 and C extension modules in light blue.
40 Again, these are only the files containing either `wking` or `comedi`
41 in their paths.
42
43 [[!img depgraph.png class="scaled"
44   alt="unfold.py dependency graph"
45   title="unfold.py dependency graph"]]
46
47 [graphviz]: http://www.graphviz.org
48 [originals]: http://tarind.com/depgraph.html
49 [py2depgraph.py]:
50   http://git.tremily.us/?p=depgraph.git;a=blob_plain;f=py2depgraph.py;hb=HEAD
51 [depgraph2dot.py]:
52   http://git.tremily.us/?p=depgraph.git;a=blob_plain;f=depgraph2dot.py;hb=HEAD
53
54 [[!tag tags/programming]]
55 [[!tag tags/python]]
56 [[!tag tags/tools]]