How could i use venv

If i have a first step of:

  python3 -m venv path/to/venv
  source path/to/venv/bin/activate

Is there a way to have the venv active in subsequent steps?

There’s not an easy way to reuse commands or snippets right now, but you could do something like this

  1. Create an editor/script/terminal block with that content. Give it a name
  2. In all subsequent terminal blocks, reuse the content like os
{{ doc.named["THE NAME"].content }}

EG

Definitely looking to make this sort of reuse easier - any suggestions as to what would work for you?

Not sure about ideas :wink: but plenty of related requirements, eg kube context or

kubectl wait deployment/myapp

Ideally, the block would visually indicate that ā€˜things aren’t ready yet’.

Finally, the export doesn’t want this content (eg export to README.md shouldn’t be littered with these annotations),

EDIT

I need to try out your suggestion, it looks good. I shudda waited until I did before giving feedback

what about a custom interpreter?

I don’t know how well it would work for two commands, but worth a try!

my understanding is that only the second command is required to run each time - the first command creates the venv

here’s my half-baked solution:

Set the following as a custom interpreter and set the workdir (local directory node) to the directory that includes the .venv folder:

bash --init-file .venv/bin/activate -ic

I say ā€œhalf bakedā€ because it results in some bash warnings at the start of each script ā€œinappropriate ioctl for deviceā€ since we tell bash that this is an interactive instead of a login terminal

unsure if this is considered a bug

EDIT: Keep in mind that due to the --init-file flag your bashrc won’t be loaded. A much easier fix than all of the above is to check if the source file exists in your bashrc and source it ([[ -f .venv/bin/activate ]] && source .venv/bin/activate)

There are many, many other hacks and workarounds but it depends on what you want to do

1 Like