poetry icon indicating copy to clipboard operation
poetry copied to clipboard

Add an option --all-optional-groups to poetry install

Open PeterBosch2 opened this issue 1 year ago • 1 comments

I think an option poetry install --all-optional-groups is needed.

What is the use-case for this?

When you create a project with optional dependency groups, as detailed in the poetry documentation for managing-dependencies, you need to know all optional groups when you want to do a full installation of the project.

[tool.poetry.group.tests]
optional = true

[tool.poetry.group.tests.dependencies]
pytest = "^8.0.0"

Example where an poetry install --all-optional-groups --all-extras would be nice is a devcontainer.json setup:

{
	"name": "Python & Poetry",
	"dockerComposeFile": [
		"../../docker-compose.yml",
		"./docker-compose.yml"
	],
	"service": "demo",
	"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
	"postCreateCommand": "poetry install --all-extras --with=dev,test",

As you see, I need to list all optional groups one-by-one. This makes it harder (impossible) for a team-wide generic setup across multiple projects.

Just some random thoughts...

A solution/workarround would be to not use the optional setting for groups, i.e., have all groups mandatory and use poetry install --only=main when it is important to only have the main group installed. But then, what is the point of tagging groups as optional?

Also to mention, the installation concept of "extras" has this --all-extras option. Wouldn't it even make more sense to have groups by default optional, as it is the case for extras?

Misc...

I saw this other feature-request #8244, which addresses another "optional" concept, which is that of individual dependencies and not the groups.

PeterBosch2 avatar Feb 15 '24 14:02 PeterBosch2

Okay ... after digging a bit more into the concept of dependency groups, I had the following finding: There is a fundamental difference in the way how poetry looks at dependency groups and extras. Dependency groups are not-optional by default and extras are optional by default.

Sorry for the confusion, my bad!

So, the way to to use dependency groups, e.g., in a CI pipeline job, is to go via the --only option. At least when you just want the absolute necessary minimum of dependencies being installed.

For static code analysis:

poetry install --only static_code_analysis

For local tests:

poetry install --only main, local_tests

While, when you are in your develop environment, you simply install everything by default:

poetry install

So, to iterate on my original statement: Now, the "optional = true" setting for dependency groups is not used in this configuration, at all. Which is good, as it reduces the amount of lines in pyproject.toml. Probably, this optional = true is good for some esoteric development tools that only a few developers install manually, when they know what they are doing. I will probably not use it, at least not for now.

PeterBosch2 avatar Feb 18 '24 06:02 PeterBosch2

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

github-actions[bot] avatar Mar 31 '24 00:03 github-actions[bot]