diff --git a/src/poetry/utils/shell.py b/src/poetry/utils/shell.py index 290a62c09c1..0d7da584865 100644 --- a/src/poetry/utils/shell.py +++ b/src/poetry/utils/shell.py @@ -97,12 +97,19 @@ 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(): + if self._name == "nu": + args = ["-e", cmd] + else: + args = ["-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,9 +117,10 @@ 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))}") + 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)