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
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/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
3333def _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
3838def _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
8282def _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
9898def _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
114114def _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
128128def _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' )
157157def 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
181181def _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
188188def _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
193193def _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
205205def 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
211211def 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
217217def 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
249249def 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
255255def _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