静态分析源并提取有关 Python 应用程序中调用和导出的库函数的信息
项目描述
基于对 Python 应用程序源的静态分析,收集提供的符号或库调用和属性使用的简单工具。
请参阅 [描述此工具的链接文章]( https://developers.redhat.com/articles/2022/01/05/extracting-information-python-source-code )。
安装
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 repo 的根目录发出以下命令:
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
查看哈希)