SuperAPI AI 工具集

dependency-analyzer

编程与开发

查看项目

更新于 10-15 21:10

技能介绍

用途:分析 Python 文件的 import 语句与项目依赖关系,帮助理解项目结构、清理无用导入并生成依赖清单。

主要能力:提取文件中的导入;可视化导入关系(依赖图);检测未使用导入;自动生成 requirements.txt;区分标准库、第三方包与本地模块;检测循环导入。

使用方式:可作为库调用,例如 from dependency_analyzer import DependencyAnalyzer,然后 analyzer.analyze_file("main.py") 或 analyzer.analyze_project("./src");也可用命令行,如 python dependency_analyzer.py --file main.py、python dependency_analyzer.py --dir ./src --requirements --output requirements.txt、--unused、--graph、--json。API 提供 analyze_file、analyze_project、find_unused_imports、find_circular_imports、generate_requirements、save_requirements、is_stdlib、is_local 等方法。输出为 JSON 结构,包含 imports、from_imports、stdlib、third_party、local、by_file 等字段。

适用场景:梳理 Python 项目依赖、生成 requirements.txt、排查未使用导入与循环依赖。

限制:资料未提供安装方式、版本要求、性能与准确率说明;仅基于 Python 标准库 ast 模块,无外部依赖。