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:
-
Create a new project:
$ poetry new env-issue Created package env_issue in env-issue $ cd env-issue/
-
Disable virtual environment creation:
poetry config virtualenvs.create false --local
-
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.