condacolab icon indicating copy to clipboard operation
condacolab copied to clipboard

Revamp `env` kwarg in new implementation and provide pre launch logic

Open jaimergp opened this issue 2 years ago • 1 comments

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 $@
      """

jaimergp avatar Oct 20 '22 10:10 jaimergp

cc @ssurbhi560

jaimergp avatar Oct 20 '22 10:10 jaimergp