API: Allow NotebookManagers to control kernel startup dir. #5468

This commit is contained in:
Dale Jung 2014-03-29 17:39:15 -04:00
parent 78bc36ec38
commit 27a77dedbd
4 changed files with 19 additions and 5 deletions

View File

@ -63,6 +63,10 @@ class MappingKernelManager(MultiKernelManager):
def cwd_for_path(self, path): def cwd_for_path(self, path):
"""Turn API path into absolute OS path.""" """Turn API path into absolute OS path."""
# short circuit for NotebookManagers that pass in absolute paths
if os.path.exists(path):
return path
os_path = to_os_path(path, self.root_dir) os_path = to_os_path(path, self.root_dir)
# in the case of notebooks and kernels not being on the same filesystem, # in the case of notebooks and kernels not being on the same filesystem,
# walk up to root_dir if the paths don't exist # walk up to root_dir if the paths don't exist

View File

@ -492,3 +492,7 @@ class FileNotebookManager(NotebookManager):
def info_string(self): def info_string(self):
return "Serving notebooks from local directory: %s" % self.notebook_dir return "Serving notebooks from local directory: %s" % self.notebook_dir
def get_kernel_path(self, name, path='', model=None):
""" Return the path to start kernel in """
return os.path.join(self.notebook_dir, path)

View File

@ -168,6 +168,10 @@ class NotebookManager(LoggingConfigurable):
# NotebookManager API part 2: methods that have useable default # NotebookManager API part 2: methods that have useable default
# implementations, but can be overridden in subclasses. # implementations, but can be overridden in subclasses.
def get_kernel_path(self, name, path='', model=None):
""" Return the path to start kernel in """
return path
def increment_filename(self, basename, path=''): def increment_filename(self, basename, path=''):
"""Increment a notebook filename without the .ipynb to make it unique. """Increment a notebook filename without the .ipynb to make it unique.

View File

@ -62,7 +62,9 @@ class SessionRootHandler(IPythonHandler):
if sm.session_exists(name=name, path=path): if sm.session_exists(name=name, path=path):
model = sm.get_session(name=name, path=path) model = sm.get_session(name=name, path=path)
else: else:
kernel_id = km.start_kernel(path=path) # allow nbm to specify kernels cwd
kernel_path = nbm.get_kernel_path(name=name, path=path)
kernel_id = km.start_kernel(path=kernel_path)
model = sm.create_session(name=name, path=path, kernel_id=kernel_id) model = sm.create_session(name=name, path=path, kernel_id=kernel_id)
location = url_path_join(self.base_url, 'api', 'sessions', model['id']) location = url_path_join(self.base_url, 'api', 'sessions', model['id'])
self.set_header('Location', url_escape(location)) self.set_header('Location', url_escape(location))