Skip to content

AssertionError when spawning shell with "virtualenvs.create" set to false #30

Open
@dunossauro

Description

@dunossauro

When attempting to activate the shell in a project with the virtualenvs.create configuration set to false, an AssertionError is raised. While the error itself may not be inherently wrong (since Poetry is expecting a virtual environment), the error message should more clearly indicate that the virtualenvs.create setting has been disabled, preventing the creation of a virtual environment.

How to reproduce:

  1. Create a new project:

    $ poetry new env-issue
    Created package env_issue in env-issue
    $ cd env-issue/
  2. Disable virtual environment creation:

    poetry config virtualenvs.create false --local
  3. Attempt to activate the Poetry shell:

    $ poetry shell
    Skipping virtualenv creation, as specified in config file.
    Spawning shell within /usr
    
      AssertionError

Error traceback:

  at ~/.local/share/pipx/venvs/poetry/lib/python3.13/site-packages/poetry_plugin_shell/command.py:43 in handle
       39self.line(f"Spawning shell within {self.env.path}")
       4041# Be sure that we have the right type of environment.
       42env = self.env43assert env.is_venv()
       44env = cast("VirtualEnv", env)
       4546# Setting this to avoid spawning unnecessary nested shells
       47os.environ["POETRY_ACTIVE"] = "1"

Expected behavior:

The shell may indeed not be spawned, and that is correct. However, instead of the AssertionError, the error message should clearly indicate that the virtualenvs.create setting is disabled, which prevents Poetry from creating a virtual environment. A more descriptive message, such as "Virtual environment creation is disabled by the configuration," would help clarify the reason for the error.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions