Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[>=1.2] Assign project dependencies to 'root' group #5197

Closed
2 tasks done
Cielquan opened this issue Feb 13, 2022 · 7 comments
Closed
2 tasks done

[>=1.2] Assign project dependencies to 'root' group #5197

Cielquan opened this issue Feb 13, 2022 · 7 comments
Labels
kind/feature Feature requests/implementations

Comments

@Cielquan
Copy link
Contributor

  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have searched the documentation and believe that my question is not covered.

Feature Request

I like the new dependency groups coming with 1.2. In a project, I use those groups to group the dependencies into groups like testing, coverage, lint, etc. Most of the groups are optional=false so they are installed with poetry install for the dev venv. But when I want to e.g. test my code with tox I have to list all the groups in poetry install --without <all groups except testing> so I only get the package itself and the testing dependencies. There is a flag for excluding the package --no-root but none to include it.

My proposal is to assign all dependencies in the [tool.poetry.dependencies] dict to the root group. Then one could run poetry install --only root,testing for example.

--no-root and --without root would do the same then.

Proposal extended

One could also change [tool.poetry.dependencies] to [tool.poetry.group.root.dependencies] like [tool.poetry.dev-dependencies] was changed to [tool.poetry.group.dev.dependencies]. But [tool.poetry.group.root]optional would always be true.

Alternative

An alternative would be to add a --with-root flag, which would be the opposite of --no-root. It would only do something if the --only option is also set, because the package is installed by default otherwise.

@Cielquan Cielquan added kind/feature Feature requests/implementations status/triage This issue needs to be triaged labels Feb 13, 2022
@finswimmer
Copy link
Member

Hello @Cielquan,

I guess you are looking for --default?

--default           Only install the default dependencies.

"Default dependencies" are those listed under [tool.poetry.dependencies].

One can than combine --default with --only. At the moment this will not install the package itself, see #4361.

fin swimmer

@finswimmer finswimmer added the status/waiting-on-response Waiting on response from author label Feb 28, 2022
@Cielquan
Copy link
Contributor Author

Cielquan commented Mar 3, 2022

If this behavior stays like it is now, I think this will serve me well.
But if the mentioned PR is merged it would re-arise this issue.

@finswimmer
Copy link
Member

But if the mentioned PR is merged it would re-arise this issue.

Can you elaborate a bit more on that?

@Cielquan
Copy link
Contributor Author

Cielquan commented Mar 5, 2022

The project, in which the issue arose and brought me to write this issue, was turned back to use poetry 1.1 + extras before your first reply.
So I have to think back into the prior situation as I still think my proposal in its base was valid. But maybe my last answer was incorrect. Let's see below.


What I wanted

  1. The project is a closed source monorepo. And like I mentioned in the OP I wanted to reduce the length of the install commands (in my tox configs).

  2. I wanted to run poetry install to create the dev venv. This dev venv should include the package itself, its dependencies and some groups with optional=false. Easy to accomplish and no problem here.

  3. For the testing tox env I only want the package, its dependencies and the testing group installed. And here lies the issue.

The issue of 3)

To achieve this install set for "testing" in a single command I have to run poetry install --without <all optional=false groups except testing>. Because if I add --only testing I only get the testing group without the package and its dependencies.

Quote from the docs:

Installation of your project’s package is also skipped when the --only option is used.

I would like to have this command sometimes more explicit then implicit.

What I mean is the following. Imagine we have a poetry config with a bunch of optional and non-optional groups, like in my actual case. When I now add a new non-optional group non_op I have to add this group the array of non-optional groups to exclude from the install like mentioned above for the "testing" tox env. And this for all tox env install commands.

If I on the other hand could e.g. just run poetry install --with-root --only testing, the command is explicit enough for the future no matter the addition of new groups.

The PR and my answer

I read your initial answer and the PR including its comments. But I think I did not think about this correctly and my answer was wrong. I think the current state would be not sufficient because if I run poetry install --default --only testing the package itself would be missing.
So it would be the exact opposite of what I wrote before: Your PR would fix the issue and make the command usable.


Further thought

For the following I did not search the issues. But coming from the thought-process writing this answer the following came to my mind. This is probably a topic for another discussion.

I think a more granular control on what to install and what not would be good. So we can express our installation desire for all areas.:

  • package
  • package dependencies
  • groups
  • extras

Package

We have --no-root which stops the installation of the package itself. When we use --only we implicitly set the flag and have no way to explicitly re-enable the package installation. We are missing a --with-root flag.

Package dependencies

We can install the package dependencies with --default, but an explicit no for them does not exist. We can get the result with the --only option but if we want to install all non-optional groups except the package dependencies we would need to name them all instead of simple set --no-default.

Groups

Here the foundation of --only, --with and --without works fine I guess.

Extras

Well those are optional my definition so the --extras option is fine.

Conclusion

  1. I think the addition of a flag to re-enable the package installation would be good.

  2. I think a way to turn the package dependencies explicitly off would also be nice. I think the easiest way to achieve this would be to assign the package dependencies to a non-optional group like with the dev group. This way one could profit from the currently implemented --only, --with and --without options and would reduce the overhead of CLI options. This is basically this Feature Request. If this group is called root, default or something else is not really important.

If we would have those two things I think we could (relative) simply create a call to poetry install which will fit our needs, whatever it may be.

@finswimmer
Copy link
Member

Hello @Cielquan,

dependency group handling was improved in #5338. Could you please test with the current version in master if this matches your expectations?

fin swimmer

@Cielquan
Copy link
Contributor Author

Cielquan commented May 2, 2022

I installed from master and tested with: poetry install --dry-run --only default,testing.

This installed the default dependencies, the testing group and the package itself. Everything I want it to do. 👍🏾

@Cielquan Cielquan closed this as completed May 2, 2022
@mkniewallner mkniewallner removed status/triage This issue needs to be triaged status/waiting-on-response Waiting on response from author labels Jun 11, 2022
Copy link

github-actions bot commented Mar 2, 2024

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 github-actions bot locked as resolved and limited conversation to collaborators Mar 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/feature Feature requests/implementations
Projects
None yet
Development

No branches or pull requests

3 participants