Skip to content

Commit cd087d8

Browse files
committed
mdoc
1 parent aeaf0dc commit cd087d8

File tree

2 files changed

+37
-19
lines changed

2 files changed

+37
-19
lines changed

nbdev/config.py

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
"""Read and write nbdev's `settings.ini` file.
2+
`get_config` is the main function for reading settings."""
3+
14
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/09_API/01_config.ipynb.
25

36
# %% auto 0
47
__all__ = ['nbdev_create_config', 'get_config', 'config_key', 'create_output', 'show_src', 'update_version', 'add_init',
58
'write_cells']
69

7-
# %% ../nbs/09_API/01_config.ipynb 3
10+
# %% ../nbs/09_API/01_config.ipynb 2
11+
_doc_ = """Read and write nbdev's `settings.ini` file.
12+
`get_config` is the main function for reading settings."""
13+
14+
# %% ../nbs/09_API/01_config.ipynb 4
815
from datetime import datetime
916
from fastcore.utils import *
1017
from fastcore.meta import *
@@ -17,16 +24,16 @@
1724
from execnb.nbio import read_nb,NbCell
1825
from urllib.error import HTTPError
1926

20-
# %% ../nbs/09_API/01_config.ipynb 8
27+
# %% ../nbs/09_API/01_config.ipynb 9
2128
_nbdev_home_dir = 'nbdev' # sub-directory of xdg base dir
2229
_nbdev_cfg_name = 'settings.ini'
2330

24-
# %% ../nbs/09_API/01_config.ipynb 9
31+
# %% ../nbs/09_API/01_config.ipynb 10
2532
def _git_repo():
2633
try: return repo_details(run('git config --get remote.origin.url'))[1]
2734
except OSError: return
2835

29-
# %% ../nbs/09_API/01_config.ipynb 11
36+
# %% ../nbs/09_API/01_config.ipynb 12
3037
def _apply_defaults(
3138
cfg,
3239
lib_name='%(repo)s', # Package name
@@ -70,7 +77,7 @@ def _apply_defaults(
7077
cfg[k] = v
7178
return cfg
7279

73-
# %% ../nbs/09_API/01_config.ipynb 12
80+
# %% ../nbs/09_API/01_config.ipynb 13
7481
def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
7582
from ghapi.all import GhApi
7683
api = GhApi(owner=owner, repo=repo, token=os.getenv('GITHUB_TOKEN'))
@@ -86,7 +93,7 @@ def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
8693

8794
return r.default_branch, default_kw if not r.topics else ' '.join(r.topics), r.description
8895

89-
# %% ../nbs/09_API/01_config.ipynb 14
96+
# %% ../nbs/09_API/01_config.ipynb 15
9097
def _fetch_from_git(raise_err=False):
9198
"Get information for settings.ini from the user."
9299
res={}
@@ -102,7 +109,7 @@ def _fetch_from_git(raise_err=False):
102109
else: res['lib_name'] = res['repo'].replace('-','_')
103110
return res
104111

105-
# %% ../nbs/09_API/01_config.ipynb 16
112+
# %% ../nbs/09_API/01_config.ipynb 17
106113
def _prompt_user(cfg, inferred):
107114
"Let user input values not in `cfg` or `inferred`."
108115
res = cfg.copy()
@@ -116,7 +123,7 @@ def _prompt_user(cfg, inferred):
116123
print(msg+res[k]+' # Automatically inferred from git')
117124
return res
118125

119-
# %% ../nbs/09_API/01_config.ipynb 18
126+
# %% ../nbs/09_API/01_config.ipynb 19
120127
def _cfg2txt(cfg, head, sections, tail=''):
121128
"Render `cfg` with commented sections."
122129
nm = cfg.d.name
@@ -128,7 +135,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
128135
res += tail
129136
return res.strip()
130137

131-
# %% ../nbs/09_API/01_config.ipynb 20
138+
# %% ../nbs/09_API/01_config.ipynb 21
132139
_nbdev_cfg_head = '''# All sections below are required unless otherwise specified.
133140
# See https://github.com/fastai/nbdev/blob/master/settings.ini for examples.
134141
@@ -143,7 +150,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
143150
# console_scripts =
144151
'''
145152

146-
# %% ../nbs/09_API/01_config.ipynb 21
153+
# %% ../nbs/09_API/01_config.ipynb 22
147154
@call_parse
148155
@delegates(_apply_defaults, but='cfg')
149156
def nbdev_create_config(
@@ -168,19 +175,19 @@ def nbdev_create_config(
168175
cfg_fn = Path(path)/cfg_name
169176
print(f'{cfg_fn} created.')
170177

171-
# %% ../nbs/09_API/01_config.ipynb 24
178+
# %% ../nbs/09_API/01_config.ipynb 25
172179
def _nbdev_config_file(cfg_name=_nbdev_cfg_name, path=None):
173180
cfg_path = path = Path.cwd() if path is None else Path(path)
174181
while cfg_path != cfg_path.parent and not (cfg_path/cfg_name).exists(): cfg_path = cfg_path.parent
175182
if not (cfg_path/cfg_name).exists(): cfg_path = path
176183
return cfg_path/cfg_name
177184

178-
# %% ../nbs/09_API/01_config.ipynb 26
185+
# %% ../nbs/09_API/01_config.ipynb 27
179186
def _xdg_config_paths(cfg_name=_nbdev_cfg_name):
180187
xdg_config_paths = reversed([xdg_config_home()]+xdg_config_dirs())
181188
return [o/_nbdev_home_dir/cfg_name for o in xdg_config_paths]
182189

183-
# %% ../nbs/09_API/01_config.ipynb 27
190+
# %% ../nbs/09_API/01_config.ipynb 28
184191
_types = dict(custom_sidebar=bool, nbs_path=Path, lib_path=Path, doc_path=Path, recursive=bool,
185192
black_formatting=bool, jupyter_hooks=bool, clean_ids=bool, custom_quarto_yml=bool)
186193

@@ -192,22 +199,22 @@ def get_config(cfg_name=_nbdev_cfg_name, path=None):
192199
cfg = Config(cfg_file.parent, cfg_file.name, extra_files=extra_files, types=_types)
193200
return _apply_defaults(cfg)
194201

195-
# %% ../nbs/09_API/01_config.ipynb 42
202+
# %% ../nbs/09_API/01_config.ipynb 43
196203
def config_key(c, default=None, path=True, missing_ok=None):
197204
"Deprecated: use `get_config().get` or `get_config().path` instead."
198205
warn("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead.", DeprecationWarning)
199206
return get_config().path(c, default) if path else get_config().get(c, default)
200207

201-
# %% ../nbs/09_API/01_config.ipynb 44
208+
# %% ../nbs/09_API/01_config.ipynb 45
202209
def create_output(txt, mime):
203210
"Add a cell output containing `txt` of the `mime` text MIME sub-type"
204211
return [{"data": { f"text/{mime}": str(txt).splitlines(True) },
205212
"execution_count": 1, "metadata": {}, "output_type": "execute_result"}]
206213

207-
# %% ../nbs/09_API/01_config.ipynb 45
214+
# %% ../nbs/09_API/01_config.ipynb 46
208215
def show_src(src, lang='python'): return Markdown(f'```{lang}\n{src}\n```')
209216

210-
# %% ../nbs/09_API/01_config.ipynb 48
217+
# %% ../nbs/09_API/01_config.ipynb 49
211218
_re_version = re.compile('^__version__\s*=.*$', re.MULTILINE)
212219
_init = '__init__.py'
213220

@@ -236,13 +243,13 @@ def add_init(path=None):
236243
if _has_py(fs) or any(filter(_has_py, subds)) and not (r/_init).exists(): (r/_init).touch()
237244
update_version(path)
238245

239-
# %% ../nbs/09_API/01_config.ipynb 51
246+
# %% ../nbs/09_API/01_config.ipynb 52
240247
def write_cells(cells, hdr, file, offset=0):
241248
"Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
242249
for cell in cells:
243250
if cell.source.strip(): file.write(f'\n\n{hdr} {cell.idx_+offset}\n{cell.source}')
244251

245-
# %% ../nbs/09_API/01_config.ipynb 52
252+
# %% ../nbs/09_API/01_config.ipynb 53
246253
def _basic_export_nb(fname, name, dest=None):
247254
"Basic exporter to bootstrap nbdev."
248255
if dest is None: dest = get_config().lib_path

nbs/09_API/01_config.ipynb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
"#|default_exp config"
2020
]
2121
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": null,
25+
"metadata": {},
26+
"outputs": [],
27+
"source": [
28+
"#|export\n",
29+
"_doc_ = \"\"\"Read and write nbdev's `settings.ini` file.\n",
30+
"`get_config` is the main function for reading settings.\"\"\""
31+
]
32+
},
2233
{
2334
"cell_type": "code",
2435
"execution_count": null,

0 commit comments

Comments
 (0)