检查Python包依赖关系
项目描述
Dependente: 检查Python包依赖关系
是Fatiando a Terra项目的一部分
关于
Dependente是一个小型的命令行程序,用于从Python项目文件(pyproject.toml
和setup.cfg
)中提取依赖项,并将它们转换为与pip
和conda
一起使用的requirements.txt
类型文件。
这样做的主要原因是在持续集成(CI)上控制和自定义测试环境,同时避免在多个地方重复依赖项列表。
本项目受到了MetPy项目的一些GitHub Actions配置的启发。
安装
Dependente可在PyPI和conda-forge上获得
python -m pip install dependente
conda install dependente -c conda-forge
使用
在这些示例中,我们将从 Pooch 解析依赖关系。
解析 setup.cfg
中的安装(运行时)依赖关系
$ dependente > requirements.txt
Extracting dependencies: install
Parsing setup.cfg
- 3 dependencies found
Printing 3 dependencies to standard output
Done!
$ cat requirements.txt
# Install (run-time) dependencies from setup.cfg
appdirs>=1.3.0
packaging>=20.0
requests>=2.19.0
同时读取 pyproject.toml
中的构建依赖关系和 setup.cfg
中的额外依赖关系
$ dependente --source install,build,extras > requirements-all.txt
Extracting dependencies: install,build,extras
Parsing setup.cfg
- 6 dependencies found
Parsing pyproject.toml
- 3 dependencies found
Printing 9 dependencies to standard output
Done!
$ cat requirements-all.txt
# Extra (optional) dependencies from setup.cfg
# extra: progress
tqdm>=4.41.0,<5.0.0
# extra: sftp
paramiko>=2.7.0
# extra: xxhash
xxhash>=1.4.3
# Install (run-time) dependencies from setup.cfg
appdirs>=1.3.0
packaging>=20.0
requests>=2.19.0
# Build dependencies from pyproject.toml
setuptools>=45
wheel
setuptools_scm[toml]>=6.2
将依赖关系固定到其最老的支持版本(在 CI 中测试时很有用)
$ dependente --source install,extras --oldest > requirements-oldest.txt
Extracting dependencies: install,extras
Parsing setup.cfg
- 6 dependencies found
Pinning dependencies to their oldest versions
Printing 6 dependencies to standard output
Done!
$ cat requirements-oldest.txt
# Extra (optional) dependencies from setup.cfg
# extra: progress
tqdm==4.41.0
# extra: sftp
paramiko==2.7.0
# extra: xxhash
xxhash==1.4.3
# Install (run-time) dependencies from setup.cfg
appdirs==1.3.0
packaging==20.0
requests==2.19.0
查看完整的选项列表
$ dependente --help
Usage: dependente [OPTIONS]
Dependente: Inspect Python package dependencies
Reads from the configuration files in the current directory and outputs to
stdout a list of dependencies into a format accepted by pip.
Supported formats:
* pyproject.toml (only build-system > requires)
* setup.cfg (install_requires and options.extras_require)
Options:
-s, --source TEXT Which sources of dependency information to
extract. Can be any combination of
'install,extras,build'. [default: install]
-o, --oldest If enabled, will pin dependencies to the oldest
accepted version. [default: False]
-v, --verbose / -q, --quiet Print information during execution / Don't
print [default: verbose]
--version Show the version and exit.
-h, --help Show this message and exit.
局限性
当前的实现是一个概念验证,存在一些局限性
- 输入文件必须在当前工作目录中。
- 同时读取所有额外依赖关系(无法区分不同的
option.extras_requires
字段)。 - 仅支持从
setup.cfg
和pyproject.toml
读取(仅限构建依赖关系)。
当然,如果足够感兴趣,所有这些问题都可以解决。欢迎提出问题和 PR!
依赖关系
我们使用以下依赖项(具体版本约束见 setup.cfg
)
联系我们
有关如何联系我们,请访问 fatiando.org/contact
贡献
行为准则
请注意,该项目以 行为准则 发布。通过参与此项目,您同意遵守其条款。
贡献指南
请阅读我们的 贡献指南 了解如何提供帮助和反馈。
许可
Dependente 是免费的开源软件,根据 MIT 许可证 分发。
项目详情
下载文件
为您的平台下载文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源代码分发
dependente-0.3.0.tar.gz (14.6 kB 查看哈希值)
构建分发
dependente-0.3.0-py3-none-any.whl (14.5 kB 查看哈希值)