Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support windows #392

Merged
merged 7 commits into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion nbdev/export2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,11 @@ def notebook2html(fname=None, force_all=False, n_workers=None, cls=HTMLExporter,
files.append(fname)
if len(files)==0: print("No notebooks were modified")
else:
passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,
if sys.platform == "win32":
mszhanyi marked this conversation as resolved.
Show resolved Hide resolved
passed = [_notebook2html(file, cls=cls,
template_file=template_file, exporter=exporter, dest=dest, execute=execute) for file in files]
else:
passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,
template_file=template_file, exporter=exporter, dest=dest, pause=pause, execute=execute)
if not all(passed):
msg = "Conversion failed on the following:\n"
Expand Down
1 change: 1 addition & 0 deletions nbdev/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def _split(code):
# Cell
def relimport2name(name, mod_name):
"Unwarps a relative import in `name` according to `mod_name`"
mod_name = str(Path(mod_name))
if mod_name.endswith('.py'): mod_name = mod_name[:-3]
mods = mod_name.split(os.path.sep)
i = last_index(Config().lib_name, mods)
Expand Down
25 changes: 18 additions & 7 deletions nbs/01_sync.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@
"#export\n",
"def relimport2name(name, mod_name):\n",
" \"Unwarps a relative import in `name` according to `mod_name`\"\n",
" mod_name = str(Path(mod_name))\n",
" if mod_name.endswith('.py'): mod_name = mod_name[:-3]\n",
" mods = mod_name.split(os.path.sep)\n",
" i = last_index(Config().lib_name, mods)\n",
Expand All @@ -258,6 +259,23 @@
" return '.'.join(mods[:-i] + [name[i:]])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"nbdev.core\n"
]
}
],
"source": [
"print(relimport2name('.core', 'nbdev/data.py'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -594,13 +612,6 @@
"from nbdev.export import *\n",
"notebook2script()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
79 changes: 31 additions & 48 deletions nbs/03_export2html.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -590,8 +590,8 @@
"outputs": [],
"source": [
"#hide\n",
"test_eq(_relative_to(Path('images/logo.png'), Config().path(\"doc_path\")), '../nbs/images/logo.png')\n",
"test_eq(_relative_to(Path('images/logo.png'), Config().path(\"doc_path\").parent), 'nbs/images/logo.png')"
"test_eq(_relative_to(Path('images/logo.png'), Config().path(\"doc_path\")), str(Path('../nbs/images/logo.png')))\n",
"test_eq(_relative_to(Path('images/logo.png'), Config().path(\"doc_path\").parent), str(Path('nbs/images/logo.png')))"
]
},
{
Expand Down Expand Up @@ -633,9 +633,9 @@
"metadata": {},
"outputs": [],
"source": [
"cell = {'cell_type': 'markdown', 'source': 'Text\\n![Alt](images/logo.png)'}\n",
"cell = {'cell_type': 'markdown', 'source': str(Path('Text\\n![Alt](images/logo.png)'))}\n",
"cell1 = adapt_img_path(cell, Path('01_export.ipynb'), Path('.').absolute().parent)\n",
"test_eq(cell1['source'], 'Text\\n![Alt](nbs/images/logo.png)')\n",
"test_eq(cell1['source'], str(Path('Text\\n![Alt](nbs/images/logo.png)')))\n",
"\n",
"cell = {'cell_type': 'markdown', 'source': 'Text\\n![Alt](http://site.logo.png)'}\n",
"cell1 = adapt_img_path(cell, Path('01_export.ipynb'), Path('.').absolute().parent)\n",
Expand Down Expand Up @@ -1765,7 +1765,11 @@
" files.append(fname)\n",
" if len(files)==0: print(\"No notebooks were modified\")\n",
" else:\n",
" passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,\n",
" if sys.platform == \"win32\":\n",
" passed = [_notebook2html(file, cls=cls,\n",
" template_file=template_file, exporter=exporter, dest=dest, execute=execute) for file in files]\n",
" else:\n",
" passed = parallel(_notebook2html, files, n_workers=n_workers, cls=cls,\n",
" template_file=template_file, exporter=exporter, dest=dest, pause=pause, execute=execute)\n",
" if not all(passed):\n",
" msg = \"Conversion failed on the following:\\n\"\n",
Expand All @@ -1779,16 +1783,6 @@
"hide_input": false
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
Expand All @@ -1800,9 +1794,14 @@
"source": [
"#hide\n",
"# Test when an argument is given to notebook2html\n",
"p1 = Path('/tmp/sync.html')\n",
"tmp_file = tempfile.NamedTemporaryFile(delete=True)\n",
"tmp_name = tmp_file.name\n",
"tmp_file.close()\n",
"#p1 = Path('/tmp/sync.html')\n",
"temp_dir = Path(tmp_name).parent\n",
"p1 = temp_dir.joinpath('sync.html') \n",
"if p1.exists(): p1.unlink()\n",
"notebook2html('01_sync.ipynb', dest='/tmp', n_workers=0);\n",
"notebook2html('01_sync.ipynb', dest=temp_dir, n_workers=0);\n",
"assert p1.exists()"
]
},
Expand All @@ -1813,42 +1812,33 @@
"hide_input": false
},
"outputs": [
{
"data": {
"text/html": [],
"text/plain": [
"<IPython.core.display.HTML object>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"converting: /data/nbs/02_showdoc.ipynb\n",
"converting: /data/nbs/03_export2html.ipynb\n",
"converting: /data/nbs/00_export.ipynb\n",
"converting: /data/nbs/01_sync.ipynb\n",
"converting: /data/nbs/06_cli.ipynb\n",
"converting: /data/nbs/04_test.ipynb\n",
"converting: /data/nbs/05_merge.ipynb\n",
"converting: /data/nbs/07_clean.ipynb\n",
"converting: /data/nbs/example.ipynb\n",
"converting: /data/nbs/99_search.ipynb\n",
"converting: /data/nbs/index.ipynb\n",
"converting: /data/nbs/tutorial.ipynb\n"
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\00_export.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\01_sync.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\02_showdoc.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\03_export2html.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\04_test.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\05_merge.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\06_cli.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\07_clean.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\99_search.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\example.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\index.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\tutorial.ipynb\n",
"converting: d:\\git\\zyrepo\\nbdev\\nbs\\.ipynb_checkpoints\\03_export2html-checkpoint.ipynb\n"
]
}
],
"source": [
"#slow\n",
"#hide\n",
"# Test when no argument is given to notebook2html\n",
"dest_files = [_nb2htmlfname(Path(f), dest='/tmp') for f in nbglob()]\n",
"dest_files = [_nb2htmlfname(Path(f), dest=temp_dir) for f in nbglob()]\n",
"[f.unlink() for f in dest_files if f.exists()]\n",
"notebook2html(fname=None, dest='/tmp');\n",
"notebook2html(fname=None, dest=temp_dir);\n",
"for f in dest_files: assert f.exists(), f"
]
},
Expand Down Expand Up @@ -2301,13 +2291,6 @@
"from nbdev.export import *\n",
"notebook2script()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down