python-poetry / python-poetry/poetry-plugin-shell

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

Open
#30 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
141
Forks
10
Avg merge
59m
Merged PRs (30d)
3

Description

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
       39│         self.line(f"Spawning shell within {self.env.path}")
       40│ 
       41│         # Be sure that we have the right type of environment.
       42│         env = self.env
    →  43│         assert env.is_venv()
       44│         env = cast("VirtualEnv", env)
       45│ 
       46│         # Setting this to avoid spawning unnecessary nested shells
       47│         os.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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading poetry_plugin_shell/command.py at the assertion shown in the traceback, especially the environment check in handle. Reproduce the case with virtualenvs.create set to false and confirm the current AssertionError. Done means shell activation reports that virtual environment creation is disabled instead of exposing the assertion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.