77__all__ = ['nbdev_create_config' , 'get_config' , 'config_key' , 'create_output' , 'show_src' , 'update_version' , 'add_init' ,
88 'write_cells' ]
99
10- # %% ../nbs/api/01_config.ipynb 2
10+ # %% ../nbs/api/01_config.ipynb
1111_doc_ = """Read and write nbdev's `settings.ini` file.
1212`get_config` is the main function for reading settings."""
1313
14- # %% ../nbs/api/01_config.ipynb 3
14+ # %% ../nbs/api/01_config.ipynb
1515from datetime import datetime
1616from fastcore .docments import *
1717from fastcore .utils import *
2525from execnb .nbio import read_nb ,NbCell
2626from urllib .error import HTTPError
2727
28- # %% ../nbs/api/01_config.ipynb 8
28+ # %% ../nbs/api/01_config.ipynb
2929_nbdev_home_dir = 'nbdev' # sub-directory of xdg base dir
3030_nbdev_cfg_name = 'settings.ini'
3131
32- # %% ../nbs/api/01_config.ipynb 9
32+ # %% ../nbs/api/01_config.ipynb
3333def _git_repo ():
3434 try : return repo_details (run ('git config --get remote.origin.url' ))[1 ]
3535 except OSError : return
3636
37- # %% ../nbs/api/01_config.ipynb 11
37+ # %% ../nbs/api/01_config.ipynb
3838# When adding a named default to the list below, be sure that that name
3939# is also added to one of the sections in `_nbdev_cfg_sections` as well,
4040# or it won't get written by `nbdev_create_config`:
@@ -82,7 +82,7 @@ def _apply_defaults(
8282 cfg [k ] = v
8383 return cfg
8484
85- # %% ../nbs/api/01_config.ipynb 12
85+ # %% ../nbs/api/01_config.ipynb
8686def _get_info (owner , repo , default_branch = 'main' , default_kw = 'nbdev' ):
8787 from ghapi .all import GhApi
8888 api = GhApi (owner = owner , repo = repo , token = os .getenv ('GITHUB_TOKEN' ))
@@ -98,7 +98,7 @@ def _get_info(owner, repo, default_branch='main', default_kw='nbdev'):
9898
9999 return r .default_branch , default_kw if not getattr (r , 'topics' , []) else ' ' .join (r .topics ), r .description
100100
101- # %% ../nbs/api/01_config.ipynb 14
101+ # %% ../nbs/api/01_config.ipynb
102102def _fetch_from_git (raise_err = False ):
103103 "Get information for settings.ini from the user."
104104 res = {}
@@ -114,7 +114,7 @@ def _fetch_from_git(raise_err=False):
114114 else : res ['lib_name' ] = res ['repo' ].replace ('-' ,'_' )
115115 return res
116116
117- # %% ../nbs/api/01_config.ipynb 16
117+ # %% ../nbs/api/01_config.ipynb
118118def _prompt_user (cfg , inferred ):
119119 "Let user input values not in `cfg` or `inferred`."
120120 res = cfg .copy ()
@@ -128,7 +128,7 @@ def _prompt_user(cfg, inferred):
128128 print (msg + res [k ]+ ' # Automatically inferred from git' )
129129 return res
130130
131- # %% ../nbs/api/01_config.ipynb 18
131+ # %% ../nbs/api/01_config.ipynb
132132def _cfg2txt (cfg , head , sections , tail = '' ):
133133 "Render `cfg` with commented sections."
134134 nm = cfg .d .name
@@ -140,7 +140,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
140140 res += tail
141141 return res .strip ()
142142
143- # %% ../nbs/api/01_config.ipynb 20
143+ # %% ../nbs/api/01_config.ipynb
144144_nbdev_cfg_head = '''# All sections below are required unless otherwise specified.
145145# See https://github.com/fastai/nbdev/blob/master/settings.ini for examples.
146146
@@ -157,7 +157,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
157157# package_data =
158158'''
159159
160- # %% ../nbs/api/01_config.ipynb 21
160+ # %% ../nbs/api/01_config.ipynb
161161@call_parse
162162@delegates (_apply_defaults , but = 'cfg' )
163163def nbdev_create_config (
@@ -183,19 +183,19 @@ def nbdev_create_config(
183183 cfg_fn = Path (path )/ cfg_name
184184 print (f'{ cfg_fn } created.' )
185185
186- # %% ../nbs/api/01_config.ipynb 24
186+ # %% ../nbs/api/01_config.ipynb
187187def _nbdev_config_file (cfg_name = _nbdev_cfg_name , path = None ):
188188 cfg_path = path = Path .cwd () if path is None else Path (path )
189189 while cfg_path != cfg_path .parent and not (cfg_path / cfg_name ).exists (): cfg_path = cfg_path .parent
190190 if not (cfg_path / cfg_name ).exists (): cfg_path = path
191191 return cfg_path / cfg_name
192192
193- # %% ../nbs/api/01_config.ipynb 26
193+ # %% ../nbs/api/01_config.ipynb
194194def _xdg_config_paths (cfg_name = _nbdev_cfg_name ):
195195 xdg_config_paths = reversed ([xdg_config_home ()]+ xdg_config_dirs ())
196196 return [o / _nbdev_home_dir / cfg_name for o in xdg_config_paths ]
197197
198- # %% ../nbs/api/01_config.ipynb 27
198+ # %% ../nbs/api/01_config.ipynb
199199def _type (t ): return bool if t == bool_arg else t
200200_types = {k :_type (v ['anno' ]) for k ,v in docments (_apply_defaults ,full = True ,returns = False ).items () if k != 'cfg' }
201201
@@ -207,22 +207,22 @@ def get_config(cfg_name=_nbdev_cfg_name, path=None):
207207 cfg = Config (cfg_file .parent , cfg_file .name , extra_files = extra_files , types = _types )
208208 return _apply_defaults (cfg )
209209
210- # %% ../nbs/api/01_config.ipynb 42
210+ # %% ../nbs/api/01_config.ipynb
211211def config_key (c , default = None , path = True , missing_ok = None ):
212212 "Deprecated: use `get_config().get` or `get_config().path` instead."
213213 warn ("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead." , DeprecationWarning )
214214 return get_config ().path (c , default ) if path else get_config ().get (c , default )
215215
216- # %% ../nbs/api/01_config.ipynb 44
216+ # %% ../nbs/api/01_config.ipynb
217217def create_output (txt , mime ):
218218 "Add a cell output containing `txt` of the `mime` text MIME sub-type"
219219 return [{"data" : { f"text/{ mime } " : str (txt ).splitlines (True ) },
220220 "execution_count" : 1 , "metadata" : {}, "output_type" : "execute_result" }]
221221
222- # %% ../nbs/api/01_config.ipynb 45
222+ # %% ../nbs/api/01_config.ipynb
223223def show_src (src , lang = 'python' ): return Markdown (f'```{ lang } \n { src } \n ```' )
224224
225- # %% ../nbs/api/01_config.ipynb 48
225+ # %% ../nbs/api/01_config.ipynb
226226_re_version = re .compile (r'^__version__\s*=.*$' , re .MULTILINE )
227227_init = '__init__.py'
228228
@@ -251,15 +251,15 @@ def add_init(path=None):
251251 if _has_py (fs ) or any (filter (_has_py , subds )) and not (r / _init ).exists (): (r / _init ).touch ()
252252 if get_config ().get ('put_version_in_init' , True ): update_version (path )
253253
254- # %% ../nbs/api/01_config.ipynb 51
254+ # %% ../nbs/api/01_config.ipynb
255255def write_cells (cells , hdr , file , offset = 0 , cell_number = True ):
256256 "Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
257257 for cell in cells :
258258 if cell .source .strip ():
259259 idx = f" { cell .idx_ + offset } " if cell_number else ""
260260 file .write (f'\n \n { hdr } { idx } \n { cell .source } ' )
261261
262- # %% ../nbs/api/01_config.ipynb 52
262+ # %% ../nbs/api/01_config.ipynb
263263def _basic_export_nb (fname , name , dest = None ):
264264 "Basic exporter to bootstrap nbdev."
265265 if dest is None : dest = get_config ().lib_path
0 commit comments