Skip to content

Commit

Permalink
fix: allow absolute paths for notebooks
Browse files Browse the repository at this point in the history
  • Loading branch information
maartenbreddels committed Jan 25, 2019
1 parent ddb60c0 commit 3bbad07
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions voila/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from jupyter_server.services.config import ConfigManager
from jupyter_server.base.handlers import FileFindHandler
from jupyter_core.paths import jupyter_config_path, jupyter_path
from ipython_genutils.py3compat import getcwd

from .paths import ROOT, STATIC_ROOT, collect_template_paths
from .handler import VoilaHandler
Expand Down Expand Up @@ -71,6 +72,9 @@ class VoilaBase(Application):
config=True,
help='Will autoreload to server and the page when a template, js file or Python code changes'
)
root_dir = Unicode(config=True,
help="The directory to use for notebooks."
)
static_root = Unicode(
STATIC_ROOT,
config=True,
Expand Down Expand Up @@ -126,6 +130,13 @@ def nbextensions_path(self):
path.append(os.path.join(get_ipython_dir(), 'nbextensions'))
return path

@default('root_dir')
def _default_root_dir(self):
if self.notebook_path:
return os.path.dirname(os.path.abspath(self.notebook_path))
else:
return getcwd()

def parse_command_line(self, argv=None):
super(VoilaBase, self).parse_command_line(argv)
self.notebook_path = self.extra_args[0] if len(self.extra_args) == 1 else None
Expand Down Expand Up @@ -167,7 +178,7 @@ def start(self):
env = jinja2.Environment(loader=jinja2.FileSystemLoader(self.template_paths), extensions=['jinja2.ext.i18n'], **jenv_opt)
nbui = gettext.translation('nbui', localedir=os.path.join(ROOT, 'i18n'), fallback=True)
env.install_gettext_translations(nbui, newstyle=False)
contents_manager = LargeFileManager() # TODO: make this configurable like notebook
contents_manager = LargeFileManager(parent=self) # TODO: make this configurable like notebook

# we create a config manager that load both the serverconfig and nbconfig (classical notebook)
read_config_path = [os.path.join(p, 'serverconfig') for p in jupyter_config_path()]
Expand Down Expand Up @@ -220,7 +231,7 @@ def start(self):
url_path_join(base_url, r'/'),
VoilaHandler,
{
'notebook_path': self.notebook_path,
'notebook_path': os.path.relpath(self.notebook_path, self.root_dir),
'strip_sources': self.strip_sources,
'nbconvert_template_paths': self.nbconvert_template_paths,
'config': self.config
Expand Down

0 comments on commit 3bbad07

Please sign in to comment.