diff --git a/IPython/html/notebookapp.py b/IPython/html/notebookapp.py
index b216eca..028de8b 100644
--- a/IPython/html/notebookapp.py
+++ b/IPython/html/notebookapp.py
@@ -344,11 +344,6 @@ class NotebookApp(BaseIPythonApplication):
# file to be opened in the notebook server
file_to_run = Unicode('', config=True)
- def _file_to_run_changed(self, name, old, new):
- path, base = os.path.split(new)
- if path:
- self.file_to_run = base
- self.notebook_dir = path
# Network related information
@@ -627,10 +622,6 @@ class NotebookApp(BaseIPythonApplication):
info_file = "nbserver-%s.json"%os.getpid()
return os.path.join(self.profile_dir.security_dir, info_file)
- notebook_dir = Unicode(py3compat.getcwd(), config=True,
- help="The directory to use for notebooks and kernels."
- )
-
pylab = Unicode('disabled', config=True,
help="""
DISABLED: use %pylab or %matplotlib in the notebook to enable matplotlib.
@@ -648,6 +639,16 @@ class NotebookApp(BaseIPythonApplication):
)
self.exit(1)
+ notebook_dir = Unicode(config=True,
+ help="The directory to use for notebooks and kernels."
+ )
+
+ def _notebook_dir_default(self):
+ if self.file_to_run:
+ return os.path.dirname(os.path.abspath(self.file_to_run))
+ else:
+ return py3compat.getcwd()
+
def _notebook_dir_changed(self, name, old, new):
"""Do a bit of validation of the notebook dir."""
if not os.path.isabs(new):
@@ -942,12 +943,12 @@ class NotebookApp(BaseIPythonApplication):
browser = None
if self.file_to_run:
- fullpath = os.path.join(self.notebook_dir, self.file_to_run)
- if not os.path.exists(fullpath):
- self.log.critical("%s does not exist" % fullpath)
+ if not os.path.exists(self.file_to_run):
+ self.log.critical("%s does not exist" % self.file_to_run)
self.exit(1)
-
- uri = url_path_join('notebooks', self.file_to_run)
+
+ relpath = os.path.relpath(self.file_to_run, self.notebook_dir)
+ uri = url_path_join('notebooks', *relpath.split(os.sep))
else:
uri = 'tree'
if browser:
diff --git a/IPython/html/services/contents/filemanager.py b/IPython/html/services/contents/filemanager.py
index 2030cb4..da91672 100644
--- a/IPython/html/services/contents/filemanager.py
+++ b/IPython/html/services/contents/filemanager.py
@@ -23,7 +23,13 @@ from IPython.html.utils import is_hidden, to_os_path, url_path_join
class FileContentsManager(ContentsManager):
- root_dir = Unicode(getcwd(), config=True)
+ root_dir = Unicode(config=True)
+
+ def _root_dir_default(self):
+ try:
+ return self.parent.notebook_dir
+ except AttributeError:
+ return getcwd()
save_script = Bool(False, config=True, help='DEPRECATED, IGNORED')
def _save_script_changed(self):
diff --git a/IPython/html/services/kernels/kernelmanager.py b/IPython/html/services/kernels/kernelmanager.py
index d135b13..e1bd5c2 100644
--- a/IPython/html/services/kernels/kernelmanager.py
+++ b/IPython/html/services/kernels/kernelmanager.py
@@ -12,7 +12,7 @@ import os
from tornado import web
from IPython.kernel.multikernelmanager import MultiKernelManager
-from IPython.utils.traitlets import Unicode, TraitError
+from IPython.utils.traitlets import List, Unicode, TraitError
from IPython.html.utils import to_os_path
from IPython.utils.py3compat import getcwd
@@ -24,7 +24,15 @@ class MappingKernelManager(MultiKernelManager):
def _kernel_manager_class_default(self):
return "IPython.kernel.ioloop.IOLoopKernelManager"
- root_dir = Unicode(getcwd(), config=True)
+ kernel_argv = List(Unicode)
+
+ root_dir = Unicode(config=True)
+
+ def _root_dir_default(self):
+ try:
+ return self.parent.notebook_dir
+ except AttributeError:
+ return getcwd()
def _root_dir_changed(self, name, old, new):
"""Do a bit of validation of the root dir."""