在python应用程序中静态分析源并提取有关调用库函数的信息
invectio的Python项目详细描述
一个简单的基于静态的库调用和属性使用收集工具 分析python应用程序的源代码。
用法
您可以将此库用作cli工具或python模块:
invectio project-dir/ # To scan all Python files recursively.
invectio app.py # To perform usage gathering just on app.py file.
frominvectioimportgather_library_calls# To scan all Python files recursively.result:dict=gather_library_usage("project-dir")# To perform usage gathering just on app.py file.result:dict=gather_library_usage("app.py")
限制
由于python是一种动态编程语言,因此不可能获得所有 只需执行 消息来源。一个人仍然可以做一些“疯狂”的事情,比如:
importtensorflowgetattr(tensorflow,"const"+"ant")("Hello, Invectio")
这个库尽力检测内部使用的所有函数/属性 python源代码,但是上面所示的用法不能由static 分析源代码。
开发
要创建开发环境,请克隆invectio repo并安装所有依赖项:
git clone https:://github.com/thoth-station/invectio && cd invectio
pipenv install --dev
要对tests/目录中的单元测试执行检查, 从git repo的根目录下发出以下命令:
pipenv run python3 setup.py test