How to init content of notebooks / working directory in Jupyterhub/Jupyterlab?

后端 未结 1 1377
忘掉有多难
忘掉有多难 2021-01-17 00:34

If I create a new user in JupyterHub I want that the working directory of the corresponding JupyterLab instance is initialized with some getting started examples:

1条回答
  •  有刺的猬
    2021-01-17 01:16

    The Spawner provides some hook functions in the configuration file jupyterhub_config.py. And its possible to get the current user name from within the hook function.

    import subprocess
    
    def git(*args):
        return subprocess.check_call(['git'] + list(args))
        
    def init_working_directory(spawner):
        username = spawner.user.name
        git_source = 'https://$user:$password@gitlab.server.de/my/project'
        target_folder = '/home/' + username + '/GettingStarted'
        git('clone', git_source, target_folder)
        
    c.Spawner.pre_spawn_hook = init_working_directory
    

    There are a few issues left:

    a) The git clone command only works the first time, when the folder /home/username/GettingStarted does not yet exist.

    b) There is no progress bar shown during the delayed log and the git clone command takes a while.

    c) Git password might be shown in error messages/console.

    Therefore, I will initially do the git clone when creating my Docker container and only perform a local copy in pre_spawn_hook if the GettingStarted folder does not yet exist.

    0 讨论(0)
提交回复
热议问题