如何在 pyproject.toml 中指定 "extra" / 括号依赖项?
How do I specify "extra" / bracket dependencies in a pyproject.toml?
我正在开发一个项目,该项目使用 Poetry and a pyproject.toml file to manage dependencies. The documentation for one of the libraries I need suggests pip 安装指定其依赖项,其中一个依赖项具有“额外”选项,如下所示:
pip install google-cloud-bigquery[opentelemetry]
我应该如何在pyproject.toml
文件中反映这个要求?目前,有几行是这样的:
[tool.poetry.dependencies]
python = "3.7.10"
apache-beam = "2.31.0"
dynaconf = "3.1.4"
google-cloud-bigquery = "2.20.0"
将最后一行更改为
google-cloud-bigquery[opentelemetry] = ">=2.20.0"
产量
Invalid TOML file /home/jupyter/vertex-monitoring/pyproject.toml: Unexpected character: 'o' at line 17 col 22
其他似乎未正确解析的变体:
google-cloud-bigquery["opentelemetry"] = "2.20.0"
有 Whosebug which look related, as well as several different PEP docs,但我的搜索很复杂,因为我不确定这些是“选项”还是“额外”或其他东西。
虽然语法看起来有点奇怪,但从某些版本开始,TOML 支持引用键来转义特殊字符 "Less restrictive bare keys"
https://github.com/toml-lang/toml/pull/283
"google-cloud-bigquery[opentelemetry]"
此语法可能适合您!
[tool.poetry.dependencies]
python = "3.7.10"
apache-beam = "2.31.0"
dynaconf = "3.1.4"
"google-cloud-bigquery[opentelemetry]" = ">=2.20.0"
TOML 可能期望 ^
>=
,尽管 docs
中的语法不明确
可以通过poetry add "google-cloud-bigquery[opentelemetry]"
添加。这将导致:
[tool.poetry.dependencies]
...
google-cloud-bigquery = {extras = ["opentelemetry"], version = "^2.34.2"}
我正在开发一个项目,该项目使用 Poetry and a pyproject.toml file to manage dependencies. The documentation for one of the libraries I need suggests pip 安装指定其依赖项,其中一个依赖项具有“额外”选项,如下所示:
pip install google-cloud-bigquery[opentelemetry]
我应该如何在pyproject.toml
文件中反映这个要求?目前,有几行是这样的:
[tool.poetry.dependencies]
python = "3.7.10"
apache-beam = "2.31.0"
dynaconf = "3.1.4"
google-cloud-bigquery = "2.20.0"
将最后一行更改为
google-cloud-bigquery[opentelemetry] = ">=2.20.0"
产量
Invalid TOML file /home/jupyter/vertex-monitoring/pyproject.toml: Unexpected character: 'o' at line 17 col 22
其他似乎未正确解析的变体:
google-cloud-bigquery["opentelemetry"] = "2.20.0"
有
虽然语法看起来有点奇怪,但从某些版本开始,TOML 支持引用键来转义特殊字符 "Less restrictive bare keys"
https://github.com/toml-lang/toml/pull/283
"google-cloud-bigquery[opentelemetry]"
此语法可能适合您!
[tool.poetry.dependencies]
python = "3.7.10"
apache-beam = "2.31.0"
dynaconf = "3.1.4"
"google-cloud-bigquery[opentelemetry]" = ">=2.20.0"
TOML 可能期望 ^
>=
,尽管 docs
可以通过poetry add "google-cloud-bigquery[opentelemetry]"
添加。这将导致:
[tool.poetry.dependencies]
...
google-cloud-bigquery = {extras = ["opentelemetry"], version = "^2.34.2"}