python-poetry / poetry

Python packaging and dependency management made easy
https://python-poetry.org
MIT License
31.74k stars 2.27k forks source link

Packages included in an Extra #8322

Open BeRT2me opened 1 year ago

BeRT2me commented 1 year ago

[tool.poetry.extras] extra = ["package"]

- [x] I am on the [latest](https://github.com/python-poetry/poetry/releases/latest) stable Poetry version, installed using a recommended method.
- [x] I have searched the [issues](https://github.com/python-poetry/poetry/issues) of this repo and believe that this is not a duplicate.
- [x] I have consulted the [FAQ](https://python-poetry.org/docs/faq/) and [blog](https://python-poetry.org/blog/) for any relevant entries or release notes.
- [x] If an exception occurs when executing a command, I executed it again in debug mode (`-vvv` option) and have included the output below.

## Issue
If I run `poetry install`,  `package` installs as expected. 

However,
- If I add this project to another project `poetry add <path_to_project>`, then `package` *doesn't* install. (It should!)
- If I publish the project and then do `pip install my_project`, then `package` *doesn't* install. (It should!)
  - But if I do `pip install my_project[extra]` then `package` does install. 

## Summary:

package = {version = "^1.4.49", optional = false}

Should not have the same result as:

package = {version = "^1.4.49", optional = true}


When it comes to installing a project externally. Just because it's included in one of the extras... especially when it installs as expected within a project. 
dimbleby commented 1 year ago

duplicate #3718

that one was closed as a duplicate of #2357 which I think is not quite right: they're more like duals than duplicates, two sides of the same coin

still it likely makes sense to note as much in a single place - ie #2357 - and track this just once. Both should simply be rejected as misconfiguration

BeRT2me commented 1 year ago

My real reason for discovering this was troubleshooting unexpected results when doing something like:

[tool.poetry.dependencies]
sqlalchemy = [
  {version = "^1.4.48", optional = false},
  {version = "^1.4.48", extras = ["asyncio"], optional = true},
]

[tool.poetry.extras]
async = ["sqlalchemy"]

Where I wanted particular extras - only when installing extras to my own app - but otherwise just the package without extras.

This doesn't work, (sqlalchemy only installs when installing my package with extras) but is it even a possible configuration pip wise even?