Skip to content

Commit 8504e44

Browse files
committed
fix conflicts
2 parents df7e3d8 + 512f00c commit 8504e44

File tree

11 files changed

+31
-25
lines changed

11 files changed

+31
-25
lines changed

nbdev/_modidx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,4 +332,4 @@
332332
'nbdev.sync.nbdev_update': ('api/sync.html#nbdev_update', 'nbdev/sync.py')},
333333
'nbdev.test': { 'nbdev.test._keep_file': ('api/test.html#_keep_file', 'nbdev/test.py'),
334334
'nbdev.test.nbdev_test': ('api/test.html#nbdev_test', 'nbdev/test.py'),
335-
'nbdev.test.test_nb': ('api/test.html#test_nb', 'nbdev/test.py')}}}
335+
'nbdev.test.test_nb': ('api/test.html#test_nb', 'nbdev/test.py')}}}

nbdev/doclinks.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,16 @@ def _iter_py_cells(p):
4949
cells = p.read_text().split("\n# %% ")
5050
for cell in cells[1:]:
5151
top,code = cell.split('\n', 1)
52-
nb,idx = top.split()
52+
try: nb,idx = top.split()
53+
except ValueError:
54+
raise NotImplementedError(f"Unexpected format in '{p}' at cell:\n```\n# %% {cell.strip()}.\n```\n"
55+
"The expected format is: '# %% {nb_path} {cell_idx}'.")
5356
nb_path = None if nb=='auto' else (p.parent/nb).resolve() # NB paths are stored relative to .py file
5457
if code.endswith('\n'): code=code[:-1]
5558
yield AttrDict(nb=nb, idx=int(idx), code=code, nb_path=nb_path, py_path=p.resolve())
5659

5760
# %% ../nbs/api/doclinks.ipynb 11
58-
def _nbpath2html(p): return p.with_name(re.sub(r'\d+[a-zA-Z0-9]*_', '', p.name.lower())).with_suffix('.html')
61+
def _nbpath2html(p): return p.with_name(re.sub(r'\d+[a-zA-Z0-9]+_', '', p.name.lower())).with_suffix('.html')
5962

6063
# %% ../nbs/api/doclinks.ipynb 13
6164
def _get_modidx(py_path, code_root, nbs_path):
@@ -96,7 +99,7 @@ def _build_modidx(dest=None, nbs_path=None, skip_exists=False):
9699
code_root = dest.parent.resolve()
97100
for file in globtastic(dest, file_glob="*.py", skip_file_re='^_', skip_folder_re="\.ipynb_checkpoints"):
98101
res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))
99-
idxfile.write_text("# Autogenerated by nbdev\n\nd = "+pformat(res, width=140, indent=2, compact=True))
102+
idxfile.write_text("# Autogenerated by nbdev\n\nd = "+pformat(res, width=140, indent=2, compact=True)+'\n')
100103

101104
# %% ../nbs/api/doclinks.ipynb 20
102105
@delegates(globtastic)

nbdev/export.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ def black_format(cell, # Cell to format
4141
except: pass
4242

4343
# %% ../nbs/api/export.ipynb 9
44-
def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker):
44+
def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None):
4545
"Create module(s) from notebook"
4646
if lib_path is None: lib_path = get_config().lib_path
4747
exp = ExportModuleProc()
4848
nb = NBProcessor(nbname, [exp]+L(procs), debug=debug)
4949
nb.process()
5050
for mod,cells in exp.modules.items():
5151
all_cells = exp.in_all[mod]
52-
name = getattr(exp, 'default_exp', None) if mod=='#' else mod
53-
if not name:
52+
nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)
53+
if not nm:
5454
warn(f"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\n"
5555
"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\n"
5656
"See https://nbdev.fast.ai/getting_started.html for more information.")
5757
return
58-
mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#')
58+
mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')
5959
mm.make(cells, all_cells, lib_path=lib_path)

nbdev/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def end(self):
211211
mimetype = 'application/vnd.jupyter.widget-state+json'
212212
old = nested_idx(self.nb.metadata, 'widgets', mimetype) or {'state': {}}
213213
new = Widget.get_manager_state(drop_defaults=True)
214-
widgets = {**old, **new, 'state': {**old['state'], **new['state']}}
214+
widgets = {**old, **new, 'state': {**old.get('state', {}), **new['state']}}
215215
self.nb.metadata['widgets'] = {mimetype: widgets}
216216

217217
# %% ../nbs/api/processors.ipynb 42

nbdev/quarto.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ def _sprun(cmd):
3030

3131
def _install_linux():
3232
system(f'curl -LO {BASE_QUARTO_URL}quarto-linux-amd64.deb')
33-
system('sudo dpkg -i *64.deb && rm *64.deb')
33+
system('sudo dpkg -i quarto-linux-amd64.deb && rm quarto-linux-amd64.deb')
3434

3535
def _install_mac():
3636
system(f'curl -LO {BASE_QUARTO_URL}quarto-macos.pkg')
37-
system('sudo installer -pkg quarto-macos.pkg -target /')
37+
system('sudo installer -pkg quarto-macos.pkg -target / && rm quarto-macos.pkg')
3838

3939
@call_parse
4040
def install_quarto():
@@ -104,7 +104,7 @@ def _f(a,b): return Path(a),b
104104

105105
yml_path = path/'sidebar.yml'
106106
yml = "website:\n sidebar:\n contents:\n"
107-
yml += '\n'.join(f' {o}' for o in res)
107+
yml += '\n'.join(f' {o}' for o in res)+'\n'
108108
if printit: return print(yml)
109109
yml_path.write_text(yml)
110110

nbs/api/doclinks.ipynb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@
137137
" cells = p.read_text().split(\"\\n# %% \")\n",
138138
" for cell in cells[1:]:\n",
139139
" top,code = cell.split('\\n', 1)\n",
140-
" nb,idx = top.split()\n",
140+
" try: nb,idx = top.split()\n",
141+
" except ValueError:\n",
142+
" raise NotImplementedError(f\"Unexpected format in '{p}' at cell:\\n```\\n# %% {cell.strip()}.\\n```\\n\"\n",
143+
" \"The expected format is: '# %% {nb_path} {cell_idx}'.\")\n",
141144
" nb_path = None if nb=='auto' else (p.parent/nb).resolve() # NB paths are stored relative to .py file\n",
142145
" if code.endswith('\\n'): code=code[:-1]\n",
143146
" yield AttrDict(nb=nb, idx=int(idx), code=code, nb_path=nb_path, py_path=p.resolve())"
@@ -162,7 +165,7 @@
162165
"outputs": [],
163166
"source": [
164167
"#|export\n",
165-
"def _nbpath2html(p): return p.with_name(re.sub(r'\\d+[a-zA-Z0-9]*_', '', p.name.lower())).with_suffix('.html')"
168+
"def _nbpath2html(p): return p.with_name(re.sub(r'\\d+[a-zA-Z0-9]+_', '', p.name.lower())).with_suffix('.html')"
166169
]
167170
},
168171
{
@@ -237,7 +240,7 @@
237240
" code_root = dest.parent.resolve()\n",
238241
" for file in globtastic(dest, file_glob=\"*.py\", skip_file_re='^_', skip_folder_re=\"\\.ipynb_checkpoints\"):\n",
239242
" res['syms'].update(_get_modidx((dest.parent/file).resolve(), code_root, nbs_path=nbs_path))\n",
240-
" idxfile.write_text(\"# Autogenerated by nbdev\\n\\nd = \"+pformat(res, width=140, indent=2, compact=True))"
243+
" idxfile.write_text(\"# Autogenerated by nbdev\\n\\nd = \"+pformat(res, width=140, indent=2, compact=True)+'\\n')"
241244
]
242245
},
243246
{

nbs/api/export.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,21 +134,21 @@
134134
"outputs": [],
135135
"source": [
136136
"#|export\n",
137-
"def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker):\n",
137+
"def nb_export(nbname, lib_path=None, procs=black_format, debug=False, mod_maker=ModuleMaker, name=None):\n",
138138
" \"Create module(s) from notebook\"\n",
139139
" if lib_path is None: lib_path = get_config().lib_path\n",
140140
" exp = ExportModuleProc()\n",
141141
" nb = NBProcessor(nbname, [exp]+L(procs), debug=debug)\n",
142142
" nb.process()\n",
143143
" for mod,cells in exp.modules.items():\n",
144144
" all_cells = exp.in_all[mod]\n",
145-
" name = getattr(exp, 'default_exp', None) if mod=='#' else mod\n",
146-
" if not name:\n",
145+
" nm = ifnone(name, getattr(exp, 'default_exp', None) if mod=='#' else mod)\n",
146+
" if not nm:\n",
147147
" warn(f\"Notebook '{nbname}' uses `#|export` without `#|default_exp` cell.\\n\"\n",
148148
" \"Note nbdev2 no longer supports nbdev1 syntax. Run `nbdev_migrate` to upgrade.\\n\"\n",
149149
" \"See https://nbdev.fast.ai/getting_started.html for more information.\")\n",
150150
" return\n",
151-
" mm = mod_maker(dest=lib_path, name=name, nb_path=nbname, is_new=mod=='#')\n",
151+
" mm = mod_maker(dest=lib_path, name=nm, nb_path=nbname, is_new=bool(name) or mod=='#')\n",
152152
" mm.make(cells, all_cells, lib_path=lib_path)"
153153
]
154154
},

nbs/api/processors.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@
609609
" mimetype = 'application/vnd.jupyter.widget-state+json'\n",
610610
" old = nested_idx(self.nb.metadata, 'widgets', mimetype) or {'state': {}}\n",
611611
" new = Widget.get_manager_state(drop_defaults=True)\n",
612-
" widgets = {**old, **new, 'state': {**old['state'], **new['state']}}\n",
612+
" widgets = {**old, **new, 'state': {**old.get('state', {}), **new['state']}}\n",
613613
" self.nb.metadata['widgets'] = {mimetype: widgets}"
614614
]
615615
},

nbs/api/quarto.ipynb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,11 @@
8989
"\n",
9090
"def _install_linux():\n",
9191
" system(f'curl -LO {BASE_QUARTO_URL}quarto-linux-amd64.deb')\n",
92-
" system('sudo dpkg -i *64.deb && rm *64.deb')\n",
92+
" system('sudo dpkg -i quarto-linux-amd64.deb && rm quarto-linux-amd64.deb')\n",
9393
" \n",
9494
"def _install_mac():\n",
9595
" system(f'curl -LO {BASE_QUARTO_URL}quarto-macos.pkg')\n",
96-
" system('sudo installer -pkg quarto-macos.pkg -target /')\n",
96+
" system('sudo installer -pkg quarto-macos.pkg -target / && rm quarto-macos.pkg')\n",
9797
"\n",
9898
"@call_parse\n",
9999
"def install_quarto():\n",
@@ -195,7 +195,7 @@
195195
"\n",
196196
" yml_path = path/'sidebar.yml'\n",
197197
" yml = \"website:\\n sidebar:\\n contents:\\n\"\n",
198-
" yml += '\\n'.join(f' {o}' for o in res)\n",
198+
" yml += '\\n'.join(f' {o}' for o in res)+'\\n'\n",
199199
" if printit: return print(yml)\n",
200200
" yml_path.write_text(yml)"
201201
]

nbs/blog/posts/2022-11-07-spaces/index.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,4 +220,4 @@ After a couple of minutes, you will see your app published! This app is publish
220220
Hopefully you felt something magical while doing this example. Even though the target application required you to write a python script (`app.py`), you didn't have to refactor your script from a notebook! I believe that you shouldn't have to refactor your code and switch contexts even when creating python packages! If this intrigues you, check out [nbdev](https://nbdev.fast.ai/blog/posts/2022-07-28-nbdev2/)
221221

222222

223-
[^1]: The prompt that generated the cover image is: "A data scientist at a computer in a futuristic city with a view of the planet Jupyter in the night sky, trending on artstation, high detail, science-fiction"
223+
[^1]: The prompt that generated the cover image is: "A data scientist at a computer in a futuristic city with a view of the planet Jupyter in the night sky, trending on artstation, high detail, science-fiction"

0 commit comments

Comments
 (0)