harrysarson commented on PR #1949:
URL: https://github.com/apache/buildstream/pull/1949#issuecomment-2434733652

   Thanks for this script! I hit a small issue when using it on a complex 
buildstream project containing junctions. The generated graphviz ends up 
containing colons in the wrong place making it invalid. See small patch below 
that fixes the script base on a recommendation I found here 
https://graphviz.readthedocs.io/en/stable/manual.html#node-ports-compass
   
   ```patch
   --- a/contrib/bst-graph
   +++ b/contrib/bst-graph
   @@ -29,6 +29,7 @@ installed.
    import argparse
    import subprocess
    import re
   +import urllib.encode
    
    from graphviz import Digraph
    from ruamel.yaml import YAML
   @@ -55,6 +56,10 @@ def parse_args():
        return parser.parse_args()
    
    
   +def safe_name(s):
   +    return urllib.parse.quote_plus(s.encode())
   +
   +
    def parse_graph(lines):
        '''Return nodes and edges of the parsed grpah.
    
   @@ -80,12 +85,13 @@ def parse_graph(lines):
            build_dep = parser.load(build_dep)
            runtime_dep = parser.load(runtime_dep)
    
   -        nodes.add(name)
   -        [build_deps.add((name, dep)) for dep in build_dep if dep]
   -        [runtime_deps.add((name, dep)) for dep in runtime_dep if dep]
   +        safe_name = safe_name(name)
    
   -    return nodes, build_deps, runtime_deps
   +        nodes.add((safe_name, name))
   +        [build_deps.add((safe_name, safe_name(dep))) for dep in build_dep 
if dep]
   +        [runtime_deps.add((safe_name, safe_name(dep))) for dep in 
runtime_dep if dep]
    
   +    return nodes, build_deps, runtime_deps
    
    def generate_graph(nodes, build_deps, runtime_deps):
        '''Generate graph from given nodes and edges.
   @@ -99,8 +105,8 @@ def generate_graph(nodes, build_deps, runtime_deps):
           A graphviz.Digraph object
        '''
        graph = Digraph()
   -    for node in nodes:
   -        graph.node(node)
   +    for tag, name in nodes:
   +        graph.node(tag, label=name)
        for source, target in build_deps:
            graph.edge(source, target, label='build-dep')
        for source, target in runtime_deps:
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to