poetry extras 以及group 模式简单说明

我以前简单介绍过poetry 的extras,此模式实际上是可以兼容pip 的,这样我们安装的包就可以通过pip install awesome[databases] 进行处理,group 模式实际上属于poetry 工具自己的特性,方便基于分组模式的依赖管理

poetry extras 参考配置

  • crewai 项目的配置
[tool.poetry.dependencies]
python = ">=3.10,<=3.13"
pydantic = "^2.4.2"
langchain = ">0.2,<=0.3"
openai = "^1.13.3"
opentelemetry-api = "^1.22.0"
opentelemetry-sdk = "^1.22.0"
opentelemetry-exporter-otlp-proto-http = "^1.22.0"
instructor = "1.3.3"
regex = "^2023.12.25"
# 此处是核心,optional 是可选的
crewai-tools = { version = "^0.4.26", optional = true }
click = "^8.1.7"
python-dotenv = "^1.0.0"
appdirs = "^1.4.4"
jsonref = "^1.1.0"
# 此处是核心,optional 是可选的
agentops = { version = "^0.3.0", optional = true }
embedchain = "^0.1.114"
json-repair = "^0.25.2"
# 通过 extras 进行特定依赖的分组
[tool.poetry.extras]
tools = ["crewai-tools"]
agentops = ["agentops"]
  • 安装
poetry install --extras "tools agentops"
poetry install -E tools -E agentops
poetry install --all-extras

poetry group 模式

  • chainlit 项目参考
[tool.poetry.group.custom-data]
optional = true
 
[tool.poetry.group.custom-data.dependencies]
asyncpg = "^0.29.0"
SQLAlchemy = "^2.0.28"
boto3 = "^1.34.73"
azure-identity = "^1.14.1"
azure-storage-file-datalake = "^12.14.0"
  • 安装
poetry install --with custom-data

说明

如果直接选择的python 构建工具很明确而且也很一致,基于特定工具的group 是不错的选择,但是如果是希望开发的python包可以兼容pip 的安装模式,推荐还是基于extras的机制,

参考资料

https://python-poetry.org/docs/pyproject#extras
https://python-poetry.org/docs/managing-dependencies/

posted on 2024-08-31 07:30  荣锋亮  阅读(33)  评论(0编辑  收藏  举报

导航