mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
API: Allow NotebookManagers to control kernel startup dir. #5468
This commit is contained in:
parent
78bc36ec38
commit
27a77dedbd
@ -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
|
||||||
|
@ -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)
|
||||||
|
@ -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.
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
Loading…
Reference in New Issue
Block a user