Skip to content

Commit

Permalink
Merge branch 'main' of github.com:WinVector/wvpy
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMount committed Dec 13, 2023
2 parents 99fdf3c + 40d6628 commit ff355ce
Show file tree
Hide file tree
Showing 20 changed files with 32,327 additions and 1,152 deletions.
10 changes: 5 additions & 5 deletions coverage.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
platform darwin -- Python 3.11.2, pytest-7.1.2, pluggy-1.0.0
rootdir: /Users/johnmount/Documents/work/wvpy/pkg
plugins: anyio-3.5.0, cov-4.0.0
collected 10 items
collected 13 items

tests/test_nb_fns.py .......... [100%]
tests/test_nb_fns.py ............. [100%]

---------- coverage: platform darwin, python 3.11.2-final-0 ----------
Name Stmts Miss Cover
---------------------------------------------
wvpy/__init__.py 3 0 100%
wvpy/jtools.py 305 98 68%
wvpy/jtools.py 328 104 68%
wvpy/pysheet.py 99 99 0%
wvpy/render_workbook.py 54 54 0%
---------------------------------------------
TOTAL 461 251 46%
TOTAL 484 257 47%


============================= 10 passed in 33.52s ==============================
============================= 13 passed in 33.67s ==============================
209 changes: 209 additions & 0 deletions examples/sheet_vars/driver_sheet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Example driver sheet.\n",
"\n",
"This can be used to run many jobs in parallel."
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from pprint import pprint\n",
"from wvpy.jtools import JTask, run_pool\n",
"import imgkit\n",
"import os"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# define tasks, rendering the same Jupyter notebook\n",
"# with different sheet_vars values and ouput suffices.\n",
"tasks = [\n",
" JTask(\n",
" \"task_sheet.ipynb\",\n",
" output_suffix=\"_g1\",\n",
" sheet_vars = {\n",
" \"file_names\": [\n",
" \"fname_1.txt\",\n",
" \"fname_2.txt\",\n",
" ],\n",
" \"sheet_group\": \"g1\",\n",
" },\n",
" exclude_input=False,\n",
" ),\n",
" JTask(\n",
" \"task_sheet.ipynb\",\n",
" output_suffix=\"_g2\",\n",
" sheet_vars = {\n",
" \"file_names\": [\n",
" \"fname_3.txt\",\n",
" \"fname_4.txt\",\n",
" ],\n",
" \"sheet_group\": \"g2\",\n",
" },\n",
" exclude_input=True,\n",
" ),\n",
"]\n"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[JTask(\n",
" sheet_name='task_sheet.ipynb',\n",
" output_suffix='_g1',\n",
" exclude_input=False,\n",
" init_code=None,\n",
" path_prefix=None,\n",
" sheet_vars={'file_names': ['fname_1.txt', 'fname_2.txt'], 'sheet_group': 'g1'},\n",
"),\n",
" JTask(\n",
" sheet_name='task_sheet.ipynb',\n",
" output_suffix='_g2',\n",
" exclude_input=True,\n",
" init_code=None,\n",
" path_prefix=None,\n",
" sheet_vars={'file_names': ['fname_3.txt', 'fname_4.txt'], 'sheet_group': 'g2'},\n",
")]\n"
]
}
],
"source": [
"# print our tasks\n",
"pprint(tasks)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"start render_as_html \"task_sheet.ipynb\" \"_g2\" 2023-07-02 12:08:33.054926\n",
"start render_as_html \"task_sheet.ipynb\" \"_g1\" 2023-07-02 12:08:33.056136\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"This version of python seems to be incorrectly compiled\n",
"(internal generated filenames are not absolute).\n",
"This may make the debugger miss breakpoints.\n",
"Related bug: http://bugs.python.org/issue1666807\n",
"This version of python seems to be incorrectly compiled\n",
"(internal generated filenames are not absolute).\n",
"This may make the debugger miss breakpoints.\n",
"Related bug: http://bugs.python.org/issue1666807\n",
"This version of python seems to be incorrectly compiled\n",
"(internal generated filenames are not absolute).\n",
"This may make the debugger miss breakpoints.\n",
"Related bug: http://bugs.python.org/issue1666807\n",
"This version of python seems to be incorrectly compiled\n",
"(internal generated filenames are not absolute).\n",
"This may make the debugger miss breakpoints.\n",
"Related bug: http://bugs.python.org/issue1666807\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"\tdone render_as_html \"task_sheet_g2.html\" 2023-07-02 12:08:35.352744\n",
"\tdone render_as_html \"task_sheet_g1.html\" 2023-07-02 12:08:35.438916\n"
]
},
{
"data": {
"text/plain": [
"[None, None]"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# run the tasks, in parallel\n",
"# ignore warning msgs\n",
"# \"This version of python seems to be incorrectly compiled\"\n",
"# Just MacOS problems\n",
"run_pool(\n",
" tasks,\n",
" njobs=2,\n",
" verbose=False,\n",
" stop_on_error=False,\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Loading page (1/2)\n",
"Rendering (2/2) \n",
"Done \n",
"Loading page (1/2)\n",
"Rendering (2/2) \n",
"Done \n"
]
}
],
"source": [
"# convert HTMLs from renders to PNGs to show\n",
"for fname in os.listdir():\n",
" if fname.startswith('task_sheet_') and fname.endswith('.html'):\n",
" imgkit.from_file(fname, fname.removesuffix('.html') + \".png\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "wvpy_dev_env",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.3"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
58 changes: 58 additions & 0 deletions examples/sheet_vars/task_sheet.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"cells": [
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"Example task sheet.\n",
"\n",
"Example of a single job to run. Values come in through `sheet_vars` and even optional `init_code`."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from pprint import pprint\n",
"from IPython.display import display, HTML, Markdown"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"display(HTML(f'File names assigned: {sheet_vars[\"file_names\"]}.'))"
]
},
{
"attachments": {},
"cell_type": "markdown",
"metadata": {},
"source": [
"The sheet variables are the following."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"pprint(sheet_vars)"
]
}
],
"metadata": {
"language_info": {
"name": "python"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading

0 comments on commit ff355ce

Please sign in to comment.