python-poetry / poetry

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

`poetry self update` fails for `pipx`-installed `poetry` #8618

Open ilyagr opened 12 months ago

ilyagr commented 12 months ago

Issue

I tried upgrading from poetry 1.6.2, installed via pipx, to poetry 1.7.0 with poetry self update. The result was the error below.

I'm using pipx 1.2.1 and python 3.11.6 on Debian.

I believe that poetry self update should either call pipx upgrade or tell the user to do it, unless it's deprecated as per #7872.

I think/hope most people will figure out the problem, so this is not a major issue, but it'd still be nice to see fixed.

$ poetry self update
Updating Poetry version ...

Using version ^1.7.0 for poetry

Updating dependencies
Resolving dependencies... Downloading https://files.pythonhosted.org/packages/99/bc/058b8ff87871fce6615ad032d62c773272f243266b110f7b86d146cf
Resolving dependencies... (2.4s)

Package operations: 1 install, 19 updates, 0 removals

  β€’ Updating cffi (1.15.1 -> 1.16.0)
  β€’ Updating charset-normalizer (3.2.0 -> 3.3.2)
  β€’ Updating cryptography (41.0.3 -> 41.0.5)
  β€’ Updating urllib3 (1.26.16 -> 2.0.7)
  β€’ Updating zipp (3.16.2 -> 3.17.0)
  β€’ Updating filelock (3.12.2 -> 3.13.1)
  β€’ Updating msgpack (1.0.5 -> 1.0.7)
  β€’ Updating packaging (23.1 -> 23.2)
  β€’ Updating platformdirs (3.10.0 -> 3.11.0)
  β€’ Updating poetry-core (1.7.0 -> 1.8.1)
  β€’ Updating rapidfuzz (2.15.1 -> 3.5.2)
  β€’ Updating build (0.10.0 -> 1.0.3)
  β€’ Updating cleo (2.0.1 -> 2.1.0)
  β€’ Updating dulwich (0.21.5 -> 0.21.6)
  β€’ Installing fastjsonschema (2.18.1)
  β€’ Updating shellingham (1.5.0.post1 -> 1.5.4)
  β€’ Updating tomlkit (0.12.1 -> 0.12.2)
  β€’ Updating trove-classifiers (2023.8.7 -> 2023.10.18)
  β€’ Updating virtualenv (20.24.3 -> 20.24.6)
  β€’ Updating poetry (1.6.1 -> 1.7.0): Failed

  CalledProcessError

  Command '['/home/ilyagr/.local/pipx/venvs/poetry/bin/python', '/home/ilyagr/.local/pipx/venvs/poetry/lib/python3.11/site-packages/virtualenv/seed/wheels/embed/pip-23.2.1-py3-none-any.whl/pip', 'uninstall', 'poetry', '-y']' returned non-zero exit status 2.

  at /usr/lib/python3.11/subprocess.py:571 in run
       567β”‚             # We don't call process.wait() as .__exit__ does that for us.
       568β”‚             raise
       569β”‚         retcode = process.poll()
       570β”‚         if check and retcode:
    β†’  571β”‚             raise CalledProcessError(retcode, process.args,
       572β”‚                                      output=stdout, stderr=stderr)
       573β”‚     return CompletedProcess(process.args, retcode, stdout, stderr)
       574β”‚
       575β”‚

The following error occurred when trying to handle this error:

  EnvCommandError

  Command ['/home/ilyagr/.local/pipx/venvs/poetry/bin/python', '/home/ilyagr/.local/pipx/venvs/poetry/lib/python3.11/site-packages/virtualenv/seed/wheels/embed/pip-23.2.1-py3-none-any.whl/pip', 'uninstall', 'poetry', '-y'] errored with the following return code 2

  Output:
  /home/ilyagr/.local/pipx/venvs/poetry/bin/python: can't open file '/home/ilyagr/.local/pipx/venvs/poetry/lib/python3.11/site-packages/virtualenv/seed/wheels/embed/pip-23.2.1-py3-none-any.whl/pip': [Errno 2] No such file or directory

  at ~/.local/pipx/venvs/poetry/lib/python3.11/site-packages/poetry/utils/env/base_env.py:363 in _run
      359β”‚                 output = subprocess.check_output(
      360β”‚                     cmd, stderr=stderr, env=env, text=True, **kwargs
      361β”‚                 )
      362β”‚         except CalledProcessError as e:
    β†’ 363β”‚             raise EnvCommandError(e, input=input_)
      364β”‚
      365β”‚         return output
      366β”‚
      367β”‚     def execute(self, bin: str, *args: str, **kwargs: Any) -> int:
dimbleby commented 12 months ago

Previously: #7170.

People probably also try to self update installations made by some other means altogether eg their package manager. Perhaps it wouldn't be the worst idea for the poetry installer to leave behind some sort of marker file that poetry self could look for - and just bail out if not found.

As usual: if you care about this, then a pull request is overwhelmingly the most likely way to make something happen.

visch commented 8 months ago

I hit this but in a slightly different way with plugins today. Hope this posts helps someone else like me in the future, and maybe contributes to the core fix here!

End result is poetry is unusable and I get No module named 'poetry.core.semver'

To replicate

  1. pipx install poetry
  2. poetry self add "poetry-dynamic-versioning[plugin]"
  3. Any poetry command will now fail

Here's the output of 2 above which shows pretty clearly what's going on

poetry self add "poetry-dynamic-versioning[plugin]"
Using version ^1.2.0 for poetry-dynamic-versioning

Updating dependencies
Resolving dependencies... (0.2s)
Warning: The locked version 0.3.5 for poetry-types is a yanked version. Reason for being yanked: Incompatible with poetry>=1.5

Package operations: 2 installs, 20 updates, 0 removals

  β€’ Downgrading cffi (1.16.0 -> 1.15.1)
  β€’ Downgrading certifi (2024.2.2 -> 2022.12.7)
  β€’ Downgrading charset-normalizer (3.3.2 -> 3.0.1)
  β€’ Downgrading cryptography (42.0.4 -> 39.0.0)
  β€’ Downgrading idna (3.6 -> 3.4)
  β€’ Downgrading more-itertools (10.2.0 -> 9.0.0)
  β€’ Installing pyparsing (3.0.9)
  β€’ Downgrading urllib3 (2.2.1 -> 1.26.14)
  β€’ Downgrading zipp (3.17.0 -> 3.11.0)
  β€’ Downgrading importlib-metadata (7.0.1 -> 4.13.0)
  β€’ Downgrading jaraco-classes (3.3.1 -> 3.2.3)
  β€’ Downgrading msgpack (1.0.7 -> 1.0.4)
  β€’ Downgrading packaging (23.2 -> 21.3)
  β€’ Downgrading requests (2.31.0 -> 2.28.2)
  β€’ Downgrading markupsafe (2.1.5 -> 2.1.1)
  β€’ Downgrading pexpect (4.9.0 -> 4.8.0)
  β€’ Downgrading requests-toolbelt (1.0.0 -> 0.10.1)
  β€’ Downgrading shellingham (1.5.4 -> 1.5.0.post1)
  β€’ Downgrading tomlkit (0.12.3 -> 0.11.6)
  β€’ Downgrading trove-classifiers (2024.2.22 -> 2023.1.12)
  β€’ Downgrading jinja2 (3.1.3 -> 3.1.2)
  β€’ Installing poetry-types (0.3.5)
Warning: The file chosen for install of poetry-types 0.3.5 (poetry_types-0.3.5-py3-none-any.whl) is yanked. Reason for being yanked: Incompatible with poetry>=1.5

The work around is to not use poetry self add for plugins for poetry installed with pipx. Instead use pipx inject poetry poetry-dynamic-versioning[plugin]