You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
TL;DR: Why does poetry run $SHELL (note: NOT poetry shell), cause this failure?
➜ poetry run python -m mole version
mole version 0.4.15
➜ poetry run sh -c "python -m mole version"
mole version 0.4.15
➜ poetry run $SHELL
(mole-py3.11) ➜ python -m mole version
/Users/erichdblume/.asdf/installs/python/3.11.6/bin/python: No module named mole
One of the commands this project supports, zonein, contains code that ultimately spawns a new $SHELL (inside of a terminal multiplexer named 'zellij'), and one of the things I use that new shell to do frequently is to edit the script itself (with mole zonein mole). I use pipx to install this script for general use, but while developing it I will sometimes need to run it like poetry run python -m mole zonein mole), and that means that when I run the command that way I will have the poetry-managed virtualenv loaded in the subshell because the parent process had it loaded via poetry run. This means the resulting subshell is a bit like running poetry run $SHELL, and as you can see above the issue exists if you do actually just run poetry run $SHELL.
OK, preamble aside, here is my problem: When I launch my editor shell this way, the environment variables are not set the same way they are set when I run poetry shell, such that the virtual environment is not on my $PATH and so none of the correct modules are loaded. I am of course able to just run poetry shell, which is what I typically do when not running my script via poetry run anyway.
I find all of this quite baffling and I'm sure there's some obvious explanation related to login shells and POSIX behavior and I've probably just footgunned myself with my custom ~/.zprofile and ~/.zshrc, but after spending an entire morning on it I've decided to come here to ask for more help. If you have any advice, thanks!
By the way, the only reason I find this to be at all problematic for me, is that because I am using a PS1 prompt generator (starship) which detects the $VIRTUAL_ENV environment variable, it signals to me that my virtual environment is loaded, so I don't always remember to poetry shell so that my editor will have access to all the proper metadata. In particular, I use neovim with nvim-lspconfig to load Pyright as my LSP python server, which will cause Pyright to litter errors all over my code due to failing to find libraries. It's a cosmetic issue, but a vexing one for me.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
TL;DR: Why does
poetry run $SHELL
(note: NOTpoetry shell
), cause this failure?I am working on a python CLI which I manage via poetry (link to pyproject.toml at time of writing).
One of the commands this project supports, zonein, contains code that ultimately spawns a new $SHELL (inside of a terminal multiplexer named 'zellij'), and one of the things I use that new shell to do frequently is to edit the script itself (with
mole zonein mole
). I usepipx
to install this script for general use, but while developing it I will sometimes need to run it likepoetry run python -m mole zonein mole
), and that means that when I run the command that way I will have the poetry-managed virtualenv loaded in the subshell because the parent process had it loaded viapoetry run
. This means the resulting subshell is a bit like runningpoetry run $SHELL
, and as you can see above the issue exists if you do actually just runpoetry run $SHELL
.OK, preamble aside, here is my problem: When I launch my editor shell this way, the environment variables are not set the same way they are set when I run
poetry shell
, such that the virtual environment is not on my $PATH and so none of the correct modules are loaded. I am of course able to just runpoetry shell
, which is what I typically do when not running my script viapoetry run
anyway.I find all of this quite baffling and I'm sure there's some obvious explanation related to login shells and POSIX behavior and I've probably just footgunned myself with my custom ~/.zprofile and ~/.zshrc, but after spending an entire morning on it I've decided to come here to ask for more help. If you have any advice, thanks!
By the way, the only reason I find this to be at all problematic for me, is that because I am using a PS1 prompt generator (starship) which detects the $VIRTUAL_ENV environment variable, it signals to me that my virtual environment is loaded, so I don't always remember to
poetry shell
so that my editor will have access to all the proper metadata. In particular, I use neovim with nvim-lspconfig to load Pyright as my LSP python server, which will cause Pyright to litter errors all over my code due to failing to find libraries. It's a cosmetic issue, but a vexing one for me.Beta Was this translation helpful? Give feedback.
All reactions