nbdev 2.4.10__py3-none-any.whl → 2.4.12__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nbdev/__init__.py +1 -1
- nbdev/_modidx.py +1 -0
- nbdev/clean.py +22 -19
- nbdev/cli.py +12 -12
- nbdev/config.py +29 -28
- nbdev/diff.py +9 -9
- nbdev/doclinks.py +29 -31
- nbdev/export.py +7 -7
- nbdev/frontmatter.py +4 -4
- nbdev/maker.py +22 -22
- nbdev/merge.py +10 -10
- nbdev/migrate.py +18 -18
- nbdev/process.py +15 -15
- nbdev/processors.py +26 -26
- nbdev/qmd.py +9 -9
- nbdev/quarto.py +25 -25
- nbdev/release.py +41 -39
- nbdev/serve.py +5 -5
- nbdev/showdoc.py +7 -7
- nbdev/sync.py +14 -11
- nbdev/test.py +5 -5
- {nbdev-2.4.10.dist-info → nbdev-2.4.12.dist-info}/METADATA +2 -2
- nbdev-2.4.12.dist-info/RECORD +30 -0
- nbdev-2.4.10.dist-info/RECORD +0 -30
- {nbdev-2.4.10.dist-info → nbdev-2.4.12.dist-info}/WHEEL +0 -0
- {nbdev-2.4.10.dist-info → nbdev-2.4.12.dist-info}/entry_points.txt +0 -0
- {nbdev-2.4.10.dist-info → nbdev-2.4.12.dist-info}/licenses/LICENSE +0 -0
- {nbdev-2.4.10.dist-info → nbdev-2.4.12.dist-info}/top_level.txt +0 -0
nbdev/__init__.py
CHANGED
nbdev/_modidx.py
CHANGED
|
@@ -309,6 +309,7 @@ d = { 'settings': { 'branch': 'main',
|
|
|
309
309
|
'nbdev.release.conda_output_path': ('api/release.html#conda_output_path', 'nbdev/release.py'),
|
|
310
310
|
'nbdev.release.latest_pypi': ('api/release.html#latest_pypi', 'nbdev/release.py'),
|
|
311
311
|
'nbdev.release.nbdev_bump_version': ('api/release.html#nbdev_bump_version', 'nbdev/release.py'),
|
|
312
|
+
'nbdev.release.push_release': ('api/release.html#push_release', 'nbdev/release.py'),
|
|
312
313
|
'nbdev.release.pypi_details': ('api/release.html#pypi_details', 'nbdev/release.py'),
|
|
313
314
|
'nbdev.release.pypi_json': ('api/release.html#pypi_json', 'nbdev/release.py'),
|
|
314
315
|
'nbdev.release.release_both': ('api/release.html#release_both', 'nbdev/release.py'),
|
nbdev/clean.py
CHANGED
|
@@ -2,31 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/11_clean.ipynb.
|
|
4
4
|
|
|
5
|
-
# %% auto 0
|
|
5
|
+
# %% auto #0
|
|
6
6
|
__all__ = ['nbdev_trust', 'clean_nb', 'process_write', 'nbdev_clean', 'clean_jupyter', 'nbdev_install_hooks']
|
|
7
7
|
|
|
8
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
8
|
+
# %% ../nbs/api/11_clean.ipynb #07637414
|
|
9
9
|
import ast,warnings,stat
|
|
10
10
|
from astunparse import unparse
|
|
11
11
|
from textwrap import indent
|
|
12
12
|
|
|
13
13
|
from execnb.nbio import *
|
|
14
14
|
from fastcore.script import *
|
|
15
|
-
from fastcore.
|
|
16
|
-
from fastcore.
|
|
15
|
+
from fastcore.utils import *
|
|
16
|
+
from fastcore.xtras import *
|
|
17
17
|
|
|
18
18
|
from .imports import *
|
|
19
19
|
from .config import *
|
|
20
20
|
from .sync import *
|
|
21
21
|
from .process import first_code_ln
|
|
22
22
|
|
|
23
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
23
|
+
# %% ../nbs/api/11_clean.ipynb #4259f92c
|
|
24
24
|
@call_parse
|
|
25
25
|
def nbdev_trust(
|
|
26
26
|
fname:str=None, # A notebook name or glob to trust
|
|
27
27
|
force_all:bool=False # Also trust notebooks that haven't changed
|
|
28
28
|
):
|
|
29
|
-
"Trust notebooks matching `fname
|
|
29
|
+
"Trust notebooks matching `fname`."
|
|
30
30
|
try: from nbformat.sign import NotebookNotary
|
|
31
31
|
except:
|
|
32
32
|
import warnings
|
|
@@ -47,7 +47,7 @@ def nbdev_trust(
|
|
|
47
47
|
if not NotebookNotary().check_signature(nb): NotebookNotary().sign(nb)
|
|
48
48
|
check_fname.touch(exist_ok=True)
|
|
49
49
|
|
|
50
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
50
|
+
# %% ../nbs/api/11_clean.ipynb #a2ba2b4c
|
|
51
51
|
_repr_id_re = re.compile('(<.*?)( at 0x[0-9a-fA-F]+)(>)')
|
|
52
52
|
|
|
53
53
|
_sub = partial(_repr_id_re.sub, r'\1\3')
|
|
@@ -57,7 +57,7 @@ def _skip_or_sub(x): return _sub(x) if "at 0x" in x else x
|
|
|
57
57
|
def _clean_cell_output_id(lines):
|
|
58
58
|
return _skip_or_sub(lines) if isinstance(lines,str) else [_skip_or_sub(o) for o in lines]
|
|
59
59
|
|
|
60
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
60
|
+
# %% ../nbs/api/11_clean.ipynb #b4cde615
|
|
61
61
|
def _clean_cell_output(cell, clean_ids):
|
|
62
62
|
"Remove `cell` output execution count and optionally ids from text reprs"
|
|
63
63
|
outputs = cell.get('outputs', [])
|
|
@@ -71,7 +71,7 @@ def _clean_cell_output(cell, clean_ids):
|
|
|
71
71
|
if 'text' in o and clean_ids: o['text'] = _clean_cell_output_id(o['text'])
|
|
72
72
|
# o.get('metadata', {}).pop('tags', None)
|
|
73
73
|
|
|
74
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
74
|
+
# %% ../nbs/api/11_clean.ipynb #2ba79c93
|
|
75
75
|
def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
|
|
76
76
|
"Clean `cell` by removing superfluous metadata or everything except the input if `clear_all`"
|
|
77
77
|
if 'execution_count' in cell: cell['execution_count'] = None
|
|
@@ -81,8 +81,9 @@ def _clean_cell(cell, clear_all, allowed_metadata_keys, clean_ids):
|
|
|
81
81
|
if cell['source'] == ['']: cell['source'] = []
|
|
82
82
|
cell['metadata'] = {} if clear_all else {
|
|
83
83
|
k:v for k,v in cell['metadata'].items() if k in allowed_metadata_keys}
|
|
84
|
+
if 'id' not in cell: cell['id'] = rtoken_hex(4)
|
|
84
85
|
|
|
85
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
86
|
+
# %% ../nbs/api/11_clean.ipynb #e8101222
|
|
86
87
|
def clean_nb(
|
|
87
88
|
nb, # The notebook to clean
|
|
88
89
|
clear_all=False, # Remove all cell metadata and cell outputs?
|
|
@@ -99,13 +100,15 @@ def clean_nb(
|
|
|
99
100
|
if nb.get('metadata', {}).get('kernelspec', {}).get('name', None):
|
|
100
101
|
nb['metadata']['kernelspec']['display_name'] = nb["metadata"]["kernelspec"]["name"]
|
|
101
102
|
nb['metadata'] = {k:v for k,v in nb['metadata'].items() if k in metadata_keys}
|
|
103
|
+
# Cell IDs were added in nbformat 4.5
|
|
104
|
+
if nb.get('nbformat') == 4 and nb.get('nbformat_minor', 0) < 5: nb['nbformat_minor'] = 5
|
|
102
105
|
|
|
103
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
106
|
+
# %% ../nbs/api/11_clean.ipynb #604d83e6
|
|
104
107
|
def _reconfigure(*strms):
|
|
105
108
|
for s in strms:
|
|
106
109
|
if hasattr(s,'reconfigure'): s.reconfigure(encoding='utf-8')
|
|
107
110
|
|
|
108
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
111
|
+
# %% ../nbs/api/11_clean.ipynb #d251837f
|
|
109
112
|
def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
|
|
110
113
|
if not f_out: f_out = f_in
|
|
111
114
|
if isinstance(f_in, (str,Path)): f_in = Path(f_in).open(encoding="utf-8")
|
|
@@ -118,7 +121,7 @@ def process_write(warn_msg, proc_nb, f_in, f_out=None, disp=False):
|
|
|
118
121
|
warn(f'{warn_msg}')
|
|
119
122
|
warn(e)
|
|
120
123
|
|
|
121
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
124
|
+
# %% ../nbs/api/11_clean.ipynb #714357ce
|
|
122
125
|
def _nbdev_clean(nb, path=None, clear_all=None):
|
|
123
126
|
cfg = get_config(path=path)
|
|
124
127
|
clear_all = clear_all or cfg.clear_all
|
|
@@ -127,7 +130,7 @@ def _nbdev_clean(nb, path=None, clear_all=None):
|
|
|
127
130
|
clean_nb(nb, clear_all, allowed_metadata_keys, allowed_cell_metadata_keys, cfg.clean_ids)
|
|
128
131
|
if path: nbdev_trust.__wrapped__(path)
|
|
129
132
|
|
|
130
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
133
|
+
# %% ../nbs/api/11_clean.ipynb #6af3b9d4
|
|
131
134
|
@call_parse
|
|
132
135
|
def nbdev_clean(
|
|
133
136
|
fname:str=None, # A notebook name or glob to clean
|
|
@@ -143,7 +146,7 @@ def nbdev_clean(
|
|
|
143
146
|
if fname is None: fname = get_config().nbs_path
|
|
144
147
|
for f in globtastic(fname, file_glob='*.ipynb', skip_folder_re='^[_.]'): _write(f_in=f, disp=disp)
|
|
145
148
|
|
|
146
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
149
|
+
# %% ../nbs/api/11_clean.ipynb #f84289fc
|
|
147
150
|
def clean_jupyter(path, model, **kwargs):
|
|
148
151
|
"Clean Jupyter `model` pre save to `path`"
|
|
149
152
|
if not (model['type']=='notebook' and model['content']['nbformat']==4): return
|
|
@@ -151,7 +154,7 @@ def clean_jupyter(path, model, **kwargs):
|
|
|
151
154
|
jupyter_hooks = get_config(path=path).jupyter_hooks
|
|
152
155
|
if jupyter_hooks: _nbdev_clean(model['content'], path=path)
|
|
153
156
|
|
|
154
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
157
|
+
# %% ../nbs/api/11_clean.ipynb #b7c19563
|
|
155
158
|
_pre_save_hook_src = '''
|
|
156
159
|
def nbdev_clean_jupyter(**kwargs):
|
|
157
160
|
try: from nbdev.clean import clean_jupyter
|
|
@@ -161,7 +164,7 @@ def nbdev_clean_jupyter(**kwargs):
|
|
|
161
164
|
c.ContentsManager.pre_save_hook = nbdev_clean_jupyter'''.strip()
|
|
162
165
|
_pre_save_hook_re = re.compile(r'c\.(File)?ContentsManager\.pre_save_hook')
|
|
163
166
|
|
|
164
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
167
|
+
# %% ../nbs/api/11_clean.ipynb #fcb8df4b
|
|
165
168
|
def _add_jupyter_hooks(src, path):
|
|
166
169
|
if _pre_save_hook_src in src: return
|
|
167
170
|
mod = ast.parse(src)
|
|
@@ -179,12 +182,12 @@ def _add_jupyter_hooks(src, path):
|
|
|
179
182
|
if src: src+='\n\n'
|
|
180
183
|
return src+_pre_save_hook_src
|
|
181
184
|
|
|
182
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
185
|
+
# %% ../nbs/api/11_clean.ipynb #cc677e44
|
|
183
186
|
def _git_root():
|
|
184
187
|
try: return Path(run('git rev-parse --show-toplevel'))
|
|
185
188
|
except OSError: return None
|
|
186
189
|
|
|
187
|
-
# %% ../nbs/api/11_clean.ipynb
|
|
190
|
+
# %% ../nbs/api/11_clean.ipynb #e6083614
|
|
188
191
|
@call_parse
|
|
189
192
|
def nbdev_install_hooks():
|
|
190
193
|
"Install Jupyter and git hooks to automatically clean, trust, and fix merge conflicts in notebooks"
|
nbdev/cli.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/13_cli.ipynb.
|
|
4
4
|
|
|
5
|
-
# %% auto 0
|
|
5
|
+
# %% auto #0
|
|
6
6
|
__all__ = ['mapping', 'nbdev_filter', 'extract_tgz', 'nbdev_new', 'nbdev_update_license', 'nb_export_cli', 'watch_export',
|
|
7
7
|
'chelp']
|
|
8
8
|
|
|
9
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
9
|
+
# %% ../nbs/api/13_cli.ipynb #6a35c7c4-748f-4c82-a9bf-c780a8d83e90
|
|
10
10
|
import warnings
|
|
11
11
|
import time
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ from urllib.error import HTTPError
|
|
|
32
32
|
from contextlib import redirect_stdout
|
|
33
33
|
import os, tarfile, sys
|
|
34
34
|
|
|
35
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
35
|
+
# %% ../nbs/api/13_cli.ipynb #86c29369
|
|
36
36
|
@call_parse
|
|
37
37
|
def nbdev_filter(
|
|
38
38
|
nb_txt:str=None, # Notebook text (uses stdin if not provided)
|
|
@@ -55,12 +55,12 @@ def nbdev_filter(
|
|
|
55
55
|
if printit: print(res, flush=True)
|
|
56
56
|
else: return res
|
|
57
57
|
|
|
58
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
58
|
+
# %% ../nbs/api/13_cli.ipynb #a1c001af-2c7c-4e0b-8c7d-a7d40c08f5e9
|
|
59
59
|
def extract_tgz(url, dest='.'):
|
|
60
60
|
from fastcore.net import urlopen
|
|
61
61
|
with urlopen(url) as u: tarfile.open(mode='r:gz', fileobj=u).extractall(dest)
|
|
62
62
|
|
|
63
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
63
|
+
# %% ../nbs/api/13_cli.ipynb #60df4b28
|
|
64
64
|
def _render_nb(fn, cfg):
|
|
65
65
|
"Render templated values like `{{lib_name}}` in notebook at `fn` from `cfg`"
|
|
66
66
|
txt = fn.read_text()
|
|
@@ -68,7 +68,7 @@ def _render_nb(fn, cfg):
|
|
|
68
68
|
for k,v in cfg.d.items(): txt = txt.replace('{{'+k+'}}', v)
|
|
69
69
|
fn.write_text(txt)
|
|
70
70
|
|
|
71
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
71
|
+
# %% ../nbs/api/13_cli.ipynb #dd385911-aa8f-44e7-8d46-7b8a20f3b010
|
|
72
72
|
def _update_repo_meta(cfg):
|
|
73
73
|
"Enable gh pages and update the homepage and description in your GitHub repo."
|
|
74
74
|
token=os.getenv('GITHUB_TOKEN')
|
|
@@ -79,7 +79,7 @@ def _update_repo_meta(cfg):
|
|
|
79
79
|
except HTTPError:print(f"Could not update the description & URL on the repo: {cfg.user}/{cfg.repo} using $GITHUB_TOKEN.\n"
|
|
80
80
|
"Use a token with the correction permissions or perform these steps manually.")
|
|
81
81
|
|
|
82
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
82
|
+
# %% ../nbs/api/13_cli.ipynb #c4a663d9
|
|
83
83
|
@call_parse
|
|
84
84
|
@delegates(nbdev_create_config)
|
|
85
85
|
def nbdev_new(**kwargs):
|
|
@@ -123,7 +123,7 @@ def nbdev_new(**kwargs):
|
|
|
123
123
|
nbdev_readme.__wrapped__()
|
|
124
124
|
nbdev_contributing.__wrapped__()
|
|
125
125
|
|
|
126
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
126
|
+
# %% ../nbs/api/13_cli.ipynb #69458d7f-cda3-4055-aecf-07d047c7a683
|
|
127
127
|
mapping = {
|
|
128
128
|
'mit': 'mit',
|
|
129
129
|
'apache2': 'apache-2.0',
|
|
@@ -132,7 +132,7 @@ mapping = {
|
|
|
132
132
|
'bsd3': 'bsd-3-clause'
|
|
133
133
|
}
|
|
134
134
|
|
|
135
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
135
|
+
# %% ../nbs/api/13_cli.ipynb #a1116ee1-f5cb-4b63-8630-b64cd2ae3c12
|
|
136
136
|
@call_parse
|
|
137
137
|
def nbdev_update_license(
|
|
138
138
|
to: str=None, # update license to
|
|
@@ -163,7 +163,7 @@ def nbdev_update_license(
|
|
|
163
163
|
lic.write(body)
|
|
164
164
|
print(f"License updated from {curr_lic} to {to}")
|
|
165
165
|
|
|
166
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
166
|
+
# %% ../nbs/api/13_cli.ipynb #412b4cd2
|
|
167
167
|
@call_parse
|
|
168
168
|
@delegates(nb_export, but=['procs', 'mod_maker'])
|
|
169
169
|
def nb_export_cli(nbname,
|
|
@@ -172,7 +172,7 @@ def nb_export_cli(nbname,
|
|
|
172
172
|
"Export a single nbdev notebook to a python script."
|
|
173
173
|
return nb_export(nbname=nbname, debug=debug, **kwargs)
|
|
174
174
|
|
|
175
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
175
|
+
# %% ../nbs/api/13_cli.ipynb #aaa472e7
|
|
176
176
|
@call_parse
|
|
177
177
|
def watch_export(nbs:str=None, # Nb directory to watch for changes
|
|
178
178
|
lib:str=None, # Export directory to write py files to
|
|
@@ -197,7 +197,7 @@ def watch_export(nbs:str=None, # Nb directory to watch for changes
|
|
|
197
197
|
with fs_watchdog(_export, nbs):
|
|
198
198
|
while True: time.sleep(1)
|
|
199
199
|
|
|
200
|
-
# %% ../nbs/api/13_cli.ipynb
|
|
200
|
+
# %% ../nbs/api/13_cli.ipynb #e34f6ff4-f85b-4805-b406-121279cc9246
|
|
201
201
|
@call_parse
|
|
202
202
|
def chelp():
|
|
203
203
|
"Show help for all console scripts"
|
nbdev/config.py
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/01_config.ipynb.
|
|
4
4
|
|
|
5
|
-
# %% auto 0
|
|
5
|
+
# %% auto #0
|
|
6
6
|
__all__ = ['pyproj_tmpl', 'nbdev_create_config', 'get_config', 'config_key', 'is_nbdev', 'create_output', 'show_src',
|
|
7
7
|
'update_version', 'update_proj', 'add_init', 'write_cells']
|
|
8
8
|
|
|
9
|
-
# %% ../nbs/api/01_config.ipynb
|
|
9
|
+
# %% ../nbs/api/01_config.ipynb #6fd14ecd
|
|
10
10
|
from datetime import datetime
|
|
11
11
|
from fastcore.docments import *
|
|
12
12
|
from fastcore.utils import *
|
|
@@ -15,21 +15,21 @@ from fastcore.script import *
|
|
|
15
15
|
from fastcore.style import *
|
|
16
16
|
from fastcore.xdg import *
|
|
17
17
|
|
|
18
|
-
import ast
|
|
18
|
+
import ast,warnings
|
|
19
19
|
from IPython.display import Markdown
|
|
20
20
|
from execnb.nbio import read_nb,NbCell
|
|
21
21
|
from urllib.error import HTTPError
|
|
22
22
|
|
|
23
|
-
# %% ../nbs/api/01_config.ipynb
|
|
23
|
+
# %% ../nbs/api/01_config.ipynb #117128e6
|
|
24
24
|
_nbdev_home_dir = 'nbdev' # sub-directory of xdg base dir
|
|
25
25
|
_nbdev_cfg_name = 'settings.ini'
|
|
26
26
|
|
|
27
|
-
# %% ../nbs/api/01_config.ipynb
|
|
27
|
+
# %% ../nbs/api/01_config.ipynb #adf0834f
|
|
28
28
|
def _git_repo():
|
|
29
29
|
try: return repo_details(run('git config --get remote.origin.url'))[1]
|
|
30
30
|
except OSError: return
|
|
31
31
|
|
|
32
|
-
# %% ../nbs/api/01_config.ipynb
|
|
32
|
+
# %% ../nbs/api/01_config.ipynb #efccb7f2
|
|
33
33
|
# When adding a named default to the list below, be sure that that name
|
|
34
34
|
# is also added to one of the sections in `_nbdev_cfg_sections` as well,
|
|
35
35
|
# or it won't get written by `nbdev_create_config`:
|
|
@@ -61,12 +61,13 @@ def _apply_defaults(
|
|
|
61
61
|
jupyter_hooks:bool_arg=False, # Run Jupyter hooks?
|
|
62
62
|
clean_ids:bool_arg=True, # Remove ids from plaintext reprs?
|
|
63
63
|
clear_all:bool_arg=False, # Remove all cell metadata and cell outputs?
|
|
64
|
-
cell_number:bool_arg=True, # Add cell number to the exported file
|
|
65
64
|
put_version_in_init:bool_arg=True, # Add the version to the main __init__.py in nbdev_export
|
|
66
65
|
update_pyproject:bool_arg=True, # Create/update pyproject.toml with correct project name
|
|
67
66
|
skip_procs:str='', # A comma-separated list of processors that you want to skip
|
|
68
67
|
):
|
|
69
68
|
"Apply default settings where missing in `cfg`."
|
|
69
|
+
if 'cell_number' in cfg:
|
|
70
|
+
warnings.warn("`cell_number` in settings.ini is deprecated and ignored. Cell IDs are now used instead.", DeprecationWarning)
|
|
70
71
|
if getattr(cfg,'repo',None) is None:
|
|
71
72
|
cfg.repo = _git_repo()
|
|
72
73
|
if cfg.repo is None:
|
|
@@ -79,7 +80,7 @@ def _apply_defaults(
|
|
|
79
80
|
cfg[k] = v
|
|
80
81
|
return cfg
|
|
81
82
|
|
|
82
|
-
# %% ../nbs/api/01_config.ipynb
|
|
83
|
+
# %% ../nbs/api/01_config.ipynb #6eeafafd
|
|
83
84
|
def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
|
|
84
85
|
from ghapi.all import GhApi
|
|
85
86
|
api = GhApi(owner=owner, repo=repo, token=os.getenv('GITHUB_TOKEN'))
|
|
@@ -95,7 +96,7 @@ https://nbdev.fast.ai/api/release.html#setup"""]
|
|
|
95
96
|
|
|
96
97
|
return r.default_branch, default_kw if not getattr(r, 'topics', []) else ' '.join(r.topics), r.description
|
|
97
98
|
|
|
98
|
-
# %% ../nbs/api/01_config.ipynb
|
|
99
|
+
# %% ../nbs/api/01_config.ipynb #35d5c037
|
|
99
100
|
def _fetch_from_git(raise_err=False):
|
|
100
101
|
"Get information for settings.ini from the user."
|
|
101
102
|
res={}
|
|
@@ -111,7 +112,7 @@ def _fetch_from_git(raise_err=False):
|
|
|
111
112
|
else: res['lib_name'] = res['repo'].replace('-','_')
|
|
112
113
|
return res
|
|
113
114
|
|
|
114
|
-
# %% ../nbs/api/01_config.ipynb
|
|
115
|
+
# %% ../nbs/api/01_config.ipynb #999c74f6
|
|
115
116
|
def _prompt_user(cfg, inferred):
|
|
116
117
|
"Let user input values not in `cfg` or `inferred`."
|
|
117
118
|
res = cfg.copy()
|
|
@@ -125,7 +126,7 @@ def _prompt_user(cfg, inferred):
|
|
|
125
126
|
print(msg+res[k]+' # Automatically inferred from git')
|
|
126
127
|
return res
|
|
127
128
|
|
|
128
|
-
# %% ../nbs/api/01_config.ipynb
|
|
129
|
+
# %% ../nbs/api/01_config.ipynb #8348a963
|
|
129
130
|
def _cfg2txt(cfg, head, sections, tail=''):
|
|
130
131
|
"Render `cfg` with commented sections."
|
|
131
132
|
nm = cfg.d.name
|
|
@@ -137,7 +138,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
|
|
|
137
138
|
res += tail
|
|
138
139
|
return res.strip()
|
|
139
140
|
|
|
140
|
-
# %% ../nbs/api/01_config.ipynb
|
|
141
|
+
# %% ../nbs/api/01_config.ipynb #a4ef6546
|
|
141
142
|
_nbdev_cfg_head = '''# All sections below are required unless otherwise specified.
|
|
142
143
|
# See https://github.com/AnswerDotAI/nbdev/blob/main/settings.ini for examples.
|
|
143
144
|
|
|
@@ -154,7 +155,7 @@ _nbdev_cfg_tail = '''### Optional ###
|
|
|
154
155
|
# package_data =
|
|
155
156
|
'''
|
|
156
157
|
|
|
157
|
-
# %% ../nbs/api/01_config.ipynb
|
|
158
|
+
# %% ../nbs/api/01_config.ipynb #05aae09f
|
|
158
159
|
@call_parse
|
|
159
160
|
@delegates(_apply_defaults, but='cfg')
|
|
160
161
|
def nbdev_create_config(
|
|
@@ -180,17 +181,17 @@ def nbdev_create_config(
|
|
|
180
181
|
cfg_fn = Path(path)/cfg_name
|
|
181
182
|
print(f'{cfg_fn} created.')
|
|
182
183
|
|
|
183
|
-
# %% ../nbs/api/01_config.ipynb
|
|
184
|
+
# %% ../nbs/api/01_config.ipynb #0e56064f
|
|
184
185
|
def _nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None):
|
|
185
186
|
cfg_path = Path.cwd() if path is None else Path(path)
|
|
186
187
|
return getattr(Config.find(cfg_name), 'config_file', cfg_path/cfg_name)
|
|
187
188
|
|
|
188
|
-
# %% ../nbs/api/01_config.ipynb
|
|
189
|
+
# %% ../nbs/api/01_config.ipynb #f8813a52
|
|
189
190
|
def _xdg_config_paths(cfg_name=_nbdev_cfg_name):
|
|
190
191
|
xdg_config_paths = reversed([xdg_config_home()]+xdg_config_dirs())
|
|
191
192
|
return [o/_nbdev_home_dir/cfg_name for o in xdg_config_paths]
|
|
192
193
|
|
|
193
|
-
# %% ../nbs/api/01_config.ipynb
|
|
194
|
+
# %% ../nbs/api/01_config.ipynb #3dac70e0
|
|
194
195
|
def _type(t): return bool if t==bool_arg else t
|
|
195
196
|
_types = {k:_type(v['anno']) for k,v in docments(_apply_defaults,full=True,returns=False).items() if k != 'cfg'}
|
|
196
197
|
|
|
@@ -202,25 +203,25 @@ def get_config(cfg_name=_nbdev_cfg_name, path=None):
|
|
|
202
203
|
cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files, types=_types)
|
|
203
204
|
return _apply_defaults(cfg)
|
|
204
205
|
|
|
205
|
-
# %% ../nbs/api/01_config.ipynb
|
|
206
|
+
# %% ../nbs/api/01_config.ipynb #9c5b3681
|
|
206
207
|
def config_key(c, default=None, path=True, missing_ok=None):
|
|
207
208
|
"Deprecated: use `get_config().get` or `get_config().path` instead."
|
|
208
209
|
warn("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead.", DeprecationWarning)
|
|
209
210
|
return get_config().path(c, default) if path else get_config().get(c, default)
|
|
210
211
|
|
|
211
|
-
# %% ../nbs/api/01_config.ipynb
|
|
212
|
+
# %% ../nbs/api/01_config.ipynb #6939b40e
|
|
212
213
|
def is_nbdev(): return _nbdev_config_file().exists()
|
|
213
214
|
|
|
214
|
-
# %% ../nbs/api/01_config.ipynb
|
|
215
|
+
# %% ../nbs/api/01_config.ipynb #6e89fe6c
|
|
215
216
|
def create_output(txt, mime):
|
|
216
217
|
"Add a cell output containing `txt` of the `mime` text MIME sub-type"
|
|
217
218
|
return [{"data": { f"text/{mime}": str(txt).splitlines(True) },
|
|
218
219
|
"execution_count": 1, "metadata": {}, "output_type": "execute_result"}]
|
|
219
220
|
|
|
220
|
-
# %% ../nbs/api/01_config.ipynb
|
|
221
|
+
# %% ../nbs/api/01_config.ipynb #5a4d8e52
|
|
221
222
|
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
|
|
222
223
|
|
|
223
|
-
# %% ../nbs/api/01_config.ipynb
|
|
224
|
+
# %% ../nbs/api/01_config.ipynb #163177f2
|
|
224
225
|
pyproj_tmpl = """[build-system]
|
|
225
226
|
requires = ["setuptools>=64.0"]
|
|
226
227
|
build-backend = "setuptools.build_meta"
|
|
@@ -234,7 +235,7 @@ dynamic = [ "keywords", "description", "version", "dependencies", "optional-depe
|
|
|
234
235
|
cache-keys = [{ file = "pyproject.toml" }, { file = "settings.ini" }, { file = "setup.py" }]
|
|
235
236
|
"""
|
|
236
237
|
|
|
237
|
-
# %% ../nbs/api/01_config.ipynb
|
|
238
|
+
# %% ../nbs/api/01_config.ipynb #f1c85f45
|
|
238
239
|
_re_version = re.compile(r'^__version__\s*=.*$', re.MULTILINE)
|
|
239
240
|
_re_proj = re.compile(r'^name\s*=\s*".*$', re.MULTILINE)
|
|
240
241
|
_re_reqpy = re.compile(r'^requires-python\s*=\s*".*$', re.MULTILINE)
|
|
@@ -276,15 +277,15 @@ def add_init(path=None):
|
|
|
276
277
|
if get_config().get('put_version_in_init', True): update_version(path)
|
|
277
278
|
if get_config().get('update_pyproject', True): update_proj(path.parent)
|
|
278
279
|
|
|
279
|
-
# %% ../nbs/api/01_config.ipynb
|
|
280
|
-
def write_cells(cells, hdr, file,
|
|
281
|
-
"Write `cells` to `file` along with header `hdr`
|
|
280
|
+
# %% ../nbs/api/01_config.ipynb #cdd05b4c
|
|
281
|
+
def write_cells(cells, hdr, file, solo_nb=False):
|
|
282
|
+
"Write `cells` to `file` along with header `hdr` (mainly for nbdev internal use)."
|
|
282
283
|
for cell in cells:
|
|
283
284
|
if cell.cell_type=='code' and cell.source.strip():
|
|
284
|
-
|
|
285
|
-
file.write(f'\n\n{hdr}{
|
|
285
|
+
cell_id = f" #{cell.id}" if cell.get('id') else ""
|
|
286
|
+
file.write(f'\n\n{hdr}{cell_id}\n{cell.source}') if not solo_nb else file.write(f'\n\n{cell.source}')
|
|
286
287
|
|
|
287
|
-
# %% ../nbs/api/01_config.ipynb
|
|
288
|
+
# %% ../nbs/api/01_config.ipynb #34cfeb82
|
|
288
289
|
def _basic_export_nb(fname, name, dest=None):
|
|
289
290
|
"Basic exporter to bootstrap nbdev."
|
|
290
291
|
if dest is None: dest = get_config().lib_path
|
nbdev/diff.py
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/api/19_diff.ipynb.
|
|
4
4
|
|
|
5
|
-
# %% auto 0
|
|
5
|
+
# %% auto #0
|
|
6
6
|
__all__ = ['read_nb_from_git', 'nbs_pair', 'changed_cells', 'source_diff', 'cell_diffs']
|
|
7
7
|
|
|
8
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
8
|
+
# %% ../nbs/api/19_diff.ipynb #10c8ad0b
|
|
9
9
|
import json
|
|
10
10
|
from fastcore.utils import *
|
|
11
11
|
from fastcore.meta import delegates
|
|
@@ -13,7 +13,7 @@ from difflib import unified_diff
|
|
|
13
13
|
from fastgit import Git
|
|
14
14
|
from execnb.nbio import *
|
|
15
15
|
|
|
16
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
16
|
+
# %% ../nbs/api/19_diff.ipynb #a8981115
|
|
17
17
|
def read_nb_from_git(
|
|
18
18
|
g:Git, # The git object
|
|
19
19
|
path, # The path to the notebook (absolute or relative to git root)
|
|
@@ -26,13 +26,13 @@ def read_nb_from_git(
|
|
|
26
26
|
raw = g.show(f'{ref}:{path}', split=False)
|
|
27
27
|
return dict2nb(json.loads(raw))
|
|
28
28
|
|
|
29
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
29
|
+
# %% ../nbs/api/19_diff.ipynb #3ac25702
|
|
30
30
|
def _nb_srcdict(g:Git, nb_path, ref=None, f=noop):
|
|
31
31
|
"Dict of id->source"
|
|
32
32
|
nb = read_nb_from_git(g, nb_path, ref)
|
|
33
33
|
return {c['id']: f(c) for c in nb.cells}
|
|
34
34
|
|
|
35
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
35
|
+
# %% ../nbs/api/19_diff.ipynb #27ff9a7b
|
|
36
36
|
def nbs_pair(
|
|
37
37
|
nb_path, # Path to the notebook
|
|
38
38
|
ref_a='HEAD', # First git ref (None for working dir)
|
|
@@ -44,7 +44,7 @@ def nbs_pair(
|
|
|
44
44
|
g = Git(nb_path.parent)
|
|
45
45
|
return _nb_srcdict(g, nb_path, ref_a, f), _nb_srcdict(g, nb_path, ref_b, f)
|
|
46
46
|
|
|
47
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
47
|
+
# %% ../nbs/api/19_diff.ipynb #958aeaf8
|
|
48
48
|
def _cell_changes(
|
|
49
49
|
nb_path, # Path to the notebook
|
|
50
50
|
fn, # function to call to get dict values
|
|
@@ -69,14 +69,14 @@ def _cell_changes(
|
|
|
69
69
|
if dels: res |= {cid: fn(cid, old[cid], '') for cid in old if cid not in new}
|
|
70
70
|
return res
|
|
71
71
|
|
|
72
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
72
|
+
# %% ../nbs/api/19_diff.ipynb #6a723bc8
|
|
73
73
|
@delegates(_cell_changes)
|
|
74
74
|
def changed_cells(nb_path, **kwargs):
|
|
75
75
|
"Return set of cell IDs for changed/added/deleted cells between two refs"
|
|
76
76
|
def f(cid,o,n): return cid
|
|
77
77
|
return set(_cell_changes(nb_path, f, **kwargs).keys())
|
|
78
78
|
|
|
79
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
79
|
+
# %% ../nbs/api/19_diff.ipynb #079eedb0
|
|
80
80
|
def source_diff(
|
|
81
81
|
old_source, # Original source string
|
|
82
82
|
new_source # New source string
|
|
@@ -84,7 +84,7 @@ def source_diff(
|
|
|
84
84
|
"Return unified diff string for source change"
|
|
85
85
|
return '\n'.join(unified_diff(old_source.splitlines(), new_source.splitlines(), lineterm=''))
|
|
86
86
|
|
|
87
|
-
# %% ../nbs/api/19_diff.ipynb
|
|
87
|
+
# %% ../nbs/api/19_diff.ipynb #38216afa
|
|
88
88
|
@delegates(_cell_changes)
|
|
89
89
|
def cell_diffs(nb_path, **kwargs):
|
|
90
90
|
"{cell_id:diff} for changed/added/deleted cells between two refs"
|