python-poetry / poetry

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

Extras with packages from groups other than main are not locked/installed correctly #9274

Closed swssl closed 5 months ago

swssl commented 5 months ago

Description

When adding an extra to the current project as stated in the docs, everything works. When adding the packages as optional to another dependency group, the lock file contains an empty array for that extra, so poetry install -E myextra runs without error but doesnt install the extra as defined in pyproject.toml. Possibly, locking the extra could either raise an error (which the docs should help to avoid) or support extras containing packages from other groups

Workarounds

Moving package to main group.

Poetry Installation Method

pipx

Operating System

Ubuntu (WSL)

Poetry Version

1.8.2

Poetry Configuration

cache-dir = "/home/swssl/.cache/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
keyring.enabled = true
solver.lazy-wheel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"
virtualenvs.prefer-active-python = false
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

Python Sysconfig

No response

Example pyproject.toml

[tool.poetry]
name = "awesome"
version = "0.1.0"
authors = ["Developer <dev@example.org>"]
description = "Awesome package"

[tool.poetry.dependencies]
# These packages are mandatory and form the core of this package’s distribution.
python = "^3.8"
requests = "^2.31.0"

[tool.poetry.group.foo.dependencies]
pydantic = "^2.0.0"
mysqlclient = { version = "^1.3", optional = true }
psycopg2 = { version = "^2.9", optional = true }

[tool.poetry.extras]
mysql = ["mysql-connector-python"]
pgsql = ["psycopg2"]

Poetry Runtime Logs

On poetry install --extras mysql --no-root, both packages extras are skipped without error:

- Installing mysqlclient (1.4.6): Pending...
- Installing mysqlclient (1.4.6): Skipped for the following reason: Not required
- Installing psycopg2 (2.9.9): Pending...
- Installing psycopg2 (2.9.9): Skipped for the following reason: Not required

Afterwards, the poetry.lock contains this:

[extras]
mysql = []
pgsql = []
dimbleby commented 5 months ago

As documented

The dependencies specified for each extra must already be defined as project dependencies. Dependencies listed in dependency groups cannot be specified as extras.

dimbleby commented 5 months ago

not only as documented, but as checked:

$ poetry check
Error: Cannot find dependency "mysql-connector-python" for extra "mysql" in main dependencies.
Error: Cannot find dependency "psycopg2" for extra "pgsql" in main dependencies.

please close

github-actions[bot] commented 4 months ago

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.