1
1
from __future__ import annotations
2
2
3
+ import os
3
4
import sys
4
5
5
- from os import environ
6
6
from typing import TYPE_CHECKING
7
7
from typing import cast
8
8
@@ -17,9 +17,12 @@ class ShellCommand(EnvCommand):
17
17
name = "shell"
18
18
description = "Spawns a shell within the virtual environment."
19
19
20
- help = """The <info>shell</> command spawns a shell, according to the
21
- <comment>$SHELL</> environment variable, within the virtual environment.
22
- If one doesn't exist yet, it will be created.
20
+ help = f"""The <info>shell</> command spawns a shell within the project's virtual environment.
21
+
22
+ By default, the current active shell is detected and used. Failing that,
23
+ the shell defined via the environment variable <comment>{ 'COMSPEC' if os .name == 'nt' else 'SHELL' } </> is used.
24
+
25
+ If a virtual environment does not exist, it will be created.
23
26
"""
24
27
25
28
def handle (self ) -> int :
@@ -41,14 +44,14 @@ def handle(self) -> int:
41
44
env = cast ("VirtualEnv" , env )
42
45
43
46
# Setting this to avoid spawning unnecessary nested shells
44
- environ ["POETRY_ACTIVE" ] = "1"
47
+ os . environ ["POETRY_ACTIVE" ] = "1"
45
48
shell = Shell .get ()
46
49
shell .activate (env )
47
- environ .pop ("POETRY_ACTIVE" )
50
+ os . environ .pop ("POETRY_ACTIVE" )
48
51
49
52
return 0
50
53
51
54
def _is_venv_activated (self ) -> bool :
52
- return bool (environ .get ("POETRY_ACTIVE" )) or getattr (
55
+ return bool (os . environ .get ("POETRY_ACTIVE" )) or getattr (
53
56
sys , "real_prefix" , sys .prefix
54
57
) == str (self .env .path )
0 commit comments