mirror of
https://github.com/jupyter/notebook.git
synced 2024-12-15 04:00:34 +08:00
Merge pull request #433 from captainsafia/title-double-backslash
Strip trailing slash from notebook_dir
This commit is contained in:
commit
009ae06e66
@ -754,15 +754,19 @@ class NotebookApp(JupyterApp):
|
||||
else:
|
||||
return py3compat.getcwd()
|
||||
|
||||
def _notebook_dir_validate(self, value, trait):
|
||||
# Strip any trailing slashes
|
||||
value = value.rstrip(os.sep)
|
||||
|
||||
if not os.path.isabs(value):
|
||||
# If we receive a non-absolute path, make it absolute.
|
||||
value = os.path.abspath(value)
|
||||
if not os.path.isdir(value):
|
||||
raise TraitError("No such notebook dir: %r" % value)
|
||||
return value
|
||||
|
||||
def _notebook_dir_changed(self, name, old, new):
|
||||
"""Do a bit of validation of the notebook dir."""
|
||||
if not os.path.isabs(new):
|
||||
# If we receive a non-absolute path, make it absolute.
|
||||
self.notebook_dir = os.path.abspath(new)
|
||||
return
|
||||
if not os.path.isdir(new):
|
||||
raise TraitError("No such notebook dir: %r" % new)
|
||||
|
||||
# setting App.notebook_dir implies setting notebook and kernel dirs as well
|
||||
self.config.FileContentsManager.root_dir = new
|
||||
self.config.MappingKernelManager.root_dir = new
|
||||
|
@ -62,6 +62,11 @@ def test_invalid_nb_dir():
|
||||
with nt.assert_raises(TraitError):
|
||||
app.notebook_dir = tf
|
||||
|
||||
def test_nb_dir_with_slash():
|
||||
with TemporaryDirectory(suffix="_slash/") as td:
|
||||
app = NotebookApp(notebook_dir=td)
|
||||
nt.assert_false(app.notebook_dir.endswith("/"))
|
||||
|
||||
def test_generate_config():
|
||||
with TemporaryDirectory() as td:
|
||||
app = NotebookApp(config_dir=td)
|
||||
@ -69,4 +74,4 @@ def test_generate_config():
|
||||
with nt.assert_raises(NoStart):
|
||||
app.start()
|
||||
assert os.path.exists(os.path.join(td, 'jupyter_notebook_config.py'))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user