Skip to content

Commit

Permalink
Fix file redirect error
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Jan 24, 2022
1 parent bf2c328 commit ec6ad68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
5 changes: 4 additions & 1 deletion voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ async def get_generator(self, path=None):
kernel_spec_manager=self.kernel_spec_manager,
)

await gen.initialize(template=template_arg, theme=theme_arg)
done = await gen.initialize(template=template_arg, theme=theme_arg)
if not done:
self.redirect_to_file(path)
return

def time_out():
"""If not done within the timeout, we send a heartbeat
Expand Down
13 changes: 10 additions & 3 deletions voila/notebook_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import sys
import traceback
from typing import Generator, Tuple, Union, List

import nbformat
import tornado.web
from jupyter_server.config_manager import recursive_update
Expand Down Expand Up @@ -46,8 +45,14 @@ def __init__(self, **kwargs):
self.stop_generator = False
self.rendered_cache: List[str] = []

async def initialize(self, **kwargs):
async def initialize(self, **kwargs) -> bool:
""" Initialize the notebook generator, this method will
return `True` if the generator is initialized, return `False`
otherwise.
Returns:
Boolean: The flag to check if the generator is initialized.
"""
notebook_path = self.notebook_path
if self.voila_configuration.enable_nbextensions:
# generate a list of nbextensions that are enabled for the classical notebook
Expand All @@ -68,7 +73,7 @@ async def initialize(self, **kwargs):
self.notebook = await self.load_notebook(notebook_path)

if not self.notebook:
return
return False
self.cwd = os.path.dirname(notebook_path)

_, basename = os.path.split(notebook_path)
Expand Down Expand Up @@ -145,6 +150,8 @@ async def initialize(self, **kwargs):
self.exporter.exclude_output_prompt = True
self.exporter.exclude_input_prompt = True

return True

def generate_content_generator(
self,
kernel_id: Union[str, None] = None,
Expand Down

0 comments on commit ec6ad68

Please sign in to comment.