Skip to content

Commit

Permalink
Update code format
Browse files Browse the repository at this point in the history
  • Loading branch information
trungleduc committed Oct 4, 2021
1 parent e3d8a3e commit f14a5ea
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 50 deletions.
2 changes: 1 addition & 1 deletion tests/app/cgi-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def notebook_cgi_path(base_url, preheat_mode):
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory,NOTEBOOK_PATH),
os.path.join(notebook_directory, NOTEBOOK_PATH),
'--VoilaTest.log_level=DEBUG'
] + voila_args_extra

Expand Down
10 changes: 7 additions & 3 deletions tests/app/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class VoilaTest(voila.app.Voila):
def listen(self):
pass # the ioloop is taken care of by the pytest-tornado framework


@pytest.fixture
def voila_config():
return lambda app: None
Expand All @@ -31,6 +32,7 @@ def voila_args(voila_notebook, voila_args_extra, voila_config_file_paths_arg):
debug_args = ['--VoilaTest.log_level=DEBUG'] if os.environ.get('VOILA_TEST_DEBUG', False) else []
return [voila_notebook, voila_config_file_paths_arg] + voila_args_extra + debug_args


@pytest.fixture(params=[False, True])
def preheat_mode(request):
"""Fixture used to activate/deactivate pre-heat kernel mode.
Expand All @@ -39,13 +41,14 @@ def preheat_mode(request):
"""
return request.param


@pytest.fixture
def preheat_config(preheat_mode):
return f'--preheat_kernel={preheat_mode}'


@pytest.fixture
def voila_app( voila_args, voila_config, preheat_config):
def voila_app(voila_args, voila_config, preheat_config):
voila_app = VoilaTest.instance()
voila_app.initialize(voila_args + ['--no-browser', preheat_config])
voila_config(voila_app)
Expand All @@ -59,10 +62,11 @@ def voila_app( voila_args, voila_config, preheat_config):
def app(voila_app):
return voila_app.app


@pytest.fixture
def wait_for_kernel(preheat_mode):
"""Wait for kernel be heated in case of `preheat_mode = True`"""
async def inner(time=1):
if preheat_mode:
await asyncio.sleep(time)
return inner
return inner
1 change: 1 addition & 0 deletions tests/app/cwd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os


@pytest.fixture
def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, 'cwd.ipynb')
Expand Down
3 changes: 2 additions & 1 deletion tests/app/execute_cpp_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
TEST_XEUS_CLING = os.environ.get('VOILA_TEST_XEUS_CLING', '') == '1'
NOTEBOOK_PATH = 'print.xcpp'


@pytest.fixture
def cpp_file_url(base_url, preheat_mode):
if preheat_mode:
Expand All @@ -19,7 +20,7 @@ def voila_args_extra():
@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory,NOTEBOOK_PATH) ] + voila_args_extra
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra


Expand Down
1 change: 1 addition & 0 deletions tests/app/image_inlining_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

NOTEBOOK_PATH = 'images.ipynb'


@pytest.fixture
def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, NOTEBOOK_PATH)
Expand Down
5 changes: 3 additions & 2 deletions tests/app/no_kernelspec_test.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest
import os
import os


NOTEBOOK_PATH = 'no_kernelspec.ipynb'

Expand All @@ -14,7 +15,7 @@ def non_existing_kernel_notebook(base_url, preheat_mode):
@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory,NOTEBOOK_PATH)] + voila_args_extra
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra

return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra

Expand Down
2 changes: 1 addition & 1 deletion tests/app/no_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def non_existing_notebook_metadata(base_url, preheat_mode):
@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory,NOTEBOOK_PATH)] + voila_args_extra
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
return ['--VoilaTest.root_dir=%r' % notebook_directory] + voila_args_extra


Expand Down
2 changes: 1 addition & 1 deletion tests/app/non_existing_kernel_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def non_existing_kernel_notebook(base_url, preheat_mode):
@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [os.path.join(notebook_directory,NOTEBOOK_PATH)] + voila_args_extra
return [os.path.join(notebook_directory, NOTEBOOK_PATH)] + voila_args_extra
return ["--VoilaTest.root_dir=%r" % notebook_directory] + voila_args_extra


Expand Down
2 changes: 1 addition & 1 deletion tests/app/notebooks_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def notebook_other_comms_path(base_url, preheat_mode):
def voila_args(notebook_directory, voila_args_extra, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory,NOTEBOOK_PATH),
os.path.join(notebook_directory, NOTEBOOK_PATH),
'--VoilaTest.log_level=DEBUG',
] + voila_args_extra
return [
Expand Down
3 changes: 3 additions & 0 deletions tests/app/preheat_activation_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@
import asyncio
import os


@pytest.fixture
def preheat_mode():
return True


@pytest.fixture
def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, 'pre_heat.ipynb')


NOTEBOOK_EXECUTION_TIME = 2


Expand Down
9 changes: 5 additions & 4 deletions tests/app/preheat_configuration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import os

BASE_DIR = os.path.dirname(__file__)
NOTEBOOK_EXECUTION_TIME = 2
NUMBER_PREHEATED_KERNEL = 2


@pytest.fixture
def voila_config_file_paths_arg():
Expand All @@ -15,12 +18,11 @@ def voila_config_file_paths_arg():
def preheat_mode():
return True


@pytest.fixture
def voila_notebook(notebook_directory):
return os.path.join(notebook_directory, 'pre_heat.ipynb')

NOTEBOOK_EXECUTION_TIME = 2
NUMBER_PREHEATED_KERNEL = 2

async def send_request(sc, url, wait=0):
await asyncio.sleep(wait)
Expand All @@ -41,7 +43,7 @@ async def test_refill_kernel_asynchronously(http_server_client, base_url):
fast.append(time)
else:
slow.append(time)

assert len(fast) > 1
assert len(slow) > 1
assert len(fast) + len(slow) == 5*NUMBER_PREHEATED_KERNEL
Expand All @@ -51,4 +53,3 @@ async def test_env_variable_defined_in_kernel(http_server_client, base_url):
await asyncio.sleep(NUMBER_PREHEATED_KERNEL*NOTEBOOK_EXECUTION_TIME + 1)
_, text = await send_request(sc=http_server_client, url=base_url)
assert "bar" in text

3 changes: 3 additions & 0 deletions tests/app/serve_directory_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
import os
import pytest


TEST_XEUS_CLING = os.environ.get('VOILA_TEST_XEUS_CLING', '') == '1'


@pytest.fixture
def preheat_mode():
return False


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra):
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra
Expand Down
4 changes: 3 additions & 1 deletion tests/app/show_traceback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@
def show_tracebacks(request):
return request.param


@pytest.fixture
def notebook_show_traceback_path(base_url, preheat_mode):
if preheat_mode:
return base_url
return base_url + f'voila/render/{NOTEBOOK_PATH}'


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra, show_tracebacks, preheat_mode):
if preheat_mode:
return [
os.path.join(notebook_directory,NOTEBOOK_PATH),
os.path.join(notebook_directory, NOTEBOOK_PATH),
f'--VoilaConfiguration.show_tracebacks={show_tracebacks}',
] + voila_args_extra
return [
Expand Down
1 change: 1 addition & 0 deletions tests/app/tree_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
def preheat_mode():
return False


@pytest.fixture
def voila_args(notebook_directory, voila_args_extra):
return ['--VoilaTest.root_dir=%r' % notebook_directory, '--VoilaTest.log_level=DEBUG'] + voila_args_extra
Expand Down
4 changes: 0 additions & 4 deletions voila/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ def start(self):
read_config_path += [os.path.join(p, 'nbconfig') for p in jupyter_config_path()]
self.config_manager = ConfigManager(parent=self, read_config_path=read_config_path)
self.contents_manager = LargeFileManager(parent=self)

preheat_kernel = self.notebook_path is not None and self.voila_configuration.preheat_kernel
kernel_manager_class = voila_kernel_manager_factory(
self.voila_configuration.multi_kernel_manager_class,
Expand All @@ -440,9 +439,6 @@ 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)




# default server_url to base_url
self.server_url = self.server_url or self.base_url
Expand Down
2 changes: 1 addition & 1 deletion voila/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ async def get(self, path=None):
try:
notebook_html_dict: Dict = self.kernel_manager.notebook_html
notebook_data: Dict = self.kernel_manager.notebook_data.get(notebook_path, {})
except:
except Exception:
# Extension mode
notebook_html_dict = notebook_data = {}
# If we have a heated kernel in pool, use it
Expand Down
7 changes: 3 additions & 4 deletions voila/notebook_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
from nbconvert.preprocessors import ClearOutputPreprocessor
from traitlets.config.configurable import LoggingConfigurable

from ._version import __version__
from .execute import VoilaExecutor, strip_code_cell_warnings
from .exporter import VoilaExporter
from .paths import collect_template_paths


class NotebookRenderer(LoggingConfigurable):
"""Render the notebook into HTML string."""
"""Render the notebook into HTML string."""

def __init__(self, **kwargs):
super().__init__()
Expand Down Expand Up @@ -159,7 +158,7 @@ def inner_cell_generator(nb, kernel_id):
# These functions allow the start of a kernel and execution of the
# notebook after (parts of) the template has been rendered and send
# to the client to allow progressive rendering.
# Template should first call kernel_start, and then decide to use
# Template should first call kernel_start, and then decide to use
# notebook_executer cell_generator to implement progressive cell rendering

extra_context = {
Expand Down Expand Up @@ -209,7 +208,7 @@ async def _jinja_kernel_start(self, nb, kernel_id, kernel_future):
async def _jinja_notebook_execute(self, nb, kernel_id):

result = await self.executor.async_execute(cleanup_kc=False)
# we modify the notebook in place, since the nb variable cannot be
# we modify the notebook in place, since the nb variable cannot be
# reassigned it seems in jinja2 e.g. if we do {% with nb = notebook_execute(nb, kernel_id) %}
# ,the base template/blocks will not see the updated variable
# (it seems to be local to our block)
Expand Down
1 change: 0 additions & 1 deletion voila/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import os



def get_server_root_dir(settings):
# notebook >= 5.0.0 has this in the settings
if 'server_root_dir' in settings:
Expand Down
Loading

0 comments on commit f14a5ea

Please sign in to comment.