jupyterhub / batchspawner

Custom Spawner for Jupyterhub to start servers in batch scheduled systems
BSD 3-Clause "New" or "Revised" License
190 stars 134 forks source link

Allow setting PATH variable for each user dynamically #181

Open yuvipanda opened 4 years ago

yuvipanda commented 4 years ago

I have a conda environment per user in their home directory. so PATH needs to be something like PATH=/home/{username}/conda/bin:$PATH. However, currently there seems to be no way to do this, since username expansion isn't supported in environment files - plus PATH doesn't seem to be passed through to the spawned notebook (on Slurm at least)

Proposed change

  1. Allow username expansion via {username} or similar in PATH
  2. Add a separate traitlet just for PATH, similar to systemdspawner

Alternative options

Currently, I use the following to get what I want:

class CustomSlurmSpawner(SlurmSpawner):
    def start(self, *args, **kwargs):
        self.req_prologue = f'export PATH=/home/{self.user.name}/conda/bin:$PATH'
        return super().start(*args, **kwargs)

c.JupyterHub.spawner_class = CustomSlurmSpawner

Who would use this feature?

People who have per-user conda environments

welcome[bot] commented 4 years ago

Thank you for opening your first issue in this project! Engagement like this is essential for open source projects! :hugs:
If you haven't done so already, check out Jupyter's Code of Conduct. Also, please try to follow the issue template as it helps other other community members to contribute more effectively. welcome You can meet the other Jovyans by joining our Discourse forum. There is also an intro thread there where you can stop by and say Hi! :wave:
Welcome to the Jupyter community! :tada:

rkdarst commented 4 years ago

req_prologue is a configurable trait, so does c.BatchSpawner.req_prolog = "source $HOME/conda/bin/activate" or even the direct path things work? The script is a shell script so you should be able to do almost anything you need (I do many things like this, too), using $USER, $HOME, etc.

rcthomas commented 4 years ago

This seems like something that needs to be configured on a per-user basis, since conda environments (or whatever) could be anywhere.

rkdarst commented 4 years ago

I was going to add a {username} substitution because it seemed pretty useful, but it looks like it's already there. Did you try it?