python-poetry / poetry

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

`poetry install --sync` without poetry.lock removes packages #7406

Closed miikka closed 1 year ago

miikka commented 1 year ago

Issue

If poetry install --sync is run with an existing virtualenv with (some of) the required packages installed but without a poetry.lock file, it will remove the packages even though they should be kept. In the repro below, it removes all the packages, but I'm not sure if this happens in every case - when I first encountered this problem, I thought it was keeping some of them.

Steps to reproduce:

git clone https://gist.github.com/miikka/d660cebb092e185344b4428f1a158a1d && cd d660cebb092e185344b4428f1a158a1d 
poetry lock
poetry install --sync --no-root
poetry run python -c 'import pydantic'  # check if Pydantic was installed
# everything works so far!

rm poetry.lock
poetry install --sync --no-root
poetry run python -c 'import pydantic'  # fails with ModuleNotFoundError!

The steps above use --no-root for easier reproduction, but the issue also happens without --no-root.

What happened: Poetry created a seemingly-correct poetry.lock file, but removed the dependencies (Pydantic in this example) specified in pyproject.toml.

What I expected to happen: Poetry would have kept the dependencies installed or at least re-installed them.

Workarounds: Either run poetry lock --no-update before running poetry install --sync or run poetry install --sync twice - the second run will use the poetry.lock created by the first run and re-installs the removes dependencies.

Debug output ``` % poetry install --sync --no-root -vvv Loading configuration file /Users/miikka.koskinen/Library/Preferences/pypoetry/config.toml Loading configuration file /Users/miikka.koskinen/Library/Preferences/pypoetry/auth.toml Using virtualenv: /Users/miikka.koskinen/Library/Caches/pypoetry/virtualenvs/poetry-repro-R0YbEG8X-py3.11 Updating dependencies Resolving dependencies... 1: fact: poetry-repro is 0.1.0 1: derived: poetry-repro 1: fact: poetry-repro depends on pydantic (^1.10.4) 1: fact: poetry-repro depends on pytest (^7.2.1) 1: selecting poetry-repro (0.1.0) 1: derived: pytest (>=7.2.1,<8.0.0) 1: derived: pydantic (>=1.10.4,<2.0.0) [keyring.backend] Loading KWallet [keyring.backend] Loading SecretService [keyring.backend] Loading Windows [keyring.backend] Loading chainer [keyring.backend] Loading libsecret [keyring.backend] Loading macOS Creating new session for pypi.org Source (PyPI): 1 packages found for pytest >=7.2.1,<8.0.0 Source (PyPI): 1 packages found for pydantic >=1.10.4,<2.0.0 1: fact: pytest (7.2.1) depends on attrs (>=19.2.0) 1: fact: pytest (7.2.1) depends on iniconfig (*) 1: fact: pytest (7.2.1) depends on packaging (*) 1: fact: pytest (7.2.1) depends on pluggy (>=0.12,<2.0) 1: fact: pytest (7.2.1) depends on colorama (*) 1: selecting pytest (7.2.1) 1: derived: colorama 1: derived: pluggy (>=0.12,<2.0) 1: derived: packaging 1: derived: iniconfig 1: derived: attrs (>=19.2.0) Source (PyPI): 43 packages found for colorama * Source (PyPI): 4 packages found for pluggy >=0.12,<2.0 Source (PyPI): 40 packages found for packaging * Source (PyPI): 6 packages found for iniconfig * Source (PyPI): 10 packages found for attrs >=19.2.0 1: fact: pydantic (1.10.4) depends on typing-extensions (>=4.2.0) 1: selecting pydantic (1.10.4) 1: derived: typing-extensions (>=4.2.0) Source (PyPI): 3 packages found for typing-extensions >=4.2.0 1: selecting typing-extensions (4.4.0) 1: selecting pluggy (1.0.0) 1: selecting iniconfig (2.0.0) 1: selecting attrs (22.2.0) 1: selecting packaging (23.0) 1: selecting colorama (0.4.6) 1: Version solving took 0.209 seconds. 1: Tried 1 solutions. Writing lock file Finding the necessary packages for the current system Source (poetry-repo): 1 packages found for pytest >=7.2.1,<8.0.0 Source (poetry-repo): 1 packages found for pydantic >=1.10.4,<2.0.0 Source (poetry-repo): 1 packages found for pluggy >=0.12,<2.0 Source (poetry-repo): 1 packages found for packaging * Source (poetry-repo): 1 packages found for iniconfig * Source (poetry-repo): 1 packages found for attrs >=19.2.0 Source (poetry-repo): 1 packages found for typing-extensions >=4.2.0 Package operations: 0 installs, 0 updates, 7 removals, 7 skipped • Removing attrs (22.2.0): Pending... • Removing attrs (22.2.0): Removing... • Removing attrs (22.2.0) • Removing iniconfig (2.0.0): Pending... • Removing iniconfig (2.0.0): Removing... • Removing iniconfig (2.0.0) • Removing packaging (23.0): Pending... • Removing packaging (23.0): Removing... • Removing packaging (23.0) • Removing pluggy (1.0.0): Pending... • Removing pluggy (1.0.0): Removing... • Removing pluggy (1.0.0) • Removing pydantic (1.10.4): Pending... • Removing pydantic (1.10.4): Removing... • Removing pydantic (1.10.4) • Removing pytest (7.2.1): Pending... • Removing pytest (7.2.1): Removing... • Removing pytest (7.2.1) • Removing typing-extensions (4.4.0): Pending... • Removing typing-extensions (4.4.0): Removing... • Removing typing-extensions (4.4.0) • Installing attrs (22.2.0): Pending... • Installing attrs (22.2.0): Skipped for the following reason: Already installed • Installing packaging (23.0): Pending... • Installing packaging (23.0): Skipped for the following reason: Already installed • Installing pluggy (1.0.0): Pending... • Installing pluggy (1.0.0): Skipped for the following reason: Already installed • Installing pydantic (1.10.4): Pending... • Installing pydantic (1.10.4): Skipped for the following reason: Already installed • Installing pytest (7.2.1): Pending... • Installing pytest (7.2.1): Skipped for the following reason: Already installed • Installing iniconfig (2.0.0): Pending... • Installing iniconfig (2.0.0): Skipped for the following reason: Already installed • Installing typing-extensions (4.4.0): Pending... • Installing typing-extensions (4.4.0): Skipped for the following reason: Already installed ```
dimbleby commented 1 year ago

duplicate #4465

miikka commented 1 year ago

Great, I tried the repro on latest master and the problem is indeed gone. Closing this issue.

github-actions[bot] commented 6 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.