Open a-recknagel opened 10 months ago
I also just discovered this behavior in a similar search. In my case, I have a dependency on Celery and a dev dependency on Pytest. Celery has an extra for a pytest plugin that I would like to use but not include in a build for a production deployment.
I did more or less the same thing:
[tool.poetry.dependencies]
celery = {version="^5.3.6", extras=["redis", "tblib", "auth"]}
[tool.poetry.group.dev.dependencies]
celery = {version="^5.3.6", extras=["pytest"]}
My poetry.lock
was unmodified after locking this configuration. Since I'm not clear on how poetry chooses what to include in a build I'm not 100% sure if that's what I wanted, but it's probably fine 🙂
So, +1 for documenting this use-case. I'd also propose a way to declare if a specific extra belongs to a different group from the parent package. Maybe something like:
[tool.poetry.dependencies.celery]
version = "^5.3.6"
extras = [
{name="pytest", group="dev"},
"redis",
"tblib",
"auth",
]
In the end, declaring a package twice isn't that much of a pain. There's a potential for version conflict if one copies verbatim the version spec like I did (rather than using "*"
like OP) and then later changes one but not the other (in my example, going to "^6"
while the other is "^5.3.6"
). Even that would be an easy fix, but I could see it being one of those things that's easy to forget about and miss while reading the file, then spend a couple hours trying to figure out where this mysterious version conflict is coming from when it clearly says "^6"
in the file.
Issue
When looking up the docs on how to define extras, the final box says in very clear words, that you can only define the packages that you can list in a
[tool.poetry.extras]
entry within the[tool.poetry.dependencies]
/[tool.poetry.dependencies.main]
section:This is not 100% true, I can re-define dependencies as optional in a group, and if I install that group plus the extra, poetry will consider the dependency as it is defined in the group.
For example, I have an extra
snowflake
which installssnowflake-connector-python
with itspandas
extra. During development, I'd like to install itssecure-local-storage
extra as well. I can express this withAnd it will work just fine.
I expected a syntax error due to the
option=true
in a non-main group, but it resolvesThis installs
snowflake-connector-python[pandas]
This installs
snowflake-connector-python[pandas,secure-local-storage]
, note thatpandas
is not getting removedThis installs
snowflake-connector-python[pandas]
again, removing all dependencies from thesecure-local-storage
. At this point, I'd say that this works in a sane manner.If it were a bug or unintended behavior, I'd have expected that one dependency specification overwrites the other one. But since the listed extras from the dependency's definition in different groups are combined correctly, it feels like something that is safe to use. It's quite useful too, so shouldn't it be documented?