clay
clay

Reputation: 20390

Python Poetry specify dependency on `sentry-sdk[flask]`

I'm trying to add support for Sentry to an existing Python Flask application that uses Python Poetry for dependency management.

The Sentry docs say to run this:

pip install --upgrade 'sentry-sdk[flask]

That works. But I want to convert that into a pyproject.toml dependency entry for Python Poetry. If I try just this:

[tool.poetry.dependencies]
# <snip>
sentry-sdk = "1.5.12"

I get a SolverProblemError:

... depends on sentry-sdk (1.5.12) which doesn't match any versions, version solving failed.

If I try:

[tool.poetry.dependencies]
# <snip>
sentry-sdk[flask] = "1.5.12"

I get Invalid TOML file.

How do I convert this pip dependency to Python pyproject.toml format?

Upvotes: 3

Views: 1942

Answers (2)

Dmytro Shyshov
Dmytro Shyshov

Reputation: 41

This worked for me:

poetry add sentry-sdk --extras=flask

Upvotes: 4

decorator-factory
decorator-factory

Reputation: 3083

This is how you can specify a dependency with extras:

[tool.poetry.dependencies]
python = "^3.9"
sentry-sdk = {extras = ["flask"], version = "1.5.12"}

See the following section of the documentation: Dependency extras

You can also achieve this by running:

poetry add sentry-sdk[flask]==1.5.12

Upvotes: 4

Related Questions