Skip to content

Commit 641fa8c

Browse files
committed
rebuild and retest
1 parent 37b9c0f commit 641fa8c

File tree

9 files changed

+1407
-1143
lines changed

9 files changed

+1407
-1143
lines changed

coverage.txt

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,42 @@
11
============================= test session starts ==============================
2-
platform darwin -- Python 3.11.2, pytest-7.1.2, pluggy-1.0.0
2+
platform darwin -- Python 3.11.3, pytest-7.3.1, pluggy-1.0.0
33
rootdir: /Users/johnmount/Documents/work/wvpy/pkg
44
plugins: anyio-3.5.0, cov-4.0.0
5-
collected 10 items
5+
collected 13 items
66

7-
tests/test_nb_fns.py .......... [100%]
7+
tests/test_nb_fns.py ............. [100%]
88

9-
---------- coverage: platform darwin, python 3.11.2-final-0 ----------
9+
=============================== warnings summary ===============================
10+
tests/test_nb_fns.py::test_jupyter_notebook_good
11+
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.11/site-packages/debugpy/_vendored/pydevd/pydevd_plugins/extensions/__init__.py:4: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('pydevd_plugins.extensions')`.
12+
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
13+
__import__('pkg_resources').declare_namespace(__name__)
14+
15+
tests/test_nb_fns.py::test_jupyter_notebook_good
16+
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.11/site-packages/pkg_resources/__init__.py:2349: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('pydevd_plugins')`.
17+
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
18+
declare_namespace(parent)
19+
20+
tests/test_nb_fns.py::test_jupyter_notebook_good
21+
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.11/site-packages/debugpy/_vendored/pydevd/pydevd_plugins/extensions/types/__init__.py:4: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('pydevd_plugins.extensions.types')`.
22+
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
23+
__import__('pkg_resources').declare_namespace(__name__)
24+
25+
tests/test_nb_fns.py::test_jupyter_notebook_good
26+
/Users/johnmount/opt/anaconda3/envs/wvpy_dev_env/lib/python3.11/site-packages/pkg_resources/__init__.py:2349: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('pydevd_plugins.extensions')`.
27+
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
28+
declare_namespace(parent)
29+
30+
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
31+
32+
---------- coverage: platform darwin, python 3.11.3-final-0 ----------
1033
Name Stmts Miss Cover
1134
---------------------------------------------
1235
wvpy/__init__.py 3 0 100%
13-
wvpy/jtools.py 305 98 68%
36+
wvpy/jtools.py 328 104 68%
1437
wvpy/pysheet.py 99 99 0%
1538
wvpy/render_workbook.py 54 54 0%
1639
---------------------------------------------
17-
TOTAL 461 251 46%
18-
40+
TOTAL 484 257 47%
1941

20-
============================= 10 passed in 31.13s ==============================
42+
======================= 13 passed, 4 warnings in 39.93s ========================

pkg/build/lib/wvpy/jtools.py

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
from nbconvert.preprocessors import ExecutePreprocessor
1010
from multiprocessing import Pool
1111
import sys
12+
import pickle
13+
import tempfile
1214

1315
from typing import Iterable, List, Optional
1416
from functools import total_ordering
@@ -287,6 +289,7 @@ def render_as_html(
287289
timeout:int = 60000,
288290
kernel_name: Optional[str] = None,
289291
verbose: bool = True,
292+
sheet_vars = None,
290293
init_code: Optional[str] = None,
291294
exclude_input: bool = False,
292295
prompt_strip_regexp: Optional[str] = r'<\s*div\s+class\s*=\s*"jp-OutputPrompt[^<>]*>[^<>]*Out[^<>]*<\s*/div\s*>',
@@ -301,7 +304,8 @@ def render_as_html(
301304
:param timeout: Maximum time in seconds each notebook cell is allowed to run.
302305
passed to nbconvert.preprocessors.ExecutePreprocessor.
303306
:param kernel_name: Jupyter kernel to use. passed to nbconvert.preprocessors.ExecutePreprocessor.
304-
:param verbose logical, if True print while running
307+
:param verbose logical, if True print while running
308+
:param sheet_vars: if not None value is de-serialized as a variable named "sheet_vars"
305309
:param init_code: Python init code for first cell
306310
:param exclude_input: if True, exclude input cells
307311
:param prompt_strip_regexp: regexp to strip prompts, only used if exclude_input is True
@@ -335,7 +339,20 @@ def render_as_html(
335339
nb = convert_py_code_to_notebook(text)
336340
else:
337341
raise ValueError('{ipynb_exists}: file must end with .py or .ipynb')
342+
tmp_path = None
338343
# do the conversion
344+
if sheet_vars is not None:
345+
with tempfile.NamedTemporaryFile(delete=False) as ntf:
346+
tmp_path = ntf.name
347+
pickle.dump(sheet_vars, file=ntf)
348+
if (init_code is None) or (len(init_code) <= 0):
349+
init_code = ""
350+
pickle_code = f"""
351+
import pickle
352+
with open({tmp_path.__repr__()}, 'rb') as pf:
353+
sheet_vars = pickle.load(pf)
354+
"""
355+
init_code = init_code + "\n\n" + pickle_code
339356
if (init_code is not None) and (len(init_code) > 0):
340357
assert isinstance(init_code, str)
341358
nb = prepend_code_cell_to_notebook(
@@ -384,12 +401,21 @@ def render_as_html(
384401
caught = ep.caught_exception
385402
except Exception as e:
386403
caught = e
404+
if tmp_path is not None:
405+
try:
406+
os.remove(tmp_path)
407+
except FileNotFoundError:
408+
pass
387409
if caught is not None:
388410
raise caught
389411
if verbose:
390412
print(f'\tdone render_as_html "{html_name}" {datetime.datetime.now()}')
391413

392414

415+
_jtask_comparison_attributes = [
416+
"sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]
417+
418+
393419
@total_ordering
394420
class JTask:
395421
def __init__(
@@ -398,6 +424,7 @@ def __init__(
398424
*,
399425
output_suffix: Optional[str] = None,
400426
exclude_input: bool = True,
427+
sheet_vars = None,
401428
init_code: Optional[str] = None,
402429
path_prefix: Optional[str] = None,
403430
strict: bool = True,
@@ -408,6 +435,7 @@ def __init__(
408435
:param sheet_name: name of sheet to run can be .ipynb or .py, and suffix can be omitted.
409436
:param output_suffix: optional string to append to rendered HTML file name.
410437
:param exclude_input: if True strip input cells out of HTML render.
438+
:param sheet_vars: if not None value is de-serialized as a variable named "sheet_vars"
411439
:param init_code: optional code to insert at the top of the Jupyter sheet, used to pass parameters.
412440
:param path_prefix: optional prefix to add to sheet_name to find Jupyter source.
413441
:param strict: if True check paths path_prefix and path_prefix/sheetname[.py|.ipynb] exist.
@@ -432,6 +460,7 @@ def __init__(
432460
self.sheet_name = sheet_name
433461
self.output_suffix = output_suffix
434462
self.exclude_input = exclude_input
463+
self.sheet_vars = sheet_vars
435464
self.init_code = init_code
436465
self.path_prefix = path_prefix
437466

@@ -443,6 +472,7 @@ def render_as_html(self) -> None:
443472
path,
444473
exclude_input=self.exclude_input,
445474
output_suffix=self.output_suffix,
475+
sheet_vars=self.sheet_vars,
446476
init_code=self.init_code,
447477
)
448478

@@ -454,33 +484,39 @@ def _is_valid_operand(self, other):
454484

455485
def __eq__(self, other):
456486
if not self._is_valid_operand(other):
457-
return NotImplemented
487+
return False
458488
if str(type(self)) != str(type(other)):
459489
return False
460-
for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]:
490+
for v in _jtask_comparison_attributes:
461491
if self[v] != other[v]:
462492
return False
493+
if str(self.sheet_vars) != str(other.sheet_vars):
494+
return False
463495
return True
464496

465497
def __lt__(self, other):
466498
if not self._is_valid_operand(other):
467499
return NotImplemented
468500
if str(type(self)) < str(type(other)):
469501
return True
470-
for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]:
502+
for v in _jtask_comparison_attributes:
471503
v_self = self[v]
472504
v_other = other[v]
473505
# can't order compare None to None
474-
if ((v_self is None) or (v_other is None)) and ((v_self is None) != (v_other is None)):
475-
return v_self is None
476-
if self[v] < other[v]:
477-
return True
506+
if ((v_self is None) or (v_other is None)):
507+
if ((v_self is None) != (v_other is None)):
508+
return v_self is None
509+
else:
510+
if self[v] < other[v]:
511+
return True
512+
if str(self.sheet_vars) < str(other.sheet_vars):
513+
return True
478514
return False
479515

480516
def __str__(self) -> str:
481517
args_str = ",\n".join([
482-
f" {v}= {repr(self[v])}"
483-
for v in ["sheet_name", "output_suffix", "exclude_input", "init_code", "path_prefix"]
518+
f" {v}={repr(self[v])}"
519+
for v in _jtask_comparison_attributes + ["sheet_vars"]
484520
])
485521
return 'JTask(\n' + args_str + ",\n)"
486522

302 Bytes
Binary file not shown.

pkg/dist/wvpy-0.4.2.tar.gz

1.68 KB
Binary file not shown.

pkg/docs/search.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/docs/wvpy.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
6-
<meta name="generator" content="pdoc 13.1.0"/>
6+
<meta name="generator" content="pdoc 14.0.0"/>
77
<title>wvpy API documentation</title>
88

99
<style>/*! * Bootstrap Reboot v5.0.0 (https://getbootstrap.com/) * Copyright 2011-2021 The Bootstrap Authors * Copyright 2011-2021 Twitter, Inc. * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE) * Forked from Normalize.css, licensed MIT (https://github.com/necolas/normalize.css/blob/master/LICENSE.md) */*,::after,::before{box-sizing:border-box}@media (prefers-reduced-motion:no-preference){:root{scroll-behavior:smooth}}body{margin:0;font-family:system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,"Noto Sans","Liberation Sans",sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-size:1rem;font-weight:400;line-height:1.5;color:#212529;background-color:#fff;-webkit-text-size-adjust:100%;-webkit-tap-highlight-color:transparent}hr{margin:1rem 0;color:inherit;background-color:currentColor;border:0;opacity:.25}hr:not([size]){height:1px}h1,h2,h3,h4,h5,h6{margin-top:0;margin-bottom:.5rem;font-weight:500;line-height:1.2}h1{font-size:calc(1.375rem + 1.5vw)}@media (min-width:1200px){h1{font-size:2.5rem}}h2{font-size:calc(1.325rem + .9vw)}@media (min-width:1200px){h2{font-size:2rem}}h3{font-size:calc(1.3rem + .6vw)}@media (min-width:1200px){h3{font-size:1.75rem}}h4{font-size:calc(1.275rem + .3vw)}@media (min-width:1200px){h4{font-size:1.5rem}}h5{font-size:1.25rem}h6{font-size:1rem}p{margin-top:0;margin-bottom:1rem}abbr[data-bs-original-title],abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted;cursor:help;-webkit-text-decoration-skip-ink:none;text-decoration-skip-ink:none}address{margin-bottom:1rem;font-style:normal;line-height:inherit}ol,ul{padding-left:2rem}dl,ol,ul{margin-top:0;margin-bottom:1rem}ol ol,ol ul,ul ol,ul ul{margin-bottom:0}dt{font-weight:700}dd{margin-bottom:.5rem;margin-left:0}blockquote{margin:0 0 1rem}b,strong{font-weight:bolder}small{font-size:.875em}mark{padding:.2em;background-color:#fcf8e3}sub,sup{position:relative;font-size:.75em;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}a{color:#0d6efd;text-decoration:underline}a:hover{color:#0a58ca}a:not([href]):not([class]),a:not([href]):not([class]):hover{color:inherit;text-decoration:none}code,kbd,pre,samp{font-family:SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em;direction:ltr;unicode-bidi:bidi-override}pre{display:block;margin-top:0;margin-bottom:1rem;overflow:auto;font-size:.875em}pre code{font-size:inherit;color:inherit;word-break:normal}code{font-size:.875em;color:#d63384;word-wrap:break-word}a>code{color:inherit}kbd{padding:.2rem .4rem;font-size:.875em;color:#fff;background-color:#212529;border-radius:.2rem}kbd kbd{padding:0;font-size:1em;font-weight:700}figure{margin:0 0 1rem}img,svg{vertical-align:middle}table{caption-side:bottom;border-collapse:collapse}caption{padding-top:.5rem;padding-bottom:.5rem;color:#6c757d;text-align:left}th{text-align:inherit;text-align:-webkit-match-parent}tbody,td,tfoot,th,thead,tr{border-color:inherit;border-style:solid;border-width:0}label{display:inline-block}button{border-radius:0}button:focus:not(:focus-visible){outline:0}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:inherit;line-height:inherit}button,select{text-transform:none}[role=button]{cursor:pointer}select{word-wrap:normal}select:disabled{opacity:1}[list]::-webkit-calendar-picker-indicator{display:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}[type=button]:not(:disabled),[type=reset]:not(:disabled),[type=submit]:not(:disabled),button:not(:disabled){cursor:pointer}::-moz-focus-inner{padding:0;border-style:none}textarea{resize:vertical}fieldset{min-width:0;padding:0;margin:0;border:0}legend{float:left;width:100%;padding:0;margin-bottom:.5rem;font-size:calc(1.275rem + .3vw);line-height:inherit}@media (min-width:1200px){legend{font-size:1.5rem}}legend+*{clear:left}::-webkit-datetime-edit-day-field,::-webkit-datetime-edit-fields-wrapper,::-webkit-datetime-edit-hour-field,::-webkit-datetime-edit-minute,::-webkit-datetime-edit-month-field,::-webkit-datetime-edit-text,::-webkit-datetime-edit-year-field{padding:0}::-webkit-inner-spin-button{height:auto}[type=search]{outline-offset:-2px;-webkit-appearance:textfield}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-color-swatch-wrapper{padding:0}::file-selector-button{font:inherit}::-webkit-file-upload-button{font:inherit;-webkit-appearance:button}output{display:inline-block}iframe{border:0}summary{display:list-item;cursor:pointer}progress{vertical-align:baseline}[hidden]{display:none!important}</style>

0 commit comments

Comments
 (0)