代码依赖和调用关系分析工具
source-hunter的Python项目详细描述
资料来源猎人
分析源代码的依赖关系和调用关系的方便工具。
在大型项目上进行编码时,有时会面临改变基础数据模型的尴尬局面 或者接口可能有机会破坏很多东西。 有一些类似pydeps的工具可以让您了解其他模块 当前模块依赖于(依赖关系图),但如果更改 模块(调用图)。source hunter的目标是同时提供调用和依赖关系图。
安装
先决条件
Graphviz
需要用于渲染- 名为
graphviz
的python包装器
如何安装Graphviz
# On Ubuntu/Debian
sudo apt install graphviz
# On mac
brew install graphviz
# On Centos/Fedora
sudo yum install graphviz
如何安装graphviz the python包
如果使用pip安装source_hunter,则不需要手动安装此软件包。否则,您可以安装
graphviz
通过pip install graphviz
使用pip安装:
pip install source_hunter
从源代码安装:
git clone https://github.com/pyeprog/source_hunter.git
cd source_hunter
python setup.py install
用法
# for help hunt -h # basic usage hunt [project_root_path][target_module_file][function_or_class]# example# search Usage of `YourModel` of `target_model.py` in current path# and save the output pdf file at `~/saving/dir/saving_file_name.pdf`# while ignoring all files with `test`, `pb2` or `migration` in its names.cd ~/example_project hunt . ./model/target_model.py YourModel \ --path ~/saving/dir \ --name saving_file_name \ --ignore test --ignore pb2 --ignore migration # output only to stdout hunt . ./model/target_model.py YourModel --stdout
输出
cd flask_reddit
hunt . ./flask_reddit/users/models.py User
hunt . ./flask_reddit/users/models.py User --stdout
cd flask_reddit
hunt . ./flask_reddit/users/models.py User --stdout
限制
- 只支持python3项目(不久将支持更多语言)
- 不支持
import a as b
或from a import b as c
更改日志
- 第0.40版:
- 添加对依赖关系图的支持
- 重构python解析器
- 第0.36版:
- 添加记录器
- 重构分析器
- 第0.35版:
- 添加对PNG和PDF输出格式的支持
- 修正标准格式
- V0.34版本:
- 添加对python项目相对导入解析的支持
- 第0.33版:
- 为pdf输出添加python解析器和graphviz