Don't unnecessarily import from modules depending on pygraphviz.

Closes #525.  Two modules use the same compiled regex; store it in the module that does not import pygraphviz.