rye icon indicating copy to clipboard operation
rye copied to clipboard

Shell subcommand doesn't bump venv Python in PATH

Open cnpryer opened this issue 2 years ago • 4 comments

Is the goal for rye shell to activate a shell with a modified environment that places the venv bin at the top of PATH? If so I'm not sure this is working with SHELL -l.

Using zsh on macos I get the following experience:

With aa559499453a6de2905a40c6ef736e50f6421fa1

test-project on  master [?] is 📦 v0.0.1 via 🐍 
❯ rye run python -c "import sys; print(sys.executable)" 
/Users/chrispryer/github/sandbox/rye/test-project/.venv/bin/python

test-project on  master [?] is 📦 v0.0.1 via 🐍 
❯ rye shell
Spawning virtualenv shell from /Users/chrispryer/github/sandbox/rye/test-project/.venv
Leave shell with 'exit'

test-project on  master [?] is 📦 v0.0.1 via 🐍 (.venv) 
❯ which python
/Users/chrispryer/.pyenv/shims/python

With something like sh --init-file .venv/bin/activate

test-project on  master [?] is 📦 v0.0.1 via 🐍 took 1m9s 
❯ rye run python -c "import sys; print(sys.executable)"
/Users/chrispryer/github/sandbox/rye/test-project/.venv/bin/python

test-project on  master [?] is 📦 v0.0.1 via 🐍 
❯ rye shell                                            
Spawning virtualenv shell from /Users/chrispryer/github/sandbox/rye/test-project/.venv
Leave shell with 'exit'
sh-3.2$ which python
/Users/chrispryer/github/sandbox/rye/test-project/.venv/bin/python

cnpryer avatar Apr 29 '23 21:04 cnpryer

Yeah it's quite possible that this is not working as intended at the moment. There is unfortunately no way without pexpect or co to initialize a shell with specific environment variables in a portable way.

mitsuhiko avatar Apr 30 '23 12:04 mitsuhiko

Yea this is what I've had my eyes on for this https://github.com/rust-cli/rexpect

cnpryer avatar Apr 30 '23 13:04 cnpryer

So looking into this more, I think the shell feature should not exist. It's almost impossible to get right without a ton of hacks, and the only thing it's even trying to do is give you a better syntax to activate a virtualenv. Maybe a better story would be to have something like rye activate-venv and it spits out a command for how to activate the virtualenv?

mitsuhiko avatar May 01 '23 15:05 mitsuhiko

I'd agree, but from what I can tell a lot of people find it useful. I think it's a UX thing. Like when you use rye you want to defer to rye on how to do things. I wouldn't prioritize this over other stuff though. It's a nice-to-have.

It is probably a good idea to rip shell out for something like rye activate-venv for now. But rye activate-venv reads kind of like it'll activate it. Maybe rye venv-activation or something.

cnpryer avatar May 01 '23 15:05 cnpryer