Example using doc

This example uses the doc package to inspect the relationships within one of its own modules: doc/doc/utils.py


In [1]:
cd /Users/harrold/Documents/GitHub/stharrold/doc/


/Users/harrold/Documents/GitHub/stharrold/doc

In [2]:
from __future__ import absolute_import, division, print_function
import doc
%matplotlib inline

In [3]:
# Create a dict from the docstrings in doc/doc/utils.py
docs_dict = doc.utils.make_docs_dict(fpath='/Users/harrold/Documents/GitHub/stharrold/doc/doc/utils.py')
doc.utils.pretty_print_dict(dobj=docs_dict, indent=0)


RELATED: set([''])
docstring: [omitted]
generate_edges:
  CALLED_BY: set(['make_graph'])
  CALLS: set(['generate_edges'])
  RELATED: set(['generate_positions', 'make_docs_dict', 'parse_see_also'])
  col_offset: 0
  docstring: [omitted]
  lineno: 211
generate_positions:
  CALLED_BY: set(['make_positions_dict'])
  CALLS: set(['generate_positions'])
  RELATED: set(['generate_edges', 'make_docs_dict'])
  col_offset: 0
  docstring: [omitted]
  lineno: 287
make_docs_dict:
  CALLED_BY: set([''])
  CALLS: set(['parse_docstring'])
  RELATED: set([''])
  col_offset: 0
  docstring: [omitted]
  lineno: 130
make_graph:
  CALLED_BY: set([''])
  CALLS: set(['generate_edges'])
  RELATED: set(['make_docs_dict', 'plot_graph'])
  col_offset: 0
  docstring: [omitted]
  lineno: 256
make_positions_dict:
  CALLED_BY: set([''])
  CALLS: set(['generate_positions'])
  RELATED: set(['make_docs_dict', 'plot_graph', 'make_graph'])
  col_offset: 0
  docstring: [omitted]
  lineno: 334
parse_docstring:
  CALLED_BY: set([''])
  CALLS: set(['parse_see_also'])
  RELATED: set([''])
  col_offset: 0
  docstring: [omitted]
  lineno: 71
parse_see_also:
  CALLED_BY: set(['parse_docstring'])
  CALLS: set([''])
  RELATED: set([''])
  col_offset: 0
  docstring: [omitted]
  lineno: 32
plot_graph:
  CALLED_BY: set([''])
  CALLS: set([''])
  RELATED: set(['make_positions_dict', 'make_graph'])
  col_offset: 0
  docstring: [omitted]
  lineno: 393
pretty_print_dict:
  CALLED_BY: set([''])
  CALLS: set([''])
  RELATED: set(['make_docs_dict'])
  col_offset: 0
  docstring: [omitted]
  lineno: 179

In [4]:
print("Graph the relationships between methods within the module.")
print("NOTE: Asymmetries in the thickness of the graph edges show\n" +
      "    that the manual labeling of relationships within doc/utils.py\n" +
      "    is inconsistent.")
graph = doc.utils.make_graph(dobj=docs_dict, parent='')
doc.utils.plot_graph(graph=graph, fixed=None, positions=None, show_plot=True, fpath=None)


Graph the relationships between methods within the module.
NOTE: Asymmetries in the thickness of the graph edges show
    that the manual labeling of relationships within doc/utils.py
    is inconsistent.

In [5]:
print("Plot the relationships between modules rank-sorted by:\n" +
      "line number from top to bottom\n" +
      "column number from left to right.")
print("NOTE: As of 2015-04-08, all methods are at column 0, so rank sorting is degenerate.")
positions = doc.utils.make_positions_dict(dobj=docs_dict, graph=graph, parent='')
doc.utils.plot_graph(graph=graph, fixed=None, positions=positions, show_plot=True, fpath=None)


Plot the relationships between modules rank-sorted by:
line number from top to bottom
column number from left to right.
NOTE: As of 2015-04-08, all methods are at column 0, so rank sorting is degenerate.

TODO


In [6]:
print("TODO: Color code edges by label.\n" +
      "Here, the edge label is just the string representation of the relationship.")
import networkx as nx
positions=nx.spring_layout(graph)
nx.draw(graph, pos=positions)
nx.draw_networkx_labels(graph, pos=positions)
nx.draw_networkx_edge_labels(graph, pos=positions)


TODO: Color code edges by label.
Here, the edge label is just the string representation of the relationship.
Out[6]:
{('generate_edges', 'generate_edges'): <matplotlib.text.Text at 0x10b2b7550>,
 ('generate_edges',
  'generate_positions'): <matplotlib.text.Text at 0x10b2ac950>,
 ('generate_edges', 'make_docs_dict'): <matplotlib.text.Text at 0x10b402050>,
 ('generate_edges', 'make_graph'): <matplotlib.text.Text at 0x10b2dc950>,
 ('generate_edges', 'parse_see_also'): <matplotlib.text.Text at 0x10b2acf50>,
 ('generate_positions',
  'generate_edges'): <matplotlib.text.Text at 0x10b40ed50>,
 ('generate_positions',
  'generate_positions'): <matplotlib.text.Text at 0x10b41bed0>,
 ('generate_positions',
  'make_docs_dict'): <matplotlib.text.Text at 0x10b402bd0>,
 ('generate_positions',
  'make_positions_dict'): <matplotlib.text.Text at 0x10b288a10>,
 ('make_docs_dict', 'parse_docstring'): <matplotlib.text.Text at 0x10b2b7b10>,
 ('make_graph', 'generate_edges'): <matplotlib.text.Text at 0x10b2cf850>,
 ('make_graph', 'make_docs_dict'): <matplotlib.text.Text at 0x10b402610>,
 ('make_graph', 'plot_graph'): <matplotlib.text.Text at 0x10b40e790>,
 ('make_positions_dict',
  'generate_positions'): <matplotlib.text.Text at 0x10b41b350>,
 ('make_positions_dict',
  'make_docs_dict'): <matplotlib.text.Text at 0x10b40e1d0>,
 ('make_positions_dict', 'make_graph'): <matplotlib.text.Text at 0x10b2cf290>,
 ('make_positions_dict', 'plot_graph'): <matplotlib.text.Text at 0x10b2c5110>,
 ('parse_docstring', 'parse_see_also'): <matplotlib.text.Text at 0x10b2dca50>,
 ('parse_see_also', 'parse_docstring'): <matplotlib.text.Text at 0x10b2dc350>,
 ('plot_graph', 'make_graph'): <matplotlib.text.Text at 0x10b41b910>,
 ('plot_graph', 'make_positions_dict'): <matplotlib.text.Text at 0x10b2c56d0>,
 ('pretty_print_dict',
  'make_docs_dict'): <matplotlib.text.Text at 0x10b2c5c90>}
/Users/harrold/anaconda/lib/python2.7/site-packages/matplotlib/text.py:52: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if rotation in ('horizontal', None):
/Users/harrold/anaconda/lib/python2.7/site-packages/matplotlib/text.py:54: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif rotation == 'vertical':

In [7]:
print("TODO: Color code edges by label.\n" +
      "Here, the edge label is just the string representation of the relationship.")
positions = doc.utils.make_positions_dict(dobj=docs_dict, graph=graph, parent='')
nx.draw(graph, pos=positions)
nx.draw_networkx_labels(graph, pos=positions)
nx.draw_networkx_edge_labels(graph, pos=positions)


TODO: Color code edges by label.
Here, the edge label is just the string representation of the relationship.
Out[7]:
{('generate_edges', 'generate_edges'): <matplotlib.text.Text at 0x10bb6b950>,
 ('generate_edges',
  'generate_positions'): <matplotlib.text.Text at 0x10bb5ed50>,
 ('generate_edges', 'make_docs_dict'): <matplotlib.text.Text at 0x10bb9d450>,
 ('generate_edges', 'make_graph'): <matplotlib.text.Text at 0x10bb8fd50>,
 ('generate_edges', 'parse_see_also'): <matplotlib.text.Text at 0x10bb6b390>,
 ('generate_positions',
  'generate_edges'): <matplotlib.text.Text at 0x10bbb5190>,
 ('generate_positions',
  'generate_positions'): <matplotlib.text.Text at 0x10bbc1310>,
 ('generate_positions',
  'make_docs_dict'): <matplotlib.text.Text at 0x10bb9dfd0>,
 ('generate_positions',
  'make_positions_dict'): <matplotlib.text.Text at 0x10b631290>,
 ('make_docs_dict', 'parse_docstring'): <matplotlib.text.Text at 0x10bb6bf10>,
 ('make_graph', 'generate_edges'): <matplotlib.text.Text at 0x10bb85c50>,
 ('make_graph', 'make_docs_dict'): <matplotlib.text.Text at 0x10bb9da10>,
 ('make_graph', 'plot_graph'): <matplotlib.text.Text at 0x10bba9b90>,
 ('make_positions_dict',
  'generate_positions'): <matplotlib.text.Text at 0x10bbb5750>,
 ('make_positions_dict',
  'make_docs_dict'): <matplotlib.text.Text at 0x10bba95d0>,
 ('make_positions_dict', 'make_graph'): <matplotlib.text.Text at 0x10bb85690>,
 ('make_positions_dict', 'plot_graph'): <matplotlib.text.Text at 0x10bb77510>,
 ('parse_docstring', 'parse_see_also'): <matplotlib.text.Text at 0x10bb8fe50>,
 ('parse_see_also', 'parse_docstring'): <matplotlib.text.Text at 0x10bb8f750>,
 ('plot_graph', 'make_graph'): <matplotlib.text.Text at 0x10bbb5d10>,
 ('plot_graph', 'make_positions_dict'): <matplotlib.text.Text at 0x10bb77ad0>,
 ('pretty_print_dict',
  'make_docs_dict'): <matplotlib.text.Text at 0x10bb850d0>}

In [ ]: