Skip to content

Commit 5be42d1

Browse files
committed
Added remote heleper method for inline jupyter evaluate
1 parent 67c634d commit 5be42d1

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

appyter/remote/nbviewer.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
import json
3+
import tempfile
4+
from subprocess import Popen, PIPE
5+
6+
from appyter.context import get_env, get_jinja2_env
7+
from appyter.render.nbviewer import render_nb_from_stream
8+
9+
def jupyter_inline_evaluate(url, context):
10+
def stream_generator():
11+
with tempfile.NamedTemporaryFile('w') as tmp:
12+
tmp.close()
13+
with open(tmp.name, 'w') as fw:
14+
json.dump(context, fw)
15+
16+
with Popen([
17+
sys.executable,
18+
'-u',
19+
'-m', 'appyter',
20+
'remote', 'nbevaluate',
21+
f"--context={tmp.name}",
22+
url,
23+
], stdout=PIPE, stderr=PIPE) as proc:
24+
packet = proc.stderr.readline()
25+
while packet:
26+
yield packet.decode()
27+
packet = proc.stderr.readline()
28+
29+
env = get_jinja2_env(get_env(**dict(ipynb='app.ipynb')))
30+
render_nb_from_stream(env, stream_generator())

0 commit comments

Comments
 (0)