Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve venv shell activation in fish shell #8804

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/poetry/utils/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ def activate(self, env: VirtualEnv) -> int | None:
cmd = f"{self._get_source_command()} {shlex.quote(str(activate_path))}"

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

c = pexpect.spawn(
self._path, args, dimensions=(terminal.lines, terminal.columns)
Expand All @@ -120,14 +125,11 @@ 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":
# If this is nu, we don't want to send the activation command to the
elif self._name in ["nu", "fish"]:
# If this is nu or fish, 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"]:
# Under fish, "\r" should be sent explicitly
cmd += "\r"
c.sendline(cmd)

def resize(sig: Any, data: Any) -> None:
Expand Down