dev-dependencies that are also extras
See original GitHub issueI’ve got a somewhat weird requirement:
Project A provides a bunch of pytest fixtures, and uses pytest itself for testing. I want to provide an extra on the resulting distributable that is called “testing”.
So I created the following:
[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}
pytest = {version = "^3.5", optional = true}
[tool.poetry.dev-dependencies]
pytest = "^3.5"
pytest-cov = "^2.5"
coverage = "^4.5"
[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]
This will work correctly, however the dependency on pytest
is specified twice. Once under tool.poetry.dependencies
and another time under tool.poetry.dev-dependencies
. What I would like to do is make sure that the same thing isn’t listed twice, so I tried the following:
[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}
[tool.poetry.dev-dependencies]
pytest = "^3.5"
pytest-cov = "^2.5"
coverage = "^4.5"
[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]
Hoping that the testing
extra would pick up pytest
from dev-dependencies
. However this is not the case.
So I moved pytest
back up, and made it optional
:
[tool.poetry.dependencies]
python = "*"
pyramid = "^1.9"
sqlalchemy = {version = "^1.2", extras = ["postgresql"]}
psycopg2 = {version = "^2.7", optional = true}
pytest = {version = "^3.5", optional = true}
[tool.poetry.dev-dependencies]
pytest-cov = "^2.5"
coverage = "^4.5"
[tool.poetry.extras]
testing = ["pytest"]
postgresql = ["psycopg2"]
Now it is correctly picked up, but there is no way to specify that when installing dev-dependencies
that the extra testing
should be automatically installed too, since that now contains the pytest
dependency.
Trying:
mypackage = { version = "*", extras = ["testing"]}
Did not work since it could not find mypackage
, and I am sure that if it could find it, it would likely download it from pypi which is not intended.
Is there a way to refer to self
somehow? Or would it be possible to add a dependency in one place (define its version and extras/requirements) without redefining it in dev-dependencies
?
The goal ultimately is that a secondary package would have the following pyproject.toml
:
[tool.poetry]
name = "B-package"
version = "0.2.0"
description = ""
authors = ["Your Name <you@example.com>"]
[tool.poetry.dependencies]
python = "*"
mypackage = {version = "^0.1"}
[tool.poetry.dev-dependencies]
mypackage = {version = "*", extras = ["testing"]}
And only if you are developing would it install mypackage[testing]
but for production it would install mypackage
. Using the version constraint from tool.poetry.dependencies
vs the constraint specified in tool.poetry.dev-dependencies
.
This is related to secondary issue: https://github.com/sdispater/poetry/issues/128
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:7 (3 by maintainers)
Top GitHub Comments
I have similar use-cases for ReadTheDocs automatic builds: https://github.com/rtfd/readthedocs.org/issues/4912#issuecomment-457219385
As @thejohnfreeman wrote, this will be possible with dependency groups which are planned for poetry 1.2. I’ll close this one in favor of #1644.