#$`source .venv/bin/activate` can't be executed

1 messages · Page 1 of 1 (latest)

runic shell
#

I love bun $ shell expression, but found $`source .venv/bin/activate` or $`. .venv/bin/activate` command doesn't work. Is it possible to run some shell script files within TypeScript with $ expression? Thank you for your cooperation in advance.

wheat spoke
#

I think you should run source .venv/bin/activate and then your bun script from that shell.

#

Although, reading the activate script created by venv, it only prepends the PATH, so you could do something like this:

import { $ } from "bun";

$.env({ PATH: process.env.PWD + "/.venv/bin:" + process.env.PATH });

console.log(await $`which python`.text());

That should give you the python from your venv. The activate script also deals with portability with windows and setting the prompt, but I don't think those are issues if you are running it from bun.

#

You might also want to unset the PYTHONHOME var if you have it set for some reason (I can't see a way to do this with $ but process.env works:

delete process.env.PYTHONHOME;
runic shell
#

Thanks a lot! Does it mean bun can't run a shell script within TypeScript? Like $`./script.sh`

gritty halo
#

I think you should be able to. Maybe you'll need to run it as $`bash ./script.sh` instead.

runic shell
#

I see, but it launches a child process, doesn't it? Is it impossible to run scripts in the same process?