Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dunossauro opened this issue Jan 11, 2025 · 0 comments · May be fixed by #31
Open

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

dunossauro opened this issue Jan 11, 2025 · 0 comments · May be fixed by #31

Comments

@dunossauro
Copy link

dunossauro commented Jan 11, 2025

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.

@taconi taconi linked a pull request Jan 11, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant