import os def get_server_root_dir(settings): # notebook >= 5.0.0 has this in the settings if 'server_root_dir' in settings: return settings['server_root_dir'] # This copies the logic added in the notebook in # https://github.com/jupyter/notebook/pull/2234 contents_manager = settings['contents_manager'] root_dir = contents_manager.root_dir home = os.path.expanduser('~') if root_dir.startswith(home + os.path.sep): # collapse $HOME to ~ root_dir = '~' + root_dir[len(home):] return root_dir