Subject: [PATCH] Add edgelist graph backend

From: Kyle Andrews <[email-masked]>
Date: Wed, 15 Feb 2023 05:21:35 +0000

Dear Guix,

I would like to be able to conveniently analyze Guix package
dependencies using general purpose network analysis software such as
igraph. To achieve this, I have added another backend to Guix and which
is exposed via guix graph which spits out a three column table that,
while not technically and edge list, is readily transformed into one
with minimal data munging.

Please see the attached patch file which I have created with `git diff'
from my working tree since I am not yet comfortable with more advanced
git workflows.

diff --git a/guix/graph.scm b/guix/graph.scm
index 41219ab67d..e1760ed92a 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -255,6 +255,24 @@ (define %graphviz-backend
                  emit-prologue emit-epilogue
                  emit-node emit-edge))
 
+(define (emit-edgelist-prologue name port)
+  (display "" port))
+
+(define (emit-edgelist-epilogue port)
+  (display "" port))
+
+(define (emit-edgelist-node id label port)
+  (format port "package, ~a, ~a\n" label id))
+
+(define (emit-edgelist-edge id1 id2 port)
+  (format port "depends, ~a, ~a\n" id1 id2))
+
+(define %edgelist-backend
+  (graph-backend "edgelist"
+                 "Generate graph in CSV edge list format"
+                 emit-edgelist-prologue emit-edgelist-epilogue
+                 emit-edgelist-node emit-edgelist-edge))
+
 
 ;;;
 ;;; d3js export.
@@ -338,7 +356,8 @@ (define %cypher-backend
 (define %graph-backends
   (list %graphviz-backend
         %d3js-backend
-        %cypher-backend))
+        %cypher-backend
+        %edgelist-backend))
 
 (define (lookup-backend name)
   "Return the graph backend called NAME.  Raise an error if it is not found."