poetry icon indicating copy to clipboard operation
poetry copied to clipboard

When adding a package, extras in a set get reset to the default import

Open Alexandre-SCHOEPP opened this issue 7 months ago • 4 comments

Description

Since I use PyTorch, I have a configuration for extras in a set that enable my users to select on which driver by the extra.

Click to expand the pyproject.toml file
[project]
# classic stuff
dynamic = ["classifiers"]
dependencies = [  # This is used to generate metadata.
    "torch (==2.6.0+cpu); extra != 'cuda' and extra != 'cuda124' and extra != 'cuda118'",
    "torchvision (==0.21.0+cpu); extra != 'cuda' and extra != 'cuda124' and extra != 'cuda118'",
]

[project.optional-dependencies]
cuda = [
    "torch (==2.6.0+cu126)",
    "torchvision (==0.21.0+cu126)",
]
cuda124 = [
    "torch (==2.6.0+cu124)",
    "torchvision (==0.21.0+cu124)",
]
cuda118 = [
    "torch (==2.6.0+cu118)",
    "torchvision (==0.21.0+cu118)",
]

It causes two issues:

  • When installing from the wheel generated by poetry build without extras, the "default flavor", I don't get torch or torchvision installed
  • When I develop my software and add a dependency, for example poetry add pytimeparse, poetry reverts me back to the "default flavor" of torch (2.6.0+cpu), even though I installed with -E cuda (when producing the logs for this issue I found the issue also arises from poetry remove pytimeparse)

Workarounds

For the first issue, I told my end-users to run

poetry add --source my-configured-source my-project
poetry add "torch==2.6.0"
poetry add "torchvision==0.21.0"

When they don't have CUDA available

For the second one, I just have to continuously run poetry install ... whenever I add a new dependency

Poetry Installation Method

pipx

Operating System

Windows 10

Poetry Version

2.1.1

Poetry Configuration

cache-dir = "C:\\Users\\me\\AppData\\Local\\pypoetry\\Cache"
data-dir = "C:\\Users\\me\\AppData\\Roaming\\pypoetry"
installer.max-workers = null
installer.no-binary = null
installer.only-binary = null
installer.parallel = true
installer.re-resolve = false
keyring.enabled = true
python.installation-dir = "{data-dir}\\python"  # C:\Users\me\AppData\Roaming\pypoetry\python
repositories.pypi1.url = "https://pypi.org/simple/"
repositories.pypi2.url = "https://pypi.org/simple/"
repositories.pypi3.url = "https://pypi.org/simple/"
repositories.pytorch-cpu.url = "https://download.pytorch.org/whl/cpu"
repositories.pytorch-cuda118.url = "https://download.pytorch.org/whl/cu118"
repositories.pytorch-cuda124.url = "https://download.pytorch.org/whl/cu124"
repositories.pytorch-cuda126.url = "https://download.pytorch.org/whl/cu126"
requests.max-retries = 0
solver.lazy-wheel = true
system-git-client = false
virtualenvs.create = true
virtualenvs.in-project = null
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}\\virtualenvs"  # C:\Users\alexandre.schoepp\AppData\Local\pypoetry\Cache\virtualenvs
virtualenvs.prompt = "{project_name}-py{python_version}"
virtualenvs.use-poetry-python = false

Poetry Runtime Logs

poetry-runtime.log
Loading configuration file C:\Users\me\AppData\Roaming\pypoetry\config.toml
Loading configuration file C:\Users\me\AppData\Roaming\pypoetry\auth.toml
Loading configuration file C:\Users\me\Documents\Code\my-project\poetry.toml
Adding repository pytorch-cpu (https://download.pytorch.org/whl/cpu) and setting it as explicit
Adding repository pytorch-cuda126 (https://download.pytorch.org/whl/cu126) and setting it as explicit
Adding repository pytorch-cuda124 (https://download.pytorch.org/whl/cu124) and setting it as explicit
Adding repository pytorch-cuda118 (https://download.pytorch.org/whl/cu118) and setting it as explicit
Using virtualenv: C:\Users\me\AppData\Local\pypoetry\Cache\virtualenvs\my-project-k_pcpb9K-py3.12
Checking keyring availability: Checking if keyring is available
[keyring:keyring.backend] Loading KWallet
[keyring:keyring.backend] Loading SecretService
[keyring:keyring.backend] Loading Windows
[win32ctypes:win32ctypes.core.ctypes] Loaded ctypes backend
[keyring:keyring.backend] Loading chainer
[keyring:keyring.backend] Loading libsecret
[keyring:keyring.backend] Loading macOS
Using keyring backend 'Windows WinVaultKeyring'
Available
Multiple source configurations found for pypi.org - pypi1, pypi2, pypi3, PyPI
Creating new session for pypi.org
Multiple source configurations found for pypi.org - pypi1, pypi2, pypi3, PyPI
Source (PyPI): 9 packages found for pytimeparse *
Using version ^1.1.8 for pytimeparse

Updating dependencies
Resolving dependencies...
 1: fact: my-project is 1.2.3
 1: derived: my-project
 0: Duplicate dependencies for torch
 0: Different requirements found for torch (2.6.0+cpu) with markers extra != "cuda118" and extra != "cuda124" and extra != "cuda", torch (<empty>) with markers (extra == "cuda" or extra == "cuda124" or extra == "cuda118") and (extra != "cuda" or extra == "cuda118" or extra == "cuda124") and (extra == "cuda" or extra == "cuda118" or extra != "cuda124") and (extra == "cuda" or extra != "cuda118" or extra == "cuda124"), torch (2.6.0+cu126) with markers extra == "cuda" and extra != "cuda118" and extra != "cuda124" and (extra == "cuda" or extra == "cuda118" or extra != "cuda124") and (extra == "cuda" or extra != "cuda118" or extra == "cuda124"), torch (2.6.0+cu124) with markers extra == "cuda124" and extra != "cuda" and extra != "cuda118" and (extra != "cuda" or extra == "cuda118" or extra == "cuda124") and (extra == "cuda" or extra != "cuda118" or extra == "cuda124") and torch (2.6.0+cu118) with markers extra == "cuda118" and extra != "cuda" and extra != "cuda124" and (extra != "cuda" or extra == "cuda118" or extra == "cuda124") and (extra == "cuda" or extra == "cuda118" or extra != "cuda124").
 1: Version solving took 0.003 seconds.
 1: Tried 1 solutions.
 0: Retrying dependency resolution with the following overrides ({Package('my-project', '1.2.3'): {'torch': <Dependency torch (==2.6.0+cpu)>}}).
 1: fact: my-project is 1.2.3
 1: derived: my-project
 ... 

And the logs continue with installing the CPU version of torch

Alexandre-SCHOEPP avatar Aug 05 '25 14:08 Alexandre-SCHOEPP

Confirms: the same happens with molecule-plugins[vagrant] on my side

Tcharl avatar Aug 14 '25 07:08 Tcharl

Image

    poetry install --all-extras --no-root --no-interaction --no-ansi
    poetry lock
    rm -rf requirements.txt
    poetry export -f requirements.txt --without-hashes -o requirements.txt
    rm -rf requirements-dev.txt
    poetry export -f requirements.txt --with dev --without-hashes -o requirements-dev.txt

Poetry export with 1.8.5:

Image

Poetry export with 2.0.0 (and later):

Image

Tcharl avatar Aug 14 '25 11:08 Tcharl

@Tcharl At first glance, your issue seems to be unrelated. Especially, the difference in poetry export is not an issue. See python-poetry/poetry-plugin-export#326 and python-poetry/poetry-plugin-export#329.

radoering avatar Aug 14 '25 13:08 radoering

You're right: no real change in poetry.lock file. Seems related to export plugin. Please ignore my comments.

Tcharl avatar Aug 14 '25 18:08 Tcharl