Visualising the dependency graph for workflow tasks

2016-02-28

Generating the task graph

For the task dependency graph to be plotted, it must first be exported to ‘dot’ (GraphViz) format.

From Sake

$ sake visual --no-graphviz
$ mv dependencies deps.dot

From Rake

Export the dependencies:

$ rake -P > deps.txt

Convert them to ‘dot’ format with this script (adapted from https://gist.github.com/7911768.git):

#!/usr/bin/env ruby
deps = File.open('deps.txt')
dot = File.open('deps.dot', 'w')
dot.puts "digraph g {"
task = "?"
deps.each_line do |line|
    line.chomp!
    if line =~ /^rake (.*)/
        task = $1
        dot.puts "\"#{task}\";"
    else
        dot.puts "\"#{task}\" -> \"#{line.strip}\";"
    end
end
dot.puts "}"

Plotting the task graph

GraphViz

Do a basic plot of the ‘dot’ file:

$ dot -Tsvg deps.dot

yEd

Convert the ‘dot’ file to GML format with this script:

#!/usr/bin/env python2
import networkx as nx
graph = nx.read_dot('deps.dot')
nx.write_gml(graph, 'deps.gml')

Import the GML file into yEd to edit the graph:

$ yed deps.gml &

(Here yed is an alias for the full java -jar ... command.)


Clean up:

$ rm deps.{txt,dot,gml,svg}