CLI argument to poetry add
to add the dependency to [tool.poetry.extras]
#9925
Labels
poetry add
to add the dependency to [tool.poetry.extras]
#9925
Issue Kind
Brand new capability
Description
Add an info to the
poetry add
help that states that dependency groups aren't equivalent to groups of extras and have no parallel in pip.Add an argument to
poetry add
which requires--optional
let's say for the sake of argument-i --include-in
.Providing that argument, adds the dependency into the list of dependencies of an extra:
So doing something like
poetry add --optional -i cuda cupy
would now additionally:[tool.poetry.extras]
if it doesn't exist.cuda
if it doesn't exits.cupy
into the dependency list ofcuda
if it doesn't exist. So you end up with:Impact
How it should affect other users
poetry add
help should reduce frustration for new users of poetry which also primarily look at the help of commands and not the docs online. (Also poetry doesn't have a man page you could consult).pyproject.toml
that you could figure out afterwards how to change the config manually. (So once again, no requirement to read the docs online)[tool.poetry.extras]
would seem to be inline with the purpose of poetry which is, as far as I understand: Managing / Resolving Dependencies and Facilitating easier Packaging for Python Projects.Lastly, it's my conviction that cli tools should contain everything needed to operate them in their help section. And not require the user to leave the shell and look up the docs in a browser.
How it affected me
I've sadly spent an entire day trying to get my package to have an optional dependency. It also may be very well possible that I'm stupid and just didn't read the docs and only referred to the help of poetry in the cli.
It firstly took me some time to figure out that if you
poetry add -E some-extra package
will addsome-package[some-extra]
to your install dependencies. That's my bad for not reading the documentation closely enough. Tho maybe the formulation of the help could be improved or the word "dependency" could be highlighted?Another thing that took me for a ride were the dependency groups. I thought they were equivalent to the extras you can define for your package.
Since, when not using poetry, you have something like:
I accidentally equated the poetry dependency groups to the
project.optional-dependencies
. I was mostly looking at the output ofpoetry [build, add, install] --help
for information. I think it might be useful to put in the note that dependency groups are something unique to poetry and they have no parallel with pip / pypi.(It would be also a cool idea to have dependency groups be marked as an extra for pip but I think that diverges too much from the established ux that poetry has)
After figuring out that dependency groups and the
-E
flag forpoetry add
weren't the right way to go, I finally left my terminal and looked at the docs to finally learn that you can only add extras to your package the following way:poetry add --optional some-package
pyproject.toml
to contain the following:I had the preconceived notion that everything regarding configs with poetry is only handled through the shell. I was not expecting to manually edit config files. Now this can be argued as an me issue and being an new poetry user.
Workarounds
poetry add --optional some-package
pyproject.toml
to contain the following:The somewhat confusing part is having to edit the
pyproject.toml
yourself.The text was updated successfully, but these errors were encountered: