Skip to content

Commit a6bae87

Browse files
committed
allow flexibility in suffix
1 parent 873926f commit a6bae87

File tree

12 files changed

+3337
-3480
lines changed

12 files changed

+3337
-3480
lines changed

coverage.txt

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
============================= test session starts ==============================
2-
platform darwin -- Python 3.9.12, pytest-7.1.1, pluggy-1.0.0
2+
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
55
collected 20 items
@@ -19,26 +19,16 @@ tests/test_stats1.py . [ 90%]
1919
tests/test_threshold_stats.py . [ 95%]
2020
tests/test_typs_in_frame.py . [100%]
2121

22-
=============================== warnings summary ===============================
23-
../../../../opt/anaconda3/envs/research_env/lib/python3.9/site-packages/seaborn/rcmod.py:82
24-
/Users/johnmount/opt/anaconda3/envs/research_env/lib/python3.9/site-packages/seaborn/rcmod.py:82: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
25-
if LooseVersion(mpl.__version__) >= "3.0":
26-
27-
../../../../opt/anaconda3/envs/research_env/lib/python3.9/site-packages/setuptools/_distutils/version.py:351
28-
/Users/johnmount/opt/anaconda3/envs/research_env/lib/python3.9/site-packages/setuptools/_distutils/version.py:351: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
29-
other = LooseVersion(other)
30-
31-
-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
32-
33-
---------- coverage: platform darwin, python 3.9.12-final-0 ----------
22+
---------- coverage: platform darwin, python 3.9.7-final-0 -----------
3423
Name Stmts Miss Cover
3524
---------------------------------------------
3625
wvpy/__init__.py 3 0 100%
37-
wvpy/jtools.py 146 32 78%
26+
wvpy/jtools.py 156 41 74%
3827
wvpy/pysheet.py 89 89 0%
3928
wvpy/render_workbook.py 47 47 0%
4029
wvpy/util.py 321 7 98%
4130
---------------------------------------------
42-
TOTAL 606 175 71%
31+
TOTAL 616 184 70%
32+
4333

44-
======================= 20 passed, 2 warnings in 16.87s ========================
34+
============================= 20 passed in 13.17s ==============================

pkg/build/lib/wvpy/jtools.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ def render_as_html(
186186
Render a Jupyter notebook in the current directory as HTML.
187187
Exceptions raised in the rendering notebook are allowed to pass trough.
188188
189-
:param notebook_file_name: name of source file, must end with .ipynb or .py
189+
:param notebook_file_name: name of source file, must end with .ipynb or .py (or type gotten from file system)
190190
:param output_suffix: optional name to add to result name
191191
:param timeout: Maximum time in seconds each notebook cell is allowed to run.
192192
passed to nbconvert.preprocessors.ExecutePreprocessor.
@@ -200,6 +200,19 @@ def render_as_html(
200200
"""
201201
assert isinstance(notebook_file_name, str)
202202
assert isinstance(convert_to_pdf, bool)
203+
# deal with no suffix case
204+
if (not notebook_file_name.endswith(".ipynb")) and (not notebook_file_name.endswith(".py")):
205+
py_name = notebook_file_name + ".py"
206+
py_exists = os.path.exists(py_name)
207+
ipynb_name = notebook_file_name + ".ipynb"
208+
ipynb_exists = os.path.exists(ipynb_name)
209+
if (py_exists + ipynb_exists) != 1:
210+
raise ValueError('{ipynb_exists}: if file suffix is not specified then exactly one of .py or .ipynb file must exist')
211+
if ipynb_exists:
212+
notebook_file_name = notebook_file_name + '.ipynb'
213+
else:
214+
notebook_file_name = notebook_file_name + '.py'
215+
# get the input
203216
if notebook_file_name.endswith(".ipynb"):
204217
suffix = ".ipynb"
205218
with open(notebook_file_name, "rb") as f:
@@ -210,12 +223,13 @@ def render_as_html(
210223
text = f.read()
211224
nb = convert_py_code_to_notebook(text)
212225
else:
213-
raise ValueError("file name must end with .ipynb or .py")
226+
raise ValueError('{ipynb_exists}: file must end with .py or .ipynb')
227+
# do the conversion
214228
if init_code is not None:
215229
assert isinstance(init_code, str)
216230
nb = prepend_code_cell_to_notebook(
217231
nb,
218-
code_text=f'\n{init_code}\n')
232+
code_text=f'\n\n{init_code}\n\n')
219233
html_name = os.path.basename(notebook_file_name)
220234
html_name = html_name.removesuffix(suffix)
221235
exec_note = ""
196 Bytes
Binary file not shown.

pkg/dist/wvpy-0.3.5.tar.gz

-133 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: 18 additions & 19 deletions
Large diffs are not rendered by default.

pkg/docs/wvpy/jtools.html

Lines changed: 626 additions & 638 deletions
Large diffs are not rendered by default.

pkg/docs/wvpy/pysheet.html

Lines changed: 225 additions & 226 deletions
Large diffs are not rendered by default.

pkg/docs/wvpy/render_workbook.html

Lines changed: 126 additions & 127 deletions
Large diffs are not rendered by default.

pkg/docs/wvpy/util.html

Lines changed: 2301 additions & 2421 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)