batchspawner icon indicating copy to clipboard operation
batchspawner copied to clipboard

Allow setting PATH variable for each user dynamically

Open yuvipanda opened this issue 5 years ago • 4 comments

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

yuvipanda avatar Jul 22 '20 18:07 yuvipanda

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:

welcome[bot] avatar Jul 22 '20 18:07 welcome[bot]

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.

rkdarst avatar Jul 22 '20 18:07 rkdarst

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

rcthomas avatar Jul 22 '20 18:07 rcthomas

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?

rkdarst avatar Jul 22 '20 18:07 rkdarst