cogent3 / c3dev

cogent3 developer tools
5 stars 9 forks source link

DEV: identify a tool for selectively building dependency graph #26

Open GavinHuttley opened 1 year ago

GavinHuttley commented 1 year ago

Use case here is we have some modules that need eventually to be removed as they duplicate functionality in other libraries on which we already depend. However, given the size of those modules it is rather daunting to approach the problem.

We need the ability to create a dependency graph that is conditioned on a specific module so we can understand where it is being used.

The specific use case is cogent3.maths.stats.special.

khiron commented 1 year ago

2 tools

https://github.com/thebjorn/pydeps and https://github.com/khiron/snakefood3

Pydeps is more polished/featured featured. It reads bytecode from .pyc files to extract out all actual imports (vs declared imports in the source) and integrates with an installed instance of Graphviz to generate Dot language text describing the graph, and render it as an .svg image file. It's a bit messier to set up as you have to have Graphviz set up just so.

Snakefood3 is a python3 update of a python classic dependency graph tool Snakefood. It's almost the simplest possible program to do the task, it uses your current pythons own AST to read .py file, extracts out all declared imports into a dictionary, and uses a jinja2 template to output to STDOUT Dot language text describing the graph. That then needs to be manually visualized using Graphviz. The reason I forked the repo is I am working on getting it to output graphs in mermaid formatted .md files which can be directly visualized in both Github and modern IDEs and I can dispatch with the unnecessary complexity of Graphviz.

Both can be centered on a specific module within a dependency. Either will do the required job.