From 2756891189fb5caea0c0a8309528f86d1d8bd998 Mon Sep 17 00:00:00 2001 From: Niklas Kappel Date: Fri, 5 May 2023 21:15:56 +0200 Subject: [PATCH 1/4] send \r to fish when using poetry shell to execute source command --- src/poetry/utils/shell.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index d5b23288540..7508d730329 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -107,6 +107,9 @@ def activate(self, env: VirtualEnv) -> int | None: 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 == "fish": + # Under fish "\r" should be sent explicitly + c.sendline(f"source {shlex.quote(str(activate_path))}\r") else: c.sendline( f"{self._get_source_command()} {shlex.quote(str(activate_path))}" @@ -141,7 +144,7 @@ def _get_activate_script(self) -> str: return "activate" + suffix def _get_source_command(self) -> str: - if self._name in ("fish", "csh", "tcsh", "nu"): + if self._name in ("csh", "tcsh", "nu"): return "source" return "." From 6371f84b1626f60982f9715849ce1ce14c435849 Mon Sep 17 00:00:00 2001 From: Niklas Kappel Date: Sun, 7 May 2023 12:32:27 +0200 Subject: [PATCH 2/4] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Randy Döring <30527984+radoering@users.noreply.github.com> --- src/poetry/utils/shell.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 7508d730329..f3e1941caed 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -107,12 +107,13 @@ def activate(self, env: VirtualEnv) -> int | None: 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 == "fish": - # Under fish "\r" should be sent explicitly - c.sendline(f"source {shlex.quote(str(activate_path))}\r") else: + cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}" + if self._name == "fish": + # Under fish "\r" should be sent explicitly + cmd += "\r" c.sendline( - f"{self._get_source_command()} {shlex.quote(str(activate_path))}" + cmd ) def resize(sig: Any, data: Any) -> None: From b0a97ae519921e269edfc4695b00a90e43df7f1f Mon Sep 17 00:00:00 2001 From: Niklas Kappel Date: Sun, 7 May 2023 12:33:44 +0200 Subject: [PATCH 3/4] revert change to `_get_source_command` --- src/poetry/utils/shell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index f3e1941caed..c6bf7b14ef2 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -145,7 +145,7 @@ def _get_activate_script(self) -> str: return "activate" + suffix def _get_source_command(self) -> str: - if self._name in ("csh", "tcsh", "nu"): + if self._name in ("fish", "csh", "tcsh", "nu"): return "source" return "." From 2af0ce7e6b96847e8bd058e5245e2b7ac3ff1bb9 Mon Sep 17 00:00:00 2001 From: Niklas Kappel Date: Sun, 7 May 2023 12:38:46 +0200 Subject: [PATCH 4/4] apply black --- src/poetry/utils/shell.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index c6bf7b14ef2..38457206b8b 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -112,9 +112,7 @@ def activate(self, env: VirtualEnv) -> int | None: if self._name == "fish": # Under fish "\r" should be sent explicitly cmd += "\r" - c.sendline( - cmd - ) + c.sendline(cmd) def resize(sig: Any, data: Any) -> None: terminal = shutil.get_terminal_size()