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

Using --all-extras does not install from project.optional-dependencies #7556

Closed
4 tasks done
mbrancato opened this issue Feb 24, 2023 · 6 comments · Fixed by #7563
Closed
4 tasks done

Using --all-extras does not install from project.optional-dependencies #7556

mbrancato opened this issue Feb 24, 2023 · 6 comments · Fixed by #7563
Labels
kind/bug Something isn't working as expected status/triage This issue needs to be triaged

Comments

@mbrancato
Copy link

mbrancato commented Feb 24, 2023

  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

The documentation indicates that poetry install --all-extras will install all "optional dependencies". Those in both the main group marked as optional, and the dev group. I've noticed that other tools with optional dependencies are not installed when using --all-extras.

Example in attached gist, summary:

  • FastAPI is a direct dependency
  • FastAPI depends on starlette
  • starlette uses pyproject.toml and has httpx as an optional dependency
  • FastAPI / starlette has a TestClient class
  • The TestClient class uses httpx
  • httpx is defined in pyproject.toml
  • Using the TestClient fails as httpx is not installed.
  • Workaround is that httpx must be added as a direct dependency
@mbrancato mbrancato added kind/bug Something isn't working as expected status/triage This issue needs to be triaged labels Feb 24, 2023
@dimbleby
Copy link
Contributor

dimbleby commented Feb 24, 2023

You have misunderstood: --all-extras installs... all extras. The pyproject.toml that you have provided defines no extras.

I don't immediately see where the docs imply anything other than this: but if they are unclear then I expect a merge request putting this right would be welcome.

@evanrittenhouse
Copy link
Contributor

I think the confusion may stem from

Poetry supports extras to allow expression of:

  • optional dependencies, which enhance a package, but are not required; and

But the issue is reporting that starlette has httpx in its project.optional-dependencies, and running poetry install --all-extras doesn't actually install httpx. While the attached pyproject.toml doesn't have any optional dependencies, starlette does. The user expects all optional-dependencies to be installed in all subpackages when running --all-extras - @mbrancato, please correct me if I'm wrong.

FWIW, after reading the docs I'd also expect that behavior. I'm not sure if it's intended or not, but a documentation update/bugfix may be in order.

@mbrancato
Copy link
Author

yes @evanrittenhouse - exactly that. I did have to dig into the dependency of starlette to identify that httpx was an "optional dependency". And that is where the documentation twice refers to extras as including "optional dependencies".

image

A little ways down in the "extras" section, it does say:

Any extras you don’t specify will be removed. Note this behavior is different from optional dependency groups not selected for install, e.g. those not specified via install --with.

The project.optional-dependencies in the pyproject.toml defines that the keys provide project extras.

So I would think one of the following commands would work, but they do not.

poetry install --with full
poetry install --extras full

So I think at a minimum, the term "optional dependencies" needs to be removed from the "extras" section of the documentation.

I am able to solve my issue by doing the following:

[tool.poetry.group.dev.dependencies]
fastapi = {version = "^0.92.0", extras = ["all"]}

Basically, the extras must be defined in the direct dependency, and that dependency must include things needed for its sub-dependency.

@evanrittenhouse
Copy link
Contributor

evanrittenhouse commented Feb 25, 2023

@dimbleby if we want --with full or --extras full to include subdependency extras, I can try to implement that

@dimbleby
Copy link
Contributor

No code change should be needed, this all is working as intended. --extras foo is to install the foo extra defined by the current project, --all-extras is to install all extras defined by the current project. If you want to install extras defined by dependencies then express that in the dependency, per #7556 (comment).

Again, docs improvements are encouraged

Copy link

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 Feb 29, 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 status/triage This issue needs to be triaged
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants