Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 330
willclarktech Avatar asked Dec 06 '25 02:12

willclarktech


1 Answers

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"
like image 199
Arne Avatar answered Dec 08 '25 15:12

Arne