From ac8a9f55853d20721be329bbddd2ad6ee14fe5d4 Mon Sep 17 00:00:00 2001 From: Skyler Hawthorne Date: Wed, 27 Sep 2023 10:08:16 -0400 Subject: [PATCH 1/2] poetry shell: fix nushell 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. --- src/poetry/utils/shell.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 290a62c09c1..872d083583c 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -97,12 +97,16 @@ 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": @@ -110,10 +114,14 @@ def activate(self, env: VirtualEnv) -> int | None: 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))}") + + # if this is nu, we don't want to send the activation command to the + # command line since we already ran it via the shell's invocation + elif self._name == "nu": + pass else: - cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}" - if self._name in ["fish", "nu"]: - # Under fish and nu "\r" should be sent explicitly + if self._name in ["fish"]: + # Under fish, "\r" should be sent explicitly cmd += "\r" c.sendline(cmd) From 7f1a0654c44759b0bca66adebee40b8ea58e5803 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Randy=20D=C3=B6ring?= <30527984+radoering@users.noreply.github.com> Date: Fri, 6 Oct 2023 17:06:10 +0200 Subject: [PATCH 2/2] coding style --- src/poetry/utils/shell.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 872d083583c..f8c413afd81 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -114,10 +114,9 @@ def activate(self, env: VirtualEnv) -> int | None: 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))}") - - # if this is nu, we don't want to send the activation command to the - # command line since we already ran it via the shell's invocation elif self._name == "nu": + # If this is nu, we don't want to send the activation command to the + # command line since we already ran it via the shell's invocation. pass else: if self._name in ["fish"]: