通过分析python包的导入来探索其依赖关系。
pkgdeps的Python项目详细描述
通过分析python包的导入来探索其依赖关系。
这可能有助于:
- 查看包中的模块如何相互依赖
- 查看依赖哪些内置库
- 第三方依赖关系分析
- 等
示例
探索此项目的依赖关系:
$ pkgdeps /path/to/pkgdeps pkgdeps - argparse.ArgumentParser - ast - collections.defaultdict - functools.reduce - os - os.path - sys
限制
- 仅针对Python3包使用Python3进行测试。
- 不处理条件导入;检查所有条件分支。
- 输出导入的模块成员:from os.path import join创建 依赖于os.path.join,但我们可能只想要os.path,例如。 tsort输出。但是,内部依赖关系被粗化为模块 水平。
安装
$ pip install pkgdeps
用法
有多种选项可用于筛选和格式化输出:
$ pkgdeps -h usage: pkgdeps [-h] [-n <num>] [-m <num>] [-e <type> | -o <type>] [-f <format>] </path/to/package> Explore dependencies of a package by parsing its imports. positional arguments: </path/to/package> path to package root optional arguments: -h, --help show this help message and exit -n <num>, --package-module-name-segments <num> truncate module names of inspected package to given number of segments (and consolidate imports) -m <num>, --dependency-module-name-segments <num> truncate module names of dependencies to given number of segments (and deduplicate) -e <type>, --exclude <type> exclude various kinds of dependencies from output (builtin, 3rd-party, internal) -o <type>, --only <type> include only dependencies of the given type (builtin, 3rd-party, internal) -f <format>, --format <format> graph output format (tree, tsort)