Skip to content

Handle missing virtualenv in shell command#60

Open
bubaizhanshen wants to merge 1 commit into
python-poetry:mainfrom
bubaizhanshen:fix-non-venv-shell-error
Open

Handle missing virtualenv in shell command#60
bubaizhanshen wants to merge 1 commit into
python-poetry:mainfrom
bubaizhanshen:fix-non-venv-shell-error

Conversation

@bubaizhanshen

@bubaizhanshen bubaizhanshen commented Jun 1, 2026

Copy link
Copy Markdown

Fixes #30.

This replaces the internal assertion when poetry shell is run without a virtualenv with a user-facing error. It also avoids printing the misleading Spawning shell within ... line before the environment type is validated.

Checks:

  • pytest tests/test_shell_command.py -q -n 0
  • ruff check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • ruff format --check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • pre-commit run --all-files

@StantonMatt StantonMatt left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked this locally because it covers the virtualenvs.create=false path from #30.

On the PR branch, a scratch project with local virtualenvs.create false now returns exit code 1 with the new user-facing message instead of reaching the assertion, and it no longer prints the misleading Spawning shell within ... line first.

Local checks I ran on Python 3.12.13:

  • .venv/bin/python -m pytest -q tests/test_shell_command.py::test_shell_without_virtualenv_shows_error
  • .venv/bin/python -m pytest -q
  • .venv/bin/python -m ruff check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • .venv/bin/python -m mypy src/poetry_plugin_shell/command.py tests/test_shell_command.py

I do not see a blocking issue from this pass.

@yangfan-yf-yf yangfan-yf-yf left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed the current head d3ea749 independently. The non-virtual environment path is now checked before the spawn message and before the VirtualEnv cast. The regression test verifies the intended user-facing error, exit status 1, no Shell.activate() call, and absence of the misleading spawn line.

Local verification on Windows with Python 3.12:

  • python -m pytest -q — 18 passed
  • python -m ruff check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • python -m ruff format --check src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • python -m mypy src/poetry_plugin_shell/command.py tests/test_shell_command.py
  • git diff --check

The GitHub Ubuntu, macOS, and Windows matrix is green on the current head.

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 this pull request may close these issues.

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

3 participants