Skip to content

Commit f3bd454

Browse files
committed
rebuild and retest
1 parent 04ab8b0 commit f3bd454

File tree

5 files changed

+826
-807
lines changed

5 files changed

+826
-807
lines changed

coverage.txt

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

7-
tests/test_nb_fns.py .... [100%]
8-
9-
=============================== warnings summary ===============================
10-
../../../../opt/anaconda3/envs/wvpy_dev_env/lib/python3.9/site-packages/jupyter_client/connect.py:27
11-
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.9/site-packages/jupyter_client/connect.py:27: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs
12-
given by the platformdirs library. To remove this warning and
13-
see the appropriate new directories, set the environment variable
14-
`JUPYTER_PLATFORM_DIRS=1` and then run `jupyter --paths`.
15-
The use of platformdirs will be the default in `jupyter_core` v6
16-
from jupyter_core.paths import jupyter_data_dir
17-
18-
tests/test_nb_fns.py::test_jupyter_notebook_parameterized_good
19-
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.9/site-packages/nbformat/v4/nbbase.py:40: MissingIDFieldWarning: Code cell is missing an id field, this will become a hard error in future nbformat versions. You may want to use `normalize()` on your notebooks before validations (available since nbformat 5.1.4). Previous versions of nbformat are fixing this issue transparently, and will stop doing so in the future.
20-
return validate_orig(node, ref=ref, version=nbformat)
21-
22-
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
7+
tests/test_nb_fns.py ..... [100%]
238

249
---------- coverage: platform darwin, python 3.9.16-final-0 ----------
2510
Name Stmts Miss Cover
2611
---------------------------------------------
2712
wvpy/__init__.py 3 0 100%
28-
wvpy/jtools.py 223 91 59%
13+
wvpy/jtools.py 227 91 60%
2914
wvpy/pysheet.py 99 99 0%
3015
wvpy/render_workbook.py 54 54 0%
3116
---------------------------------------------
32-
TOTAL 379 244 36%
17+
TOTAL 383 244 36%
18+
3319

34-
======================== 4 passed, 2 warnings in 8.72s =========================
20+
============================== 5 passed in 7.73s ===============================

pkg/build/lib/wvpy/jtools.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
except ModuleNotFoundError:
2424
pass
2525

26+
nbf_v = nbformat.v4
27+
28+
#def _normalize(nb):
29+
# # try and work around version mismatches
30+
# return nbformat.validator.normalize(nb, version=4, version_minor=5)[1]
31+
2632

2733
# noinspection PyBroadException
2834
def pretty_format_python(python_txt: str, *, black_mode=None) -> str:
@@ -69,7 +75,6 @@ def convert_py_code_to_notebook(
6975
begin_text_regexp = re.compile(r"^\s*r?((''')|(\"\"\"))\s*begin\s+text\s*$")
7076
end_text_regexp = re.compile(r"^\s*r?((''')|(\"\"\"))\s*#\s*end\s+text\s*$")
7177
end_code_regexp = re.compile(r"(^\s*r?'''\s*end\s+code\s*'''\s*$)|(^\s*r?\"\"\"\s*end\s+code\s*\"\"\"\s*$)")
72-
nbf_v = nbformat.v4
7378
# run a little code collecting state machine
7479
cells = []
7580
collecting_python = []
@@ -110,8 +115,10 @@ def convert_py_code_to_notebook(
110115
collecting_python.append(line)
111116
if collecting_text is not None:
112117
collecting_text.append(line)
118+
for i in range(len(cells)):
119+
cells[i]["id"] = f"cell{i}"
113120
nb = nbf_v.new_notebook(cells=cells)
114-
nb = nbformat.validator.normalize(nb)[1]
121+
# nb = _normalize(nb)
115122
return nb
116123

117124

@@ -127,12 +134,18 @@ def prepend_code_cell_to_notebook(
127134
:param code_text: Python source code to add
128135
:return: new notebook
129136
"""
130-
nbf_v = nbformat.v4
131-
cells = [nbf_v.new_code_cell(code_text)] + list(nb.cells)
137+
header_cell = nbf_v.new_code_cell(code_text)
138+
# set cell ids to avoid:
139+
# "MissingIDFieldWarning: Code cell is missing an id field, this will become a hard error in future nbformat versions."
140+
header_cell["id"] = "wvpy_header_cell"
141+
orig_cells = [c.copy() for c in nb.cells]
142+
for i in range(len(orig_cells)):
143+
orig_cells[i]["id"] = f"cell{i}"
144+
cells = [header_cell] + orig_cells
132145
nb_out = nbf_v.new_notebook(
133146
cells=cells
134147
)
135-
nb_out = nbformat.validator.normalize(nb_out)[1]
148+
# nb_out = _normalize(nb_out)
136149
return nb_out
137150

138151

@@ -288,7 +301,7 @@ def render_as_html(
288301
else:
289302
raise ValueError('{ipynb_exists}: file must end with .py or .ipynb')
290303
# do the conversion
291-
if init_code is not None:
304+
if (init_code is not None) and (len(init_code) > 0):
292305
assert isinstance(init_code, str)
293306
nb = prepend_code_cell_to_notebook(
294307
nb,
217 Bytes
Binary file not shown.

pkg/dist/wvpy-0.3.8.tar.gz

201 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)