python-poetry / poetry

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

The `poentry install` command does not modify the file `env.toml` #9552

Open EliseevEgor opened 1 month ago

EliseevEgor commented 1 month ago

Description

Steps to reproduce:

  1. Create a poetry project.
  2. Install two python versions: for example, python 3.12.2 and 3.12.3.
  3. poetry env use /<path to python 3.12.2>/bin/python.
  4. Delete existing env rm -rf $(poetry env info --path).
  5. Create a new one with poetry install (Poetry will use the newest patch version by default 3.12.3).
  6. Run command poetry env use /.../pypoetry/virtualenvs/poetry-project-name/bin/python

Poetry deletes the existing poetry environment with an error: Could not find the python executable /.../pypoetry/virtualenvs/poetry-project-name/bin/python

Workarounds

Manually change the version of the interpreter in the file env.toml.

In my example from 3.12.2 to 3.12.3.

Poetry Installation Method

system package manager (eg: dnf, apt etc.)

Operating System

MacOS Sonoma 14.3.1

Poetry Version

1.7.1

Poetry Configuration

cache-dir = "/Users/Egor.Eliseev/Library/Caches/pypoetry"
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = null
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"  # /Users/Egor.Eliseev/Library/Caches/pypoetry/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 = "poetry-pro"
version = "0.1.0"
description = ""
authors = ["Some Dev <somedev@mail.com>"]
packages = []

[tool.poetry.dependencies]
python = "^3.12"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

Stack trace:

  8  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/application.py:327 in run
      325│ 
      326│             try:
    → 327│                 exit_code = self._run(io)
      328│             except BrokenPipeError:
      329│                 # If we are piped to another process, it may close early and send a

  7  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/poetry/console/application.py:190 in _run
      188│         self._load_plugins(io)
      189│ 
    → 190│         exit_code: int = super()._run(io)
      191│         return exit_code
      192│ 

  6  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/application.py:431 in _run
      429│             io.input.interactive(interactive)
      430│ 
    → 431│         exit_code = self._run_command(command, io)
      432│         self._running_command = None
      433│ 

  5  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/application.py:473 in _run_command
      471│ 
      472│         if error is not None:
    → 473│             raise error
      474│ 
      475│         return terminate_event.exit_code

  4  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/application.py:457 in _run_command
      455│ 
      456│             if command_event.command_should_run():
    → 457│                 exit_code = command.run(io)
      458│             else:
      459│                 exit_code = ConsoleCommandEvent.RETURN_CODE_DISABLED

  3  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/commands/base_command.py:117 in run
      115│         io.input.validate()
      116│ 
    → 117│         return self.execute(io) or 0
      118│ 
      119│     def merge_application_definition(self, merge_args: bool = True) -> None:

  2  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/cleo/commands/command.py:61 in execute
       59│ 
       60│         try:
    →  61│             return self.handle()
       62│         except KeyboardInterrupt:
       63│             return 1

  1  /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/poetry/console/commands/env/use.py:24 in handle
       22│             return 0
       23│ 
    →  24│         env = manager.activate(self.argument("python"))
       25│ 
       26│         self.line(f"Using virtualenv: {env.path}")

  PythonVersionNotFound

  Could not find the python executable /.../pypoetry/virtualenvs/poetry-project-name-py3.12/bin/python

  at /opt/homebrew/Cellar/poetry/1.7.1/libexec/lib/python3.12/site-packages/poetry/utils/env/env_manager.py:141 in activate
      137│             pass
      138│ 
      139│         python_path = self._full_python_path(python)
      140│         if python_path is None:
    → 141│             raise PythonVersionNotFound(python)
      142│ 
      143│         try:
      144│             python_version_string = subprocess.check_output(
      145│                 [python_path, "-c", GET_PYTHON_VERSION_ONELINER], text=True
dimbleby commented 1 month ago

probably duplicate https://github.com/python-poetry/poetry/pull/9286? try with the main branch, please close

EliseevEgor commented 1 month ago

I tried it with Poetry 1.8.3. Bug is still reproducing.

https://github.com/python-poetry/poetry/pull/9286 was merged on Apr 9. 1.8.3 was published on May 8.

dimbleby commented 1 month ago

9286 is not in the 1.8.3 release, your test didn't show anything

EliseevEgor commented 1 month ago

Ok. In 1.9.0.dev0 bug is still reproducing

EliseevEgor commented 1 month ago
Traceback (most recent call last):
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/application.py", line 327, in run
  File ".../poetry/src/poetry/console/application.py", line 180, in _run
    exit_code: int = super()._run(io)
                     ^^^^^^^^^^^^^^^^
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/application.py", line 431, in _run
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/application.py", line 473, in _run_command
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/application.py", line 457, in _run_command
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/commands/base_command.py", line 117, in run
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/cleo/commands/command.py", line 61, in execute
  File ".../poetry/src/poetry/console/commands/env/use.py", line 33, in handle
    env = manager.activate(self.argument("python"))
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../poetry/src/poetry/utils/env/env_manager.py", line 248, in activate
    self.create_venv(executable=python_path, force=create)
  File ".../poetry/src/poetry/utils/env/env_manager.py", line 596, in create_venv
    self.build_venv(
  File ".../poetry/src/poetry/utils/env/env_manager.py", line 682, in build_venv
    cli_result = virtualenv.cli_run(args, setup_logging=False)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/virtualenv/run/__init__.py", line 31, in cli_run
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/virtualenv/run/__init__.py", line 49, in session_via_cli
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/virtualenv/run/__init__.py", line 76, in build_parser
  File ".../Library/Caches/pypoetry/virtualenvs/poetry-py3.12/lib/python3.12/site-packages/virtualenv/run/plugin/discovery.py", line 22, in get_discover
StopIteration

And .../Library/Caches/pypoetry/virtualenvs/poetry-py3.12 env has been deleted.