Skip to content

Commit

Permalink
Simplify some code (#1329)
Browse files Browse the repository at this point in the history
* Use partial

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove unneeded inner_cell_generator function

* Change comments a bit

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: martinRenou <[email protected]>
  • Loading branch information
3 people authored Aug 1, 2023
1 parent a2453b3 commit f7a74cc
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions voila/notebook_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import sys
import traceback
from functools import partial
from copy import deepcopy
from typing import Generator, List, Tuple, Union

Expand Down Expand Up @@ -154,23 +155,21 @@ def generate_content_generator(
kernel_id: Union[str, None] = None,
kernel_future=None,
) -> Generator:
async def inner_kernel_start(nb):
return await self._jinja_kernel_start(nb, kernel_id, kernel_future)

def inner_cell_generator(nb, kernel_id):
return self._jinja_cell_generator(nb, kernel_id)
inner_kernel_start = partial(
self._jinja_kernel_start, kernel_id=kernel_id, kernel_future=kernel_future
)

# These functions allow the start of a kernel and execution of the
# notebook after (parts of) the template has been rendered and send
# kernel_start and cell_generator allow starting the kernel and executing the
# notebook after (parts of) the template has been rendered and sent
# to the client to allow progressive rendering.
# Template should first call kernel_start, and then decide to use
# notebook_executer cell_generator to implement progressive cell rendering
# notebook_executer cell_generator to implement progressive cell rendering.

extra_context = {
"frontend": "voila",
"main_js": "voila.js",
"kernel_start": inner_kernel_start,
"cell_generator": inner_cell_generator,
"cell_generator": self._jinja_cell_generator,
"notebook_execute": self._jinja_notebook_execute,
}
# render notebook in snippets, then return an iterator so we can flush
Expand Down

0 comments on commit f7a74cc

Please sign in to comment.