Skip to content

Commit e6a6bda

Browse files
committed
run export
1 parent ace6c61 commit e6a6bda

File tree

18 files changed

+246
-246
lines changed

18 files changed

+246
-246
lines changed

nbdev/clean.py

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

33
# %% auto 0
44
__all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'clean_jupyter', 'nbdev_install_hooks']
55

6-
# %% ../nbs/api/clean.ipynb 2
6+
# %% ../nbs/api/11_clean.ipynb 2
77
import ast,warnings,stat
88
from astunparse import unparse
99
from textwrap import indent
@@ -18,7 +18,7 @@
1818
from .sync import *
1919
from .process import first_code_ln
2020

21-
# %% ../nbs/api/clean.ipynb 6
21+
# %% ../nbs/api/11_clean.ipynb 6
2222
@call_parse
2323
def nbdev_trust(
2424
fname:str=None, # A notebook name or glob to trust
@@ -44,7 +44,7 @@ def nbdev_trust(
4444
if not NotebookNotary().check_signature(nb): NotebookNotary().sign(nb)
4545
check_fname.touch(exist_ok=True)
4646

47-
# %% ../nbs/api/clean.ipynb 9
47+
# %% ../nbs/api/11_clean.ipynb 9
4848
_repr_id_re = re.compile('(<.*?)( at 0x[0-9a-fA-F]+)(>)')
4949

5050
_sub = partial(_repr_id_re.sub, r'\1\3')
@@ -54,7 +54,7 @@ def _skip_or_sub(x): return _sub(x) if "at 0x" in x else x
5454
def _clean_cell_output_id(lines):
5555
return _skip_or_sub(lines) if isinstance(lines,str) else [_skip_or_sub(o) for o in lines]
5656

57-
# %% ../nbs/api/clean.ipynb 11
57+
# %% ../nbs/api/11_clean.ipynb 11
5858
def _clean_cell_output(cell, clean_ids):
5959
"Remove `cell` output execution count and optionally ids from text reprs"
6060
outputs = cell.get('outputs', [])
@@ -68,7 +68,7 @@ def _clean_cell_output(cell, clean_ids):
6868
if 'text' in o: o['text'] = _clean_cell_output_id(o['text'])
6969
o.get('metadata', {}).pop('tags', None)
7070

71-
# %% ../nbs/api/clean.ipynb 12
71+
# %% ../nbs/api/11_clean.ipynb 12
7272
def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
7373
"Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"
7474
if 'execution_count' in cell: cell['execution_count'] = None
@@ -79,7 +79,7 @@ def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
7979
cell['metadata'] = {} if clear_all else {
8080
k:v for k,v in cell['metadata'].items() if k in allowed_metadata_keys}
8181

82-
# %% ../nbs/api/clean.ipynb 13
82+
# %% ../nbs/api/11_clean.ipynb 13
8383
def clean_nb(
8484
nb, # The notebook to clean
8585
clear_all=False, # Remove all cell metadata and cell outputs?
@@ -97,12 +97,12 @@ def clean_nb(
9797
nb['metadata']['kernelspec']['display_name'] = nb.metadata.kernelspec.name
9898
nb['metadata'] = {k:v for k,v in nb['metadata'].items() if k in metadata_keys}
9999

100-
# %% ../nbs/api/clean.ipynb 24
100+
# %% ../nbs/api/11_clean.ipynb 24
101101
def _reconfigure(*strms):
102102
for s in strms:
103103
if hasattr(s,'reconfigure'): s.reconfigure(encoding='utf-8')
104104

105-
# %% ../nbs/api/clean.ipynb 25
105+
# %% ../nbs/api/11_clean.ipynb 25
106106
def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
107107
if not f_out: f_out = f_in
108108
if isinstance(f_in, (str,Path)): f_in = Path(f_in).open()
@@ -115,15 +115,15 @@ def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
115115
warn(f'{warn_msg}')
116116
warn(e)
117117

118-
# %% ../nbs/api/clean.ipynb 26
118+
# %% ../nbs/api/11_clean.ipynb 26
119119
def _nbdev_clean(nb, path=None, clear_all=None):
120120
cfg = get_config(path=path)
121121
clear_all = clear_all or cfg.clear_all
122122
allowed_metadata_keys = cfg.get("allowed_metadata_keys").split()
123123
allowed_cell_metadata_keys = cfg.get("allowed_cell_metadata_keys").split()
124124
return clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
125125

126-
# %% ../nbs/api/clean.ipynb 27
126+
# %% ../nbs/api/11_clean.ipynb 27
127127
@call_parse
128128
def nbdev_clean(
129129
fname:str=None, # A notebook name or glob to clean
@@ -139,15 +139,15 @@ def nbdev_clean(
139139
if fname is None: fname = get_config().nbs_path
140140
for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)
141141

142-
# %% ../nbs/api/clean.ipynb 30
142+
# %% ../nbs/api/11_clean.ipynb 30
143143
def clean_jupyter(path, model, **kwargs):
144144
"Clean Jupyter `model` pre save to `path`"
145145
if not (model['type']=='notebook' and model['content']['nbformat']==4): return
146146
get_config.cache_clear() # Allow config changes without restarting Jupyter
147147
jupyter_hooks = get_config(path=path).jupyter_hooks
148148
if jupyter_hooks: _nbdev_clean(model['content'], path=path)
149149

150-
# %% ../nbs/api/clean.ipynb 33
150+
# %% ../nbs/api/11_clean.ipynb 33
151151
_pre_save_hook_src = '''
152152
def nbdev_clean_jupyter(**kwargs):
153153
try: from nbdev.clean import clean_jupyter
@@ -157,7 +157,7 @@ def nbdev_clean_jupyter(**kwargs):
157157
c.ContentsManager.pre_save_hook = nbdev_clean_jupyter'''.strip()
158158
_pre_save_hook_re = re.compile(r'c\.(File)?ContentsManager\.pre_save_hook')
159159

160-
# %% ../nbs/api/clean.ipynb 34
160+
# %% ../nbs/api/11_clean.ipynb 34
161161
def _add_jupyter_hooks(src, path):
162162
if _pre_save_hook_src in src: return
163163
mod = ast.parse(src)
@@ -175,12 +175,12 @@ def _add_jupyter_hooks(src, path):
175175
if src: src+='\n\n'
176176
return src+_pre_save_hook_src
177177

178-
# %% ../nbs/api/clean.ipynb 38
178+
# %% ../nbs/api/11_clean.ipynb 38
179179
def _git_root():
180180
try: return Path(run('git rev-parse --show-toplevel'))
181181
except OSError: return None
182182

183-
# %% ../nbs/api/clean.ipynb 41
183+
# %% ../nbs/api/11_clean.ipynb 41
184184
@call_parse
185185
def nbdev_install_hooks():
186186
"Install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks"

nbdev/cli.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/cli.ipynb.
1+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/13_cli.ipynb.
22

3-
# %% ../nbs/api/cli.ipynb 2
3+
# %% ../nbs/api/13_cli.ipynb 2
44
from __future__ import annotations
55
import warnings
66

@@ -27,7 +27,7 @@
2727
# %% auto 0
2828
__all__ = ['nbdev_filter', 'extract_tgz', 'nbdev_new', 'chelp']
2929

30-
# %% ../nbs/api/cli.ipynb 5
30+
# %% ../nbs/api/13_cli.ipynb 5
3131
@call_parse
3232
def nbdev_filter(
3333
nb_txt:str=None, # Notebook text (uses stdin if not provided)
@@ -50,20 +50,20 @@ def nbdev_filter(
5050
if printit: print(res, flush=True)
5151
else: return res
5252

53-
# %% ../nbs/api/cli.ipynb 8
53+
# %% ../nbs/api/13_cli.ipynb 8
5454
def extract_tgz(url, dest='.'):
5555
from fastcore.net import urlopen
5656
with urlopen(url) as u: tarfile.open(mode='r:gz', fileobj=u).extractall(dest)
5757

58-
# %% ../nbs/api/cli.ipynb 9
58+
# %% ../nbs/api/13_cli.ipynb 9
5959
def _render_nb(fn, cfg):
6060
"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
6161
txt = fn.read_text()
6262
txt = txt.replace('from your_lib.core', f'from {cfg.lib_path}.core') # for compatibility with old templates
6363
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
6464
fn.write_text(txt)
6565

66-
# %% ../nbs/api/cli.ipynb 10
66+
# %% ../nbs/api/13_cli.ipynb 10
6767
def _update_repo_meta(cfg):
6868
"Enable gh pages and update the homepage and description in your GitHub repo."
6969
token=os.getenv('GITHUB_TOKEN')
@@ -74,7 +74,7 @@ def _update_repo_meta(cfg):
7474
except HTTPError:print(f"Could not update the description & URL on the repo: {cfg.user}/{cfg.repo} using $GITHUB_TOKEN.\n"
7575
"Use a token with the correction permissions or perform these steps manually.")
7676

77-
# %% ../nbs/api/cli.ipynb 11
77+
# %% ../nbs/api/13_cli.ipynb 11
7878
@call_parse
7979
@delegates(nbdev_create_config)
8080
def nbdev_new(**kwargs):
@@ -108,7 +108,7 @@ def nbdev_new(**kwargs):
108108
nbdev_export.__wrapped__()
109109
nbdev_readme.__wrapped__()
110110

111-
# %% ../nbs/api/cli.ipynb 15
111+
# %% ../nbs/api/13_cli.ipynb 15
112112
@call_parse
113113
def chelp():
114114
"Show help for all console scripts"

nbdev/config.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
"""Read and write nbdev's `settings.ini` file.
22
`get_config` is the main function for reading settings."""
33

4-
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/config.ipynb.
4+
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
55

66
# %% auto 0
77
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'create_output', 'show_src', 'update_version', 'add_init',
88
'write_cells']
99

10-
# %% ../nbs/api/config.ipynb 2
10+
# %% ../nbs/api/01_config.ipynb 2
1111
_doc_ = """Read and write nbdev's `settings.ini` file.
1212
`get_config` is the main function for reading settings."""
1313

14-
# %% ../nbs/api/config.ipynb 3
14+
# %% ../nbs/api/01_config.ipynb 3
1515
from datetime import datetime
1616
from fastcore.docments import *
1717
from fastcore.utils import *
@@ -25,16 +25,16 @@
2525
from execnb.nbio import read_nb,NbCell
2626
from urllib.error import HTTPError
2727

28-
# %% ../nbs/api/config.ipynb 8
28+
# %% ../nbs/api/01_config.ipynb 8
2929
_nbdev_home_dir = 'nbdev' # sub-directory of xdg base dir
3030
_nbdev_cfg_name = 'settings.ini'
3131

32-
# %% ../nbs/api/config.ipynb 9
32+
# %% ../nbs/api/01_config.ipynb 9
3333
def _git_repo():
3434
try: return repo_details(run('git config --get remote.origin.url'))[1]
3535
except OSError: return
3636

37-
# %% ../nbs/api/config.ipynb 11
37+
# %% ../nbs/api/01_config.ipynb 11
3838
def _apply_defaults(
3939
cfg,
4040
lib_name='%(repo)s', # Package name
@@ -78,7 +78,7 @@ def _apply_defaults(
7878
cfg[k] = v
7979
return cfg
8080

81-
# %% ../nbs/api/config.ipynb 12
81+
# %% ../nbs/api/01_config.ipynb 12
8282
def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
8383
from ghapi.all import GhApi
8484
api = GhApi(owner=owner, repo=repo, token=os.getenv('GITHUB_TOKEN'))
@@ -94,7 +94,7 @@ def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
9494

9595
return r.default_branch, default_kw if not getattr(r, 'topics', []) else ' '.join(r.topics), r.description
9696

97-
# %% ../nbs/api/config.ipynb 14
97+
# %% ../nbs/api/01_config.ipynb 14
9898
def _fetch_from_git(raise_err=False):
9999
"Get information for settings.ini from the user."
100100
res={}
@@ -110,7 +110,7 @@ def _fetch_from_git(raise_err=False):
110110
else: res['lib_name'] = res['repo'].replace('-','_')
111111
return res
112112

113-
# %% ../nbs/api/config.ipynb 16
113+
# %% ../nbs/api/01_config.ipynb 16
114114
def _prompt_user(cfg, inferred):
115115
"Let user input values not in `cfg` or `inferred`."
116116
res = cfg.copy()
@@ -124,7 +124,7 @@ def _prompt_user(cfg, inferred):
124124
print(msg+res[k]+' # Automatically inferred from git')
125125
return res
126126

127-
# %% ../nbs/api/config.ipynb 18
127+
# %% ../nbs/api/01_config.ipynb 18
128128
def _cfg2txt(cfg, head, sections, tail=''):
129129
"Render `cfg` with commented sections."
130130
nm = cfg.d.name
@@ -136,7 +136,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
136136
res += tail
137137
return res.strip()
138138

139-
# %% ../nbs/api/config.ipynb 20
139+
# %% ../nbs/api/01_config.ipynb 20
140140
_nbdev_cfg_head = '''# All sections below are required unless otherwise specified.
141141
# See https://github.com/fastai/nbdev/blob/master/settings.ini for examples.
142142
@@ -151,7 +151,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
151151
# console_scripts =
152152
'''
153153

154-
# %% ../nbs/api/config.ipynb 21
154+
# %% ../nbs/api/01_config.ipynb 21
155155
@call_parse
156156
@delegates(_apply_defaults, but='cfg')
157157
def nbdev_create_config(
@@ -177,19 +177,19 @@ def nbdev_create_config(
177177
cfg_fn = Path(path)/cfg_name
178178
print(f'{cfg_fn} created.')
179179

180-
# %% ../nbs/api/config.ipynb 24
180+
# %% ../nbs/api/01_config.ipynb 24
181181
def _nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None):
182182
cfg_path = path = Path.cwd() if path is None else Path(path)
183183
while cfg_path != cfg_path.parent and not (cfg_path/cfg_name).exists(): cfg_path = cfg_path.parent
184184
if not (cfg_path/cfg_name).exists(): cfg_path = path
185185
return cfg_path/cfg_name
186186

187-
# %% ../nbs/api/config.ipynb 26
187+
# %% ../nbs/api/01_config.ipynb 26
188188
def _xdg_config_paths(cfg_name=_nbdev_cfg_name):
189189
xdg_config_paths = reversed([xdg_config_home()]+xdg_config_dirs())
190190
return [o/_nbdev_home_dir/cfg_name for o in xdg_config_paths]
191191

192-
# %% ../nbs/api/config.ipynb 27
192+
# %% ../nbs/api/01_config.ipynb 27
193193
def _type(t): return bool if t==bool_arg else t
194194
_types = {k:_type(v['anno']) for k,v in docments(_apply_defaults,full=True,returns=False).items() if k != 'cfg'}
195195

@@ -201,22 +201,22 @@ def get_config(cfg_name=_nbdev_cfg_name, path=None):
201201
cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files, types=_types)
202202
return _apply_defaults(cfg)
203203

204-
# %% ../nbs/api/config.ipynb 42
204+
# %% ../nbs/api/01_config.ipynb 42
205205
def config_key(c, default=None, path=True, missing_ok=None):
206206
"Deprecated: use `get_config().get` or `get_config().path` instead."
207207
warn("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead.", DeprecationWarning)
208208
return get_config().path(c, default) if path else get_config().get(c, default)
209209

210-
# %% ../nbs/api/config.ipynb 44
210+
# %% ../nbs/api/01_config.ipynb 44
211211
def create_output(txt, mime):
212212
"Add a cell output containing `txt` of the `mime` text MIME sub-type"
213213
return [{"data": { f"text/{mime}": str(txt).splitlines(True) },
214214
"execution_count": 1, "metadata": {}, "output_type": "execute_result"}]
215215

216-
# %% ../nbs/api/config.ipynb 45
216+
# %% ../nbs/api/01_config.ipynb 45
217217
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
218218

219-
# %% ../nbs/api/config.ipynb 48
219+
# %% ../nbs/api/01_config.ipynb 48
220220
_re_version = re.compile('^__version__\s*=.*$', re.MULTILINE)
221221
_init = '__init__.py'
222222

@@ -245,13 +245,13 @@ def add_init(path=None):
245245
if _has_py(fs) or any(filter(_has_py, subds)) and not (r/_init).exists(): (r/_init).touch()
246246
if get_config().get('put_version_in_init', True): update_version(path)
247247

248-
# %% ../nbs/api/config.ipynb 51
248+
# %% ../nbs/api/01_config.ipynb 51
249249
def write_cells(cells, hdr, file, offset=0):
250250
"Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
251251
for cell in cells:
252252
if cell.source.strip(): file.write(f'\n\n{hdr} {cell.idx_+offset}\n{cell.source}')
253253

254-
# %% ../nbs/api/config.ipynb 52
254+
# %% ../nbs/api/01_config.ipynb 52
255255
def _basic_export_nb(fname, name, dest=None):
256256
"Basic exporter to bootstrap nbdev."
257257
if dest is None: dest = get_config().lib_path

0 commit comments

Comments
 (0)