跳转到主要内容

静态分析源代码并提取Python应用程序中调用的和导出的库函数信息

项目描述

一个简单的工具,用于通过静态分析Python应用程序的源代码来收集提供的符号、库调用和属性使用情况。

请参阅[描述此工具的链接文章](https://developers.redhat.com/articles/2022/01/05/extracting-information-python-source-code)。

安装

可以使用PyPI安装Invectio,地址为PyPI

$ pip3 install invectio
$ invectio --help

使用方法

您可以将此库用作CLI工具或Python模块。

invectio whatprovides project-dir/   # To scan all Python files recursively for symbols provided.
invectio whatprovides app.py         # To perform symbols gathering on app.py file.

invectio whatuses project-dir/       # To scan all Python files recursively for symbols used from libraries.
invectio whatuses app.py             # To perform gather symbols used from libraries on app.py file.
from invectio import gather_library_calls
from invectio import gather_symbols_provided

result: dict = gather_library_usage("project-dir")
result: dict = gather_library_usage("app.py")

result: dict = gather_symbols_provided("project-dir")
result: dict = gather_symbols_provided("app.py")

限制

由于Python是一种动态编程语言,因此仅通过源代码的静态分析无法获取所有库函数/属性的用法。人们仍然可以执行“疯狂”的事情,例如

import tensorflow

getattr(tensorflow, "const" + "ant")("Hello, Invectio")

此库尽最大努力检测Python源代码中使用的所有函数/属性,但像上面显示的使用情况不能仅通过源代码的静态分析来检测。

开发

要创建开发环境,克隆invectio仓库并安装所有依赖项。

git clone https://github.com/thoth-station/invectio && cd invectio
pipenv install --dev

要从根目录的tests/目录中的单元测试执行检查,请从git仓库的根目录执行以下命令

pipenv run python3 setup.py test

项目详情


下载文件

下载适合您平台的应用程序。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

invectio-0.2.2.tar.gz (20.8 kB 查看哈希值)

上传时间 源代码

构建分发

invectio-0.2.2-py3-none-any.whl (21.3 kB 查看哈希值)

上传时间 Python 3

由以下支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly 加速