Skip to content

Commit

Permalink
poetry shell: fix nushell
Browse files Browse the repository at this point in the history
Presently, there are two bugs with `poetry shell` on nushell:

1. The `overlay use` command that poetry sends to the subshell does not
   get run, but merely appears on the command line as if the user had
   typed it themselves. Hitting the enter key is still necessary to
   activate the virtualenv.
2. In the subshell, whenever the user uses a tool that requires
   interactive keyboard input, the input is not echoed on the screen.
   This is because the current code specifically and explicitly turns
   off the terminal echo mode. It is unclear why.

This change fixes both of these problems by changing the invocation of
`nu` to run the `overlay use` command with the `-e` flag, which runs the
given command and then starts an interactive shell.

Disabling echo mode is also removed.
  • Loading branch information
dead10ck committed Sep 28, 2023
1 parent b6ebabf commit 6ae926a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/poetry/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,27 @@ def activate(self, env: VirtualEnv) -> int | None:
import shlex

terminal = shutil.get_terminal_size()
cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}"

with env.temp_environ():
args = ["-e", cmd] if self._name == "nu" else ["-i"]

c = pexpect.spawn(
self._path, ["-i"], dimensions=(terminal.lines, terminal.columns)
self._path, args, dimensions=(terminal.lines, terminal.columns)
)

if self._name in ["zsh", "nu"]:
if self._name in ["zsh"]:
c.setecho(False)

if self._name == "zsh":
# Under ZSH the source command should be invoked in zsh's bash emulator
c.sendline(f"emulate bash -c '. {shlex.quote(str(activate_path))}'")
elif self._name == "xonsh":
c.sendline(f"vox activate {shlex.quote(str(env.path))}")
elif self._name == "nu":
pass
else:
cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}"
if self._name in ["fish", "nu"]:
if self._name in ["fish"]:
# Under fish and nu "\r" should be sent explicitly
cmd += "\r"
c.sendline(cmd)
Expand Down

0 comments on commit 6ae926a

Please sign in to comment.