Skip to content

Commit 7cfef24

Browse files
committed
fixes #699
1 parent 973759d commit 7cfef24

File tree

7 files changed

+32
-93
lines changed

7 files changed

+32
-93
lines changed

nbdev/_modidx.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
'nbdev_trust=nbdev.clean:nbdev_trust\n'
1313
'nbdev_clean=nbdev.clean:nbdev_clean\n'
1414
'nbdev_install_hooks=nbdev.clean:nbdev_install_hooks\n'
15-
'nbdev_install_jupyter_hooks=nbdev.clean:nbdev_install_jupyter_hooks\n'
1615
'nbdev_filter=nbdev.cli:nbdev_filter\n'
1716
'nbdev_quarto=nbdev.cli:nbdev_quarto\n'
1817
'nbdev_ghp_deploy=nbdev.cli:nbdev_ghp_deploy\n'
@@ -51,7 +50,7 @@
5150
'readme_nb': 'getting_started.ipynb',
5251
'recursive': 'False',
5352
'repo': 'nbdev',
54-
'requirements': 'fastcore>=1.5.8 execnb astunparse ghapi',
53+
'requirements': 'fastcore>=1.5.11 execnb astunparse ghapi',
5554
'status': '2',
5655
'title': 'nbdev',
5756
'tst_flags': 'notest',
@@ -61,7 +60,6 @@
6160
'nbdev.clean.clean_nb': 'https://nbdev.fast.ai/clean.html#clean_nb',
6261
'nbdev.clean.nbdev_clean': 'https://nbdev.fast.ai/clean.html#nbdev_clean',
6362
'nbdev.clean.nbdev_install_hooks': 'https://nbdev.fast.ai/clean.html#nbdev_install_hooks',
64-
'nbdev.clean.nbdev_install_jupyter_hooks': 'https://nbdev.fast.ai/clean.html#nbdev_install_jupyter_hooks',
6563
'nbdev.clean.nbdev_trust': 'https://nbdev.fast.ai/clean.html#nbdev_trust',
6664
'nbdev.clean.process_write': 'https://nbdev.fast.ai/clean.html#process_write'},
6765
'nbdev.cli': { 'nbdev.cli.FilterDefaults': 'https://nbdev.fast.ai/cli.html#filterdefaults',

nbdev/clean.py

Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/11_clean.ipynb.
22

33
# %% auto 0
4-
__all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'nbdev_install_hooks', 'clean_jupyter',
5-
'nbdev_install_jupyter_hooks']
4+
__all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'clean_jupyter', 'nbdev_install_hooks']
65

76
# %% ../nbs/11_clean.ipynb 2
87
import warnings,stat
@@ -121,40 +120,6 @@ def nbdev_clean(
121120
for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)
122121

123122
# %% ../nbs/11_clean.ipynb 24
124-
@call_parse
125-
def nbdev_install_hooks():
126-
"Install git hooks to clean and trust notebooks automatically"
127-
nb_path = config_key("nbs_path", '.')
128-
path = get_config().config_path
129-
hook_path = path/'.git'/'hooks'
130-
fn = hook_path/'post-merge'
131-
hook_path.mkdir(parents=True, exist_ok=True)
132-
fn.write_text("#!/bin/bash\nnbdev_trust")
133-
os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)
134-
#Clean notebooks on commit/diff
135-
(path/'.gitconfig').write_text("""# Generated by nbdev_install_hooks
136-
#
137-
# If you need to disable this instrumentation do:
138-
# git config --local --unset include.path
139-
#
140-
# To restore the filter
141-
# git config --local include.path .gitconfig
142-
#
143-
# If you see notebooks not stripped, checked the filters are applied in .gitattributes
144-
#
145-
[filter "clean-nbs"]
146-
clean = nbdev_clean --stdin
147-
smudge = cat
148-
required = true
149-
[diff "ipynb"]
150-
textconv = nbdev_clean --disp --fname
151-
""")
152-
cmd = "git config --local include.path ../.gitconfig"
153-
run(cmd)
154-
print("Hooks are installed and repo's .gitconfig is now trusted")
155-
(nb_path/'.gitattributes').write_text("**/*.ipynb filter=clean-nbs\n**/*.ipynb diff=ipynb\n")
156-
157-
# %% ../nbs/11_clean.ipynb 25
158123
def clean_jupyter(path, model, **kwargs):
159124
"Clean Jupyter `model` pre save to `path`"
160125
get_config.cache_clear() # Reset Jupyter's cache
@@ -165,17 +130,17 @@ def clean_jupyter(path, model, **kwargs):
165130
is_nb_v4 = (model['type'],model['content']['nbformat']) == ('notebook',4)
166131
if in_nbdev_repo and jupyter_hooks and is_nb_v4: _nbdev_clean(model['content'])
167132

168-
# %% ../nbs/11_clean.ipynb 27
133+
# %% ../nbs/11_clean.ipynb 26
169134
def _nested_setdefault(o, attr, default):
170135
"Same as `setdefault`, but if `attr` includes a `.`, then looks inside nested objects"
171136
attrs = attr.split('.')
172137
for a in attrs[:-1]: o = o.setdefault(a, type(o)())
173138
return o.setdefault(attrs[-1], default)
174139

175-
# %% ../nbs/11_clean.ipynb 31
140+
# %% ../nbs/11_clean.ipynb 30
176141
@call_parse
177-
def nbdev_install_jupyter_hooks():
178-
"Install Jupyter hooks to clean notebooks on save"
142+
def nbdev_install_hooks():
143+
"Install Jupyter and git hooks to clean notebooks on save and trust notebooks automatically"
179144
cfg_path = Path.home()/'.jupyter'
180145
cfg_fns = [cfg_path/f'jupyter_{o}_config.json' for o in ('notebook','server')]
181146
attr,hook = 'ContentsManager.pre_save_hook','nbdev.clean.clean_jupyter'
@@ -188,3 +153,12 @@ def nbdev_install_jupyter_hooks():
188153
elif val != hook:
189154
sys.stderr.write(f"Can't install hook to '{p}' since it already contains `{attr} = '{val}'`. "
190155
f"Manually update to `{attr} = '{hook}'` for this functionality.")
156+
157+
nb_path = config_key("nbs_path", '.')
158+
path = get_config().config_path
159+
hook_path = path/'.git'/'hooks'
160+
fn = hook_path/'post-merge'
161+
hook_path.mkdir(parents=True, exist_ok=True)
162+
fn.write_text("#!/bin/bash\nnbdev_trust")
163+
os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)
164+
print("Hooks are installed.")

nbdev/processors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def clean_show_doc(cell):
121121
def _show_docs(trees):
122122
return [t for t in trees if isinstance(t,ast.Expr) and nested_attr(t, 'value.func.id')=='show_doc']
123123

124-
_show_dirs = {'export','exports','exporti'}
124+
_show_dirs = {'export','exports','exporti','exec_doc'}
125125

126126
def _do_eval(cell):
127127
if cell_lang(cell) != 'python': return

nbs/09_processors.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@
439439
"def _show_docs(trees):\n",
440440
" return [t for t in trees if isinstance(t,ast.Expr) and nested_attr(t, 'value.func.id')=='show_doc']\n",
441441
"\n",
442-
"_show_dirs = {'export','exports','exporti'}\n",
442+
"_show_dirs = {'export','exports','exporti','exec_doc'}\n",
443443
"\n",
444444
"def _do_eval(cell):\n",
445445
" if cell_lang(cell) != 'python': return\n",

nbs/11_clean.ipynb

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -326,47 +326,6 @@
326326
"```"
327327
]
328328
},
329-
{
330-
"cell_type": "code",
331-
"execution_count": null,
332-
"metadata": {},
333-
"outputs": [],
334-
"source": [
335-
"#|export\n",
336-
"@call_parse\n",
337-
"def nbdev_install_hooks():\n",
338-
" \"Install git hooks to clean and trust notebooks automatically\"\n",
339-
" nb_path = config_key(\"nbs_path\", '.')\n",
340-
" path = get_config().config_path\n",
341-
" hook_path = path/'.git'/'hooks'\n",
342-
" fn = hook_path/'post-merge'\n",
343-
" hook_path.mkdir(parents=True, exist_ok=True)\n",
344-
" fn.write_text(\"#!/bin/bash\\nnbdev_trust\")\n",
345-
" os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)\n",
346-
" #Clean notebooks on commit/diff\n",
347-
" (path/'.gitconfig').write_text(\"\"\"# Generated by nbdev_install_hooks\n",
348-
"#\n",
349-
"# If you need to disable this instrumentation do:\n",
350-
"# git config --local --unset include.path\n",
351-
"#\n",
352-
"# To restore the filter\n",
353-
"# git config --local include.path .gitconfig\n",
354-
"#\n",
355-
"# If you see notebooks not stripped, checked the filters are applied in .gitattributes\n",
356-
"#\n",
357-
"[filter \"clean-nbs\"]\n",
358-
" clean = nbdev_clean --stdin\n",
359-
" smudge = cat\n",
360-
" required = true\n",
361-
"[diff \"ipynb\"]\n",
362-
" textconv = nbdev_clean --disp --fname\n",
363-
"\"\"\")\n",
364-
" cmd = \"git config --local include.path ../.gitconfig\"\n",
365-
" run(cmd)\n",
366-
" print(\"Hooks are installed and repo's .gitconfig is now trusted\")\n",
367-
" (nb_path/'.gitattributes').write_text(\"**/*.ipynb filter=clean-nbs\\n**/*.ipynb diff=ipynb\\n\")"
368-
]
369-
},
370329
{
371330
"cell_type": "code",
372331
"execution_count": null,
@@ -389,7 +348,7 @@
389348
"cell_type": "markdown",
390349
"metadata": {},
391350
"source": [
392-
"`clean_jupyter` implements Jupyter's [`ContentsManager.pre_save_hook`](https://jupyter-notebook.readthedocs.io/en/6.4.12/extending/savehooks.html). The easiest way to install it as a Jupyter Notebook or Lab pre-save hook is by running `nbdev_install_jupyter_hooks`."
351+
"`clean_jupyter` implements Jupyter's [`ContentsManager.pre_save_hook`](https://jupyter-notebook.readthedocs.io/en/6.4.12/extending/savehooks.html). The easiest way to install it as a Jupyter Notebook or Lab pre-save hook is by running `nbdev_install_hooks`."
393352
]
394353
},
395354
{
@@ -450,8 +409,8 @@
450409
"source": [
451410
"#|export\n",
452411
"@call_parse\n",
453-
"def nbdev_install_jupyter_hooks():\n",
454-
" \"Install Jupyter hooks to clean notebooks on save\"\n",
412+
"def nbdev_install_hooks():\n",
413+
" \"Install Jupyter and git hooks to clean notebooks on save and trust notebooks automatically\"\n",
455414
" cfg_path = Path.home()/'.jupyter'\n",
456415
" cfg_fns = [cfg_path/f'jupyter_{o}_config.json' for o in ('notebook','server')]\n",
457416
" attr,hook = 'ContentsManager.pre_save_hook','nbdev.clean.clean_jupyter'\n",
@@ -463,7 +422,16 @@
463422
" fn.write_text(dumps(obj2dict(cfg), indent=2))\n",
464423
" elif val != hook:\n",
465424
" sys.stderr.write(f\"Can't install hook to '{p}' since it already contains `{attr} = '{val}'`. \"\n",
466-
" f\"Manually update to `{attr} = '{hook}'` for this functionality.\")"
425+
" f\"Manually update to `{attr} = '{hook}'` for this functionality.\")\n",
426+
"\n",
427+
" nb_path = config_key(\"nbs_path\", '.')\n",
428+
" path = get_config().config_path\n",
429+
" hook_path = path/'.git'/'hooks'\n",
430+
" fn = hook_path/'post-merge'\n",
431+
" hook_path.mkdir(parents=True, exist_ok=True)\n",
432+
" fn.write_text(\"#!/bin/bash\\nnbdev_trust\")\n",
433+
" os.chmod(fn, os.stat(fn).st_mode | stat.S_IEXEC)\n",
434+
" print(\"Hooks are installed.\")"
467435
]
468436
},
469437
{
@@ -487,8 +455,7 @@
487455
"outputs": [],
488456
"source": [
489457
"#|hide\n",
490-
"#|eval:false\n",
491-
"from nbdev.doclinks import nbdev_export\n",
458+
"from nbdev import nbdev_export\n",
492459
"nbdev_export()"
493460
]
494461
},

nbs/getting_started.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
}
146146
],
147147
"source": [
148+
"#| exec_doc\n",
148149
"!nbdev_help"
149150
]
150151
},

settings.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ console_scripts = nbdev_create_config=nbdev.read:nbdev_create_config
3131
nbdev_trust=nbdev.clean:nbdev_trust
3232
nbdev_clean=nbdev.clean:nbdev_clean
3333
nbdev_install_hooks=nbdev.clean:nbdev_install_hooks
34-
nbdev_install_jupyter_hooks=nbdev.clean:nbdev_install_jupyter_hooks
3534
nbdev_filter=nbdev.cli:nbdev_filter
3635
nbdev_quarto=nbdev.cli:nbdev_quarto
3736
nbdev_ghp_deploy=nbdev.cli:nbdev_ghp_deploy

0 commit comments

Comments
 (0)