Skip to content
This repository was archived by the owner on Jan 30, 2023. It is now read-only.

Commit

Permalink
Make doctests work even if you never ran the ipython notebook before
Browse files Browse the repository at this point in the history
  • Loading branch information
vbraun committed Oct 8, 2014
1 parent 9d034cc commit 11326b6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/bin/sage-notebook
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,12 @@ class NotebookSageNB(object):
class NotebookIPython(object):

def __init__(self, argv):
self._make_notebook_dir()
from sage.repl.notebook_ipython import SageNotebookApp
from sage.repl.notebook_ipython import SageNotebookApp, make_notebook_dir
make_notebook_dir()
app = SageNotebookApp.instance()
app.initialize(argv)
app.start()

def _make_notebook_dir(self):
# The IPython notebook directory must exist
from sage.repl.notebook_ipython import NOTEBOOK_DIR
if not os.path.exists(NOTEBOOK_DIR):
os.makedirs(NOTEBOOK_DIR)


description = \
"""
Expand Down
14 changes: 14 additions & 0 deletions src/sage/repl/notebook_ipython.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@
# The directory where all Sage IPython Notebooks files are stored
NOTEBOOK_DIR = os.path.join(DOT_SAGE, 'notebooks_ipython')

def make_notebook_dir():
"""
Ensure that the IPython notebook directory exists.
EXAMPLES::
sage: from sage.repl.notebook_ipython import make_notebook_dir, NOTEBOOK_DIR
sage: make_notebook_dir()
sage: assert os.path.isdir(NOTEBOOK_DIR)
"""
if not os.path.exists(NOTEBOOK_DIR):
os.makedirs(NOTEBOOK_DIR)


# The notebook Jinja2 templates and static files
TEMPLATE_PATH = os.path.join(SAGE_EXTCODE, 'notebook-ipython', 'templates')
Expand Down Expand Up @@ -67,6 +80,7 @@ def load_config_file(self, *args, **kwds):
True
sage: os.environ['IPYTHONDIR'] = IPYTHONDIR
"""
make_notebook_dir()
super(SageNotebookApp, self).load_config_file(*args, **kwds)
newconfig = copy.deepcopy(DEFAULT_SAGE_CONFIG)
newconfig.merge(DEFAULT_SAGE_NOTEBOOK_CONFIG)
Expand Down

0 comments on commit 11326b6

Please sign in to comment.