Set environment variables based on user - for example, use $HOME

Hi, I’m a Jupyterhub newbie. I’m setting up a jupyterhub and I’d like to set a user dependent variable, one that depends on $HOME.

I now have changed jupyterhub_config.py to include:

def homeproj(instance):
  import os
  return os.path.expanduser('~' + instance.user.name + '/proj')

c.Spawner.environment = { "PROJ_LIB":homeproj }

This works. Is this the “right” way to do this? Or are there better/easier ways?

Assuming os.path.expanduser('~' + instance.user.name + '/proj') returns the correct value that approach looks fine to me. c.Spawner.environment is designed to take callables to suport dynamic environment values: