Skip to content
This repository was archived by the owner on Sep 3, 2024. It is now read-only.

Fix import without mywb #42

Merged
merged 1 commit into from
May 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,4 @@ dist/
__pycache__/
etc/notebooks/*
.DS_Store
.ipynb_checkpoints/
17 changes: 9 additions & 8 deletions jupyter_cms/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,15 +238,16 @@ def find_module(self, fullname, path=None):
'''
Find a notebook, given its fully qualified name and an optional path
'''
# print '*** finding fullname:', fullname, 'path:', path
name = fullname.rsplit('.', 1)[-1]
path = [''] if path is None or not len(path) else path
fullpath = os.path.join(*path)

nb_path = os.path.join(fullpath, name + ".ipynb")
loader = None
if os.path.isfile(nb_path):
loader = self.loader_cls(path, nb_path)
# print('*** finding fullname:', fullname, 'path:', path)
if fullname.startswith('mywb.'):
name = fullname.rsplit('.', 1)[-1]
path = [''] if path is None or not len(path) else path
fullpath = os.path.join(*path)

nb_path = os.path.join(fullpath, name + ".ipynb")
if os.path.isfile(nb_path):
loader = self.loader_cls(path, nb_path)
return loader

class NotebookPathFinder(object):
Expand Down
15 changes: 15 additions & 0 deletions test/test_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,21 @@ def test_general_not_found(self):
pass
else:
self.assertTrue(False, 'expected ImportError')

def test_cwd_notebook(self):
'''Should not import a notebook in the cwd.'''
# switch to resources so that notebook are in the cwd
path = os.getcwd()
os.chdir(self.root)
try:
import test_injectable as mod
except ImportError as e:
pass
else:
self.assertTrue(False, 'expected ImportError')
finally:
os.chdir(path)


class TestNotebookLoader(unittest.TestCase):
'''Tests for loading notebooks within the loader root directory.'''
Expand Down