Skip to content

Commit 3684ff7

Browse files
committed
Be more careful about where we stick init lines (see below).
Before, run.py was formatting all of the sign-in lines and plot-calls. Now, these things happen in the code_translator. Therefore, we need to actually insert lines into the code we get back for the initializations to happen in a reasonable order.
1 parent 979bcb6 commit 3684ff7

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

run.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ def process_model_worker(leaf, language, model):
649649
code = code.replace("<pre>", "").replace("</pre>", "")
650650
code = code.replace('">>>', "").replace('<<<"', "")
651651
code = code.replace("'>>>", "").replace("<<<'", "")
652-
raw_exec_code = init + remove_header(code)
652+
headless_exec_code = remove_header(code)
653+
raw_exec_code = insert_init(headless_exec_code, init, language)
653654
save_code(raw_exec_code, leaf, language, 'execution')
654655
if language == 'python':
655656
leaf['python-exec'] = raw_exec_code
@@ -667,13 +668,29 @@ def process_model_worker(leaf, language, model):
667668
code = code.replace("<pre>", "").replace("</pre>", "")
668669
code = code.replace('">>>', "").replace('<<<"', "")
669670
code = code.replace("'>>>", "").replace("<<<'", "")
670-
raw_doc_code = init + remove_header(code)
671+
headless_doc_code = remove_header(code)
672+
raw_doc_code = insert_init(headless_doc_code, init, language)
671673
doc_code = format_code(raw_doc_code, language, leaf)
672674
code_path = save_code(doc_code, leaf, language, 'documentation')
673675
# do this last so we know it worked!
674676
leaf[language] = code_path
675677

676678

679+
def insert_init(code, init, language):
680+
lines = code.splitlines()
681+
sign_in_lino = -1
682+
for lino, line in enumerate(lines):
683+
if line[:6] == sign_in['execution'][language][:6]:
684+
sign_in_lino = lino
685+
break
686+
# FIXME: HACK! needs updating in streambed...
687+
elif language == 'r' and line[:6] == 'p <- plotly('[:6]:
688+
sign_in_lino = lino
689+
break
690+
new_lines = lines[:sign_in_lino+1] + [init] + lines[sign_in_lino+1:]
691+
return '\n'.join(new_lines)
692+
693+
677694
def process_script_leaf(leaf, options, id_dict):
678695
"""
679696
1. for each language with 'model' as the *source*...

0 commit comments

Comments
 (0)