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 all 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
1 change: 1 addition & 0 deletions nbdev/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ def nbdev_clean_nbs(fname:Param("A notebook name or glob to convert", str)=None,
clean_nb(nb, clear_all=clear_all)
_print_output(nb)
return
path = None
if fname is None:
try: path = Config().path("nbs_path")
except Exception as e: path = Path.cwd()
Expand Down
1 change: 1 addition & 0 deletions nbdev/export2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ 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:
if sys.platform == "win32": n_workers = 0
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):
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
10 changes: 6 additions & 4 deletions nbs/00_export.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -1669,10 +1669,11 @@
" (Path(d)/'a'/'b'/'c'/'fake_c.ipynb').touch()\n",
" (Path(d)/'a'/'b'/'c'/'foo_c.ipynb').touch()\n",
" \n",
" assert len(nbglob(f'{str(d)}/**/foo*', recursive=True)) == 1\n",
" if sys.platform != \"win32\":\n",
" assert len(nbglob(str(Path(f'{str(d)}/**/foo*')), recursive=True)) == 1\n",
" assert len(nbglob(d, recursive=True)) == 5\n",
" assert len(nbglob(d)) == 0\n",
" assert len(nbglob(f'{d}/a')) == 2"
" assert len(nbglob(str(Path(f'{d}/a')))) == 2"
]
},
{
Expand All @@ -1682,8 +1683,9 @@
"outputs": [],
"source": [
"#hide\n",
"assert len(nbglob('*')) > 1\n",
"assert len(nbglob('*')) > len(nbglob('0*'))"
"if sys.platform != \"win32\":\n",
" assert len(nbglob('*')) > 1\n",
" assert len(nbglob('*')) > len(nbglob('0*'))"
]
},
{
Expand Down
20 changes: 12 additions & 8 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 Down Expand Up @@ -407,6 +408,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"Converted export.py.\n"
]
}
Expand All @@ -421,7 +423,15 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"None\n"
]
}
],
"source": [
"#hide\n",
"exported = get_nbdev_module().modules\n",
Expand Down Expand Up @@ -574,6 +584,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"Converted 00_export.ipynb.\n",
"Converted 01_sync.ipynb.\n",
"Converted 02_showdoc.ipynb.\n",
Expand All @@ -594,13 +605,6 @@
"from nbdev.export import *\n",
"notebook2script()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
7 changes: 4 additions & 3 deletions nbs/02_showdoc.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"notebook2script\" class=\"doc_header\"><code>notebook2script</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L417\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"notebook2script\" class=\"doc_header\"><code>notebook2script</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L413\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>notebook2script</code>(**`fname`**=*`None`*, **`silent`**=*`False`*, **`to_dict`**=*`False`*, **`bare`**=*`False`*, **`recursive`**=*`None`*)\n",
"\n",
Expand Down Expand Up @@ -914,7 +914,7 @@
{
"data": {
"text/markdown": [
"<h2 id=\"DocsTestClass\" class=\"doc_header\"><code>class</code> <code>DocsTestClass</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L433\" class=\"source_link\" style=\"float:right\">[source]</a></h2>\n",
"<h2 id=\"DocsTestClass\" class=\"doc_header\"><code>class</code> <code>DocsTestClass</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L429\" class=\"source_link\" style=\"float:right\">[source]</a></h2>\n",
"\n",
"> <code>DocsTestClass</code>()\n",
"\n",
Expand All @@ -941,7 +941,7 @@
{
"data": {
"text/markdown": [
"<h4 id=\"DocsTestClass.test\" class=\"doc_header\"><code>DocsTestClass.test</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L435\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"<h4 id=\"DocsTestClass.test\" class=\"doc_header\"><code>DocsTestClass.test</code><a href=\"https://github.com/fastai/nbdev/tree/master/nbdev/export.py#L431\" class=\"source_link\" style=\"float:right\">[source]</a></h4>\n",
"\n",
"> <code>DocsTestClass.test</code>()\n",
"\n"
Expand Down Expand Up @@ -1178,6 +1178,7 @@
"name": "stdout",
"output_type": "stream",
"text": [
"None\n",
"Converted 00_export.ipynb.\n",
"Converted 01_sync.ipynb.\n",
"Converted 02_showdoc.ipynb.\n",
Expand Down
66 changes: 42 additions & 24 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 @@ -1761,6 +1761,7 @@
" files.append(fname)\n",
" if len(files)==0: print(\"No notebooks were modified\")\n",
" else:\n",
" if sys.platform == \"win32\": n_workers = 0\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",
Expand All @@ -1774,13 +1775,25 @@
"metadata": {
"hide_input": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"converting: 01_sync.ipynb\n"
]
}
],
"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",
"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 @@ -1790,14 +1803,33 @@
"metadata": {
"hide_input": false
},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"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"
]
}
],
"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 @@ -2235,20 +2267,6 @@
"from nbdev.export import *\n",
"notebook2script()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
1 change: 1 addition & 0 deletions nbs/07_clean.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@
" clean_nb(nb, clear_all=clear_all)\n",
" _print_output(nb)\n",
" return\n",
" path = None\n",
" if fname is None:\n",
" try: path = Config().path(\"nbs_path\")\n",
" except Exception as e: path = Path.cwd()\n",
Expand Down