Transfer dependency to --dev in poetry

Viewed 3525

If you accidentally install a dependency in poetry as a main dependency (i.e. poetry add ...), is there a way to quickly transfer it to dev dependencies (i.e. poetry add --dev ...), or do you have to uninstall it and reinstall with poetry add --dev?

2 Answers

You can move the corresponding line in the pyproject.toml from the [tool.poetry.dependencies] section to [tool.poetry.dev-dependencies] by hand and run poetry lock --no-update afterwards.

You can also poetry add -D <dep> and poetry remove <dep> in either order. Just be sure to use the same version constraint. Poetry stops/warns you if you use different constraints as they'd conflict.

Related