diff --git a/voila/app.py b/voila/app.py index ac5de5639..c383a0497 100644 --- a/voila/app.py +++ b/voila/app.py @@ -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 @@ -71,6 +72,9 @@ class Voila(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, @@ -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(Voila, self).parse_command_line(argv) self.notebook_path = self.extra_args[0] if len(self.extra_args) == 1 else None @@ -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()] @@ -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