condacolab
condacolab copied to clipboard
Revamp `env` kwarg in new implementation and provide pre launch logic
We forgot about the env
keyword argument in #31, oopsie.
This keyword allows users to inject environment variables in the kernel launch. We used it for LD_LIBRARY_PATH
, but we don't need that anymore because we activate the environment fully.
Instead, I suggest we revamp this option and mix it with a new keyword argument `pre_kernel_launch or something. It should accept either a path to a file or a multiline content str.
Logic would be like:
def fn(..., env={"my_var": "my_value"}, pre_kernel_launch="my_script.sh"):
...
contents = ""
for key, value in env.items():
contents += f'export {key}="{value}"\n'
with open(pre_kernel_launch_script) as f:
contents += "\n"
contents += f.read()
...
with open(sys.executable, "w") as f:
f.write(
f"""
#!/bin/bash
{contents} # this is the new change!
source {prefix}/etc/profile.d/conda.sh
conda activate
unset PYTHONPATH
mv /usr/bin/lsb_release /usr/bin/lsb_release.renamed_by_condacolab.bak
exec {bin_path}/python $@
"""
cc @ssurbhi560