martido / homebrew-graph

Creates a dependency graph of Homebrew formulae.
Other
217 stars 12 forks source link

Highlighting "leaves" in GraphViz output? #6

Closed jpalardy closed 7 years ago

jpalardy commented 7 years ago

Hi there,

I've been using brew-graph for a while and it's quite helpful. In fact, I noticed I can't depend on the brew leaves output because it doesn't account for "requirements". For example: vim depends on perl, but perl is a "requirement" rather than a "dependency", so perl is considered a "leaf".

I wrote an awk script to find nodes without any dependencies -- aka leaf nodes -- from the output of brew graph. If a node is never on the right side of an arrow, nobody depends on it.

If I incorporated this logic directly in brew-graph, would that be something you would be willing to merge?

In practice, the create_node function could take a 2nd argument, a boolean for leaf. Something like:

def create_node(node, leaf)
  %Q(  "#{node}"#{leaf ? " [style=filled]" : ""};)
end

It opens some questions:

jpalardy commented 7 years ago

highlighted-leaves

A sample of how [style=filled] changes the output -- leaves are gray.

martido commented 7 years ago

Hi,

That's a nice idea. It's actually also pretty simple to do something similar for GraphML. You just specify a different fill color for the nodes. Logic should be the same as in your solution. If you don't mind, I'll extend it to include the changes for GraphML, too.

Also, I'd like to add a command line option for this to give people the choice. Just not sure if it should be enabled by default or not.

jpalardy commented 7 years ago

Sounds good.

I blogged about this -- http://blog.jpalardy.com/posts/untangling-your-homebrew-dependencies/ -- once you've made the improvements, I'll edit the post to only link to your repo.

martido commented 7 years ago

Just released a new version that includes this feature. It is enabled by adding the --highlight-leaves command line switch. It's disabled by default.

Very nice blog post! First mention of brew-graph that I'm aware of. Cool!

Btw, have you ever used the --all switch to create the dependency graph of all formulae? I'm asking because I'm thinking about removing it. It used to work, but I recently noticed that the resulting Dot and GraphML files are unusable. The picture that is created by dot cannot be opened in any image viewer that I tried, and the GraphML file doesn't load in yEd on my machine.

jpalardy commented 7 years ago

No, I don't use --all, it might be useful to some people, but it's probably not the main use case.