Skip to content

Commit 9c12cc9

Browse files
committed
rebuild and retest
1 parent 9ebdab5 commit 9c12cc9

File tree

6 files changed

+121
-59
lines changed

6 files changed

+121
-59
lines changed

coverage.txt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,33 +2,33 @@
22
platform darwin -- Python 3.9.7, pytest-6.2.5, py-1.11.0, pluggy-1.0.0
33
rootdir: /Users/johnmount/Documents/work/wvpy/pkg
44
plugins: anyio-3.5.0, cov-3.0.0
5-
collected 19 items
5+
collected 20 items
66

77
tests/test_cross_plan1.py . [ 5%]
88
tests/test_cross_predict.py .. [ 15%]
9-
tests/test_deviance_calc.py . [ 21%]
10-
tests/test_eval_fn_pre_row.py . [ 26%]
11-
tests/test_match_auc.py . [ 31%]
12-
tests/test_nb_fns.py ... [ 47%]
13-
tests/test_onehot.py .. [ 57%]
14-
tests/test_perm_score_vars.py . [ 63%]
15-
tests/test_plots.py . [ 68%]
16-
tests/test_se.py . [ 73%]
17-
tests/test_search_grid.py .. [ 84%]
18-
tests/test_stats1.py . [ 89%]
19-
tests/test_threshold_stats.py . [ 94%]
9+
tests/test_deviance_calc.py . [ 20%]
10+
tests/test_eval_fn_pre_row.py . [ 25%]
11+
tests/test_match_auc.py . [ 30%]
12+
tests/test_nb_fns.py .... [ 50%]
13+
tests/test_onehot.py .. [ 60%]
14+
tests/test_perm_score_vars.py . [ 65%]
15+
tests/test_plots.py . [ 70%]
16+
tests/test_se.py . [ 75%]
17+
tests/test_search_grid.py .. [ 85%]
18+
tests/test_stats1.py . [ 90%]
19+
tests/test_threshold_stats.py . [ 95%]
2020
tests/test_typs_in_frame.py . [100%]
2121

2222
---------- coverage: platform darwin, python 3.9.7-final-0 -----------
2323
Name Stmts Miss Cover
2424
---------------------------------------------
2525
wvpy/__init__.py 3 0 100%
26-
wvpy/jtools.py 136 34 75%
26+
wvpy/jtools.py 135 27 80%
2727
wvpy/pysheet.py 74 74 0%
2828
wvpy/render_workbook.py 46 46 0%
2929
wvpy/util.py 321 7 98%
3030
---------------------------------------------
31-
TOTAL 580 161 72%
31+
TOTAL 579 154 73%
3232

3333

34-
============================= 19 passed in 14.58s ==============================
34+
============================= 20 passed in 13.11s ==============================

pkg/build/lib/wvpy/jtools.py

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def convert_py_code_to_notebook(text: str) -> nbformat.notebooknode.NotebookNode
1919
:param text: Python text to convert.
2020
:return: a notebook
2121
"""
22+
# https://stackoverflow.com/a/23729611/6901725
23+
# https://nbviewer.org/gist/fperez/9716279
2224
assert isinstance(text, str)
2325
lines = text.splitlines()
2426
begin_text_regexp = re.compile(r"^r?'''\s*begin\s+text\s*$")
@@ -68,6 +70,24 @@ def convert_py_code_to_notebook(text: str) -> nbformat.notebooknode.NotebookNode
6870
return nb
6971

7072

73+
def prepend_code_cell_to_notebook(
74+
nb: nbformat.notebooknode.NotebookNode,
75+
*,
76+
code_text: str,
77+
) -> nbformat.notebooknode.NotebookNode:
78+
"""
79+
Prepend a code cell to a Jupyter notebook.
80+
81+
:param nb: Jupyter notebook to alter
82+
:param code_text: Python source code to add
83+
:return: new notebook
84+
"""
85+
nbf_v = nbformat.v4
86+
nb_out = nbf_v.new_notebook()
87+
nb_out['cells'] = [nbf_v.new_code_cell(code_text)] + list(nb.cells)
88+
return nb_out
89+
90+
7191
def convert_py_file_to_notebook(*, py_file: str, ipynb_file: str) -> None:
7292
"""
7393
Convert python text to a notebook.
@@ -149,8 +169,7 @@ def render_as_html(
149169
timeout:int = 60000,
150170
kernel_name: Optional[str] = None,
151171
verbose: bool = True,
152-
parameters = None,
153-
parameter_file_name: Optional[str] = None,
172+
init_code: Optional[str] = None,
154173
exclude_input: bool = False,
155174
prompt_strip_regexp: Optional[str] = r'<\s*div\s+class\s*=\s*"jp-OutputPrompt[^<>]*>[^<>]*Out[^<>]*<\s*/div\s*>',
156175
) -> None:
@@ -164,8 +183,7 @@ def render_as_html(
164183
passed to nbconvert.preprocessors.ExecutePreprocessor.
165184
:param kernel_name: Jupyter kernel to use. passed to nbconvert.preprocessors.ExecutePreprocessor.
166185
:param verbose logical, if True print while running
167-
:param parameters: arbitrary object to write to paramater_file_name
168-
:param parameter_file_name: file name to pickle parameters to
186+
:param init_code: Python init code for first cell
169187
:param exclude_input: if True, exclude input cells
170188
:param prompt_strip_regexp: regexp to strip prompts, only used if exclude_input is True
171189
:return: None
@@ -182,6 +200,9 @@ def render_as_html(
182200
nb = convert_py_code_to_notebook(text)
183201
else:
184202
raise ValueError("file name must end with .ipynb or .py")
203+
if init_code is not None:
204+
assert isinstance(init_code, str)
205+
nb = prepend_code_cell_to_notebook(nb, code_text=init_code)
185206
html_name = notebook_file_name.removesuffix(suffix)
186207
exec_note = ""
187208
if output_suffix is not None:
@@ -193,10 +214,6 @@ def render_as_html(
193214
os.remove(html_name)
194215
except FileNotFoundError:
195216
pass
196-
if parameter_file_name is not None:
197-
assert isinstance(parameter_file_name, str)
198-
with open(parameter_file_name, "wb") as f:
199-
pickle.dump(parameters, f)
200217
caught = None
201218
try:
202219
if verbose:
@@ -222,11 +239,6 @@ def render_as_html(
222239
f.write(html_body)
223240
except Exception as e:
224241
caught = e
225-
if parameter_file_name is not None:
226-
try:
227-
os.remove(parameter_file_name)
228-
except FileNotFoundError:
229-
pass
230242
if caught is not None:
231243
raise caught
232244
if verbose:
115 Bytes
Binary file not shown.

pkg/dist/wvpy-0.3.2.tar.gz

139 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)