Poetry: Ctrl+C exits `poetry shell` in Fish shell

Created on 22 Jan 2019  路  3Comments  路  Source: python-poetry/poetry

  • [x] I am on the latest Poetry version.
  • [x] I have searched the issues of this repo and believe that this is not a duplicate.
  • OS version and name: macOS 10.14.2
  • Poetry version: 0.12.11

Issue

When the Poetry shell is launched with poetry shell under the Fish shell, Ctrl+C exits the Poetry shell. This doesn't happen when launched from Bash. I would expect that Ctrl+C does nothing. I ended up not using poetry shell, but rather sourcing the activate.fish from the virtual environment, but that is a bit more cumbersome, because it's not directly accessible as a Poetry command.

Most helpful comment

I can reproduce this on Arch with these versions:

poetry: 0.12.12
fish: 3.0.2

Edit: I did some digging through the Pipenv source code, and it looks like they launch a shell using os.execvp() instead of subprocess.call(), like Poetry. I can confirm that launching a shell that way allows fish to accept Ctrl+C normally.

Here's a reproduction:

import os
import subprocess

SHELL_PATH = '/usr/bin/fish'

if __name__ == '__main__':
    print('spawning new shell')
    # Ctrl+C will kill this shell:
    subprocess.call([SHELL_PATH])

    # Ctrl+C will not kill this shell:
    os.execvp(SHELL_PATH, ['-i'])

Here's how Pipenv launches a shell:

def _handover(cmd, args):
    args = [cmd] + args
    if os.name != "nt":
        os.execvp(cmd, args)
    else:
        sys.exit(subprocess.call(args, shell=True, universal_newlines=True))

All 3 comments

I can reproduce this on Arch with these versions:

poetry: 0.12.12
fish: 3.0.2

Edit: I did some digging through the Pipenv source code, and it looks like they launch a shell using os.execvp() instead of subprocess.call(), like Poetry. I can confirm that launching a shell that way allows fish to accept Ctrl+C normally.

Here's a reproduction:

import os
import subprocess

SHELL_PATH = '/usr/bin/fish'

if __name__ == '__main__':
    print('spawning new shell')
    # Ctrl+C will kill this shell:
    subprocess.call([SHELL_PATH])

    # Ctrl+C will not kill this shell:
    os.execvp(SHELL_PATH, ['-i'])

Here's how Pipenv launches a shell:

def _handover(cmd, args):
    args = [cmd] + args
    if os.name != "nt":
        os.execvp(cmd, args)
    else:
        sys.exit(subprocess.call(args, shell=True, universal_newlines=True))

temporary workaround which i found (is not so good since it have python version hardcoded):

function poetry_shell
        source $HOME/.cache/pypoetry/virtualenvs/(basename $PWD)-py3.7/bin/activate.fish
end

UPD:

or could be like that but still not fine if you have projects using non-default version:

function poetry_shell
    source $HOME/.cache/pypoetry/virtualenvs/(basename $PWD)-py(python --version | grep -o '[0-9].[0-9]')/bin/activate.fish
end

@jhrmnn This was fixed in 1.0.0b2 by making the change I mentioned above

Was this page helpful?
0 / 5 - 0 ratings