From 31a3aa41925e6f1f1db330b4cced4767ecb5eb93 Mon Sep 17 00:00:00 2001 From: Kent Tonino Date: Fri, 10 Apr 2026 00:34:14 +0800 Subject: [PATCH 1/3] fix: should return false if poetry is active but not virtual env --- src/poetry_plugin_shell/command.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/poetry_plugin_shell/command.py b/src/poetry_plugin_shell/command.py index 234ac85..e3a9bea 100644 --- a/src/poetry_plugin_shell/command.py +++ b/src/poetry_plugin_shell/command.py @@ -52,6 +52,10 @@ def handle(self) -> int: return 0 def _is_venv_activated(self) -> bool: + if os.environ.get("POETRY_ACTIVE") and not os.environ.get("VIRTUAL_ENV"): + os.environ.pop("POETRY_ACTIVE") + return False + return bool(os.environ.get("POETRY_ACTIVE")) or getattr( sys, "real_prefix", sys.prefix ) == str(self.env.path) From 8d866af5017f62dd8a46c6d39f80ee55eb41f56b Mon Sep 17 00:00:00 2001 From: Kent Tonino Date: Fri, 10 Apr 2026 00:45:08 +0800 Subject: [PATCH 2/3] fix: pop the POETRY_ACTIVE if it is set but not the VIRTUAL_ENV --- src/poetry_plugin_shell/command.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/poetry_plugin_shell/command.py b/src/poetry_plugin_shell/command.py index e3a9bea..fb05ae6 100644 --- a/src/poetry_plugin_shell/command.py +++ b/src/poetry_plugin_shell/command.py @@ -28,6 +28,9 @@ class ShellCommand(EnvCommand): def handle(self) -> int: from poetry_plugin_shell.shell import Shell + if os.environ.get("POETRY_ACTIVE") == "1" and not os.environ.get("VIRTUAL_ENV"): + os.environ.pop("POETRY_ACTIVE") + # Check if it's already activated or doesn't exist and won't be created if self._is_venv_activated(): self.line( @@ -52,10 +55,6 @@ def handle(self) -> int: return 0 def _is_venv_activated(self) -> bool: - if os.environ.get("POETRY_ACTIVE") and not os.environ.get("VIRTUAL_ENV"): - os.environ.pop("POETRY_ACTIVE") - return False - return bool(os.environ.get("POETRY_ACTIVE")) or getattr( sys, "real_prefix", sys.prefix ) == str(self.env.path) From c08095e49622f02108e563fe13e63c1030d436db Mon Sep 17 00:00:00 2001 From: Kent Tonino Date: Fri, 10 Apr 2026 00:57:14 +0800 Subject: [PATCH 3/3] fix: set the VIRTUAL_ENV in test --- tests/test_shell_command.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_shell_command.py b/tests/test_shell_command.py index 8b05732..c24fa30 100644 --- a/tests/test_shell_command.py +++ b/tests/test_shell_command.py @@ -35,7 +35,9 @@ def test_shell(tester: CommandTester, mocker: MockerFixture) -> None: def test_shell_already_active(tester: CommandTester, mocker: MockerFixture) -> None: + assert isinstance(tester.command, ShellCommand) os.environ["POETRY_ACTIVE"] = "1" + os.environ["VIRTUAL_ENV"] = str(tester.command.env.path) shell_activate = mocker.patch("poetry_plugin_shell.shell.Shell.activate") tester.execute()