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

Install removes dependencies of non-installed extras #6229

Closed
chimaerase opened this issue Aug 24, 2022 · 8 comments · Fixed by #6432
Closed

Install removes dependencies of non-installed extras #6229

chimaerase opened this issue Aug 24, 2022 · 8 comments · Fixed by #6432
Labels
kind/bug Something isn't working as expected

Comments

@chimaerase
Copy link
Contributor

chimaerase commented Aug 24, 2022

  • [x ] I am on the latest Poetry version.
  • [x ] I have searched the issues of this repo and believe that this is not a duplicate.
  • [ x] If an exception occurs when executing a command, I executed it again in debug mode (-vvv option).
  • Debian bullseye:
  • poetry 1.2.0rc1:
  • Link of a Gist with the contents of your pyproject.toml file: pyproject.toml

Issue

I've been testing 1.2.0rc1 and it seems poetry is removing dependencies of non-installed extras. My understanding of #4336 and #4242 is that poetry should only ever remove packages during an install if they're superseded by the locked versions that need to be installed, or if the --sync option is used. A workaround is to rewrite the extras as optional groups, which seems to solve the problem. If nothing else, perhaps some documentation updates are needed to mark extras as deprecated?

In my pyproject.toml, setuptools is a derived dependency of gunicorn (an optional package grouped under the web extra).

Running poetry install --no-root -vvv removes setuptools:

#8 2.645 + poetry lock --check
#8 3.115 poetry.lock is consistent with pyproject.toml.
#8 3.159 + poetry install --no-root -vvv
#8 3.515 Using virtualenv: /code/.venv
#8 3.555 Project environment contains an empty path in sys_path, ignoring.
#8 3.591 Installing dependencies from lock file
#8 3.635 
#8 3.635 Finding the necessary packages for the current system
#8 3.647 
#8 3.647 Package operations: 0 installs, 0 updates, 1 removal, 2 skipped
#8 3.647 
#8 3.648   • Removing setuptools (65.3.0)
#8 4.726   • Updating setuptools (63.2.0 -> 65.3.0): Skipped for the following reason: Not required
#8 4.727   • Installing gunicorn (20.1.0): Skipped for the following reason: Not required
#8 DONE 4.9s

I also tested re-writing the extras as groups instead, and did not get the same result. Making these changes fixed the problem:

#gunicorn = {optional = true, version = "*"}
#
#[tool.poetry.extras]
#web = [
#    "gunicorn",
#]
[tool.poetry.group.web]
optional=true

[tool.poetry.group.web.dependencies]
gunicorn = "*"
@chimaerase chimaerase added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Aug 24, 2022
@dimbleby
Copy link
Contributor

I don't see that #4336 ever had anything to say about extras, and #4242 is a different thing altogether (relating to poetry 1.1's handling of poetry 1.2 lockfiles).

Described behaviour seems correct to me: you've asked to install a package without extras, and poetry has made that happen.

@chimaerase
Copy link
Contributor Author

IMO poetry's behavior with extras should parallel what's happening with --without dev flag as documented in #4336. From the PR description: "Any locked packages will be kept in the environment regardless of what is asked via the install command unless the --sync option is specified...Overall, this should be less surprising for end users makes working with dependency groups easier."

Also, IMO whether pyproject.toml is written using an optional group or using extras, the end result should be consistent. I think this ticket shows it isn't right now.

@dimbleby
Copy link
Contributor

groups and extras are absolutely not interchangeable and you should not expect them to give identical results - them not being "consistent" here is not an issue.

@chimaerase
Copy link
Contributor Author

Ok, thanks for your reply.

I submit that the distinction between when to use extras and when to use optional groups isn't clear in the documentation yet (especially to me, mostly a 1.1 user, who only had the option to use extras in that version). I think this important distinction re: whether dependencies get removed when the extra / optional group isn't selected is important to end users and should be clearly / prominently documented.

@dimbleby
Copy link
Contributor

I see that #6230 has just gone in hopefully helping to clarify the distinction, I expect further MRs improving the docs would be welcome.

@chimaerase
Copy link
Contributor Author

Thanks, that is a good start!

Unfortunately, I'm asking for documentation largely because I'm still unclear on the motivations for making optional groups/extras behave differently when not selected for install. I don't think clarifying that reasoning is something I can contribute to.

@dimbleby
Copy link
Contributor

duplicate #5895

Copy link

github-actions bot commented Mar 1, 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 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Something isn't working as expected
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants