poetry pip extras 模式包配置简单说明
我们经常看到一些开源pip 包提供了类似pip install awesome[databases]
模式的安装方法,以下是一个简单说明
使用到的核心配置
核心就是extras 配置,对于不同的构建工具的配置可能不太一样,但是都是基于extras的
poetry参考配置
我使用的是编辑模式的包,实际上安装只有sharespec 以及fire,对于其他模版可以手工独立安装
[tool.poetry.dependencies]
python = "^3.11"
sharespec = { path = "../sharespec",develop = true}
first = { path = "../first",develop = true,optional = true}
second = { path = "../second",develop = true,optional = true}
fire = "^0.6.0"
[tool.poetry.extras]
plugins = ["first", "second"]
说明
extras 模式的配置还是比较方便的,类似可选扩展包,但是用好了,可以实现强大的插件化设计,以上是对于poetry模式的说明
其他工具的配置可能不太一样,具体的可以参考相关工具的文档, patroni 是基于setup 的管理里边有相关的可以参考
参考资料
https://stackoverflow.com/questions/52474931/what-is-extra-in-pypi-dependency
https://pip.pypa.io/en/stable/cli/pip_install/
https://github.com/zalando/patroni
https://github.com/zalando/patroni/blob/master/setup.py
https://patroni.readthedocs.io/en/latest/
https://packaging.python.org/en/latest/tutorials/installing-packages/
https://python-poetry.org/docs/pyproject/