Skip to content

Commit 342f2a9

Browse files
abnneersighted
andauthored
cmd/shell: fix incorrect documentation (#9060)
Co-authored-by: Bjorn Neergaard <bjorn@neersighted.com>
1 parent 52ec509 commit 342f2a9

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

docs/cli.md

+12-4
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,13 @@ Note that this command has no option.
637637

638638
## shell
639639

640-
The `shell` command spawns a shell,
641-
according to the `$SHELL` environment variable,
642-
within the virtual environment.
643-
If one doesn't exist yet, it will be created.
640+
The shell command spawns a shell within the project's virtual environment.
641+
642+
By default, the current active shell is detected and used. Failing that,
643+
the shell defined via the environment variable `SHELL` (on *nix) or
644+
`COMSPEC` (on Windows) is used.
645+
646+
If a virtual environment does not exist, it will be created.
644647

645648
```bash
646649
poetry shell
@@ -650,6 +653,11 @@ Note that this command starts a new shell and activates the virtual environment.
650653

651654
As such, `exit` should be used to properly exit the shell and the virtual environment instead of `deactivate`.
652655

656+
{{% note %}}
657+
Poetry internally uses the [Shellingham](https://github.com/sarugaku/shellingham) project to detect current
658+
active shell.
659+
{{% /note %}}
660+
653661
## check
654662

655663
The `check` command validates the content of the `pyproject.toml` file

src/poetry/console/commands/shell.py

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
from __future__ import annotations
22

3+
import os
34
import sys
45

5-
from os import environ
66
from typing import TYPE_CHECKING
77
from typing import cast
88

@@ -17,9 +17,12 @@ class ShellCommand(EnvCommand):
1717
name = "shell"
1818
description = "Spawns a shell within the virtual environment."
1919

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.
2326
"""
2427

2528
def handle(self) -> int:
@@ -41,14 +44,14 @@ def handle(self) -> int:
4144
env = cast("VirtualEnv", env)
4245

4346
# Setting this to avoid spawning unnecessary nested shells
44-
environ["POETRY_ACTIVE"] = "1"
47+
os.environ["POETRY_ACTIVE"] = "1"
4548
shell = Shell.get()
4649
shell.activate(env)
47-
environ.pop("POETRY_ACTIVE")
50+
os.environ.pop("POETRY_ACTIVE")
4851

4952
return 0
5053

5154
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(
5356
sys, "real_prefix", sys.prefix
5457
) == str(self.env.path)

0 commit comments

Comments
 (0)