pythonvirtualenvgnupgpython-poetrytty

How do I set an environment variable dynamically when using poetry shell?


When I activate a virtual environment via poetry shell, GPG signing gets messed up because $GPG_TTY is set for the parent shell. So every time I use poetry shell I have to do GPG_TTY=$(tty). Is there a way to do this automatically? Ideally I would set this up once globally rather than for every poetry project.


Solution

  • Poetry does include a plugin system from version 1.2 onwards, and .env support - if that works for your use case - has been one of the first plugins being written. You can activate it with

    poetry self add poetry-dotenv-plugin
    

    If plugins are not for you, this pattern works with most shells and will work globally for your user:

    ~/.bashrc

    alias poetry="GPG_TTY=$(tty) poetry"