Visualize Go's internal package relationships on a commit-by-commit basis

call-aimation.gif
Program used: bxcodec / go-clean-arch

Overview

  1. It is difficult to understand programs with complicated relationships between Go's internal packages. --I want to visualize ――Because it's a big deal, let's visualize each commit and make it an animation

Preparation

code

What i did

  1. Get the commit log
  2. Execute command for each commit
  3. Output Go's internal package relation to dot Fariru and create gif
  4. Create an animation with the same gif size for each commit

1. Get the commit log

You can get it with git log --pretty = oneline. Anyway with python

res = subprocess.check_output(["git", "-C", path_dir, "log", "--pretty=oneline"])

I want to get only the hash value of the commit (hash value + comment). I got only the first hash value separated by spaces and made it into a list.

2. Execute command for each commit

I reset each commit and executed the command (is there a better way than reset ??).

for commit in log_list:
    subprocess.call(["git", "-C", path_dir, "reset", "--hard", commit]) |
    command(path_dir)

Use the path of the directory where the program is located when executing the command.

3. Output Go's internal package relation to dot Fariru and create gif

3.1. Dot file creation

This is the most difficult. There is a very useful package called parser that will get the package you are importing in the file. This can be grouped from file to package.

trouble

--By file-> By package The parser also gets the package name of the file, but it's indistinguishable if the same package name is in another directory. I saved the directory, but there seems to be an easier way --Distinguishing external packages I wanted to target only internal packages (made by myself), how can I distinguish them? ?? I made it like "external if there is github", but it seems that it is not a very good method.

3.2. Create gif file from dot file

Use graphviz. dot -T gif sample.dot -o sample.gif

4. Create an animation with the same gif size for each commit

4.1. Align gif sizes

When making an animation, if the size of each file is different, the large size will be cut off. mogrify -resize (width)x(height)! *.gif Choose a size that feels good.

4.2. Animation creation

Use ImageMagick. convert -delay 5 -loop 0 *.gif animation.gif

Referenced site

-Execute the git command from outside the Git directory -How to execute a command using subprocess in Python

from now on

The display position of the graph becomes different for each commit, and it is difficult to see when animating. I want to arrange it somehow.

Recommended Posts

Visualize Go's internal package relationships on a commit-by-commit basis
Register as a package on PyPI
Folium: Visualize data on a map with Python
Visualize grib2 on a map with python (matplotlib)