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
710# %% ../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 3
815from datetime import datetime
916from fastcore .utils import *
1017from fastcore .meta import *
1724from execnb .nbio import read_nb ,NbCell
1825from urllib .error import HTTPError
1926
20- # %% ../nbs/09_API/01_config.ipynb 7
27+ # %% ../nbs/09_API/01_config.ipynb 8
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 8
31+ # %% ../nbs/09_API/01_config.ipynb 9
2532def _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 10
36+ # %% ../nbs/09_API/01_config.ipynb 11
3037def _apply_defaults (
3138 cfg ,
3239 lib_name = '%(repo)s' , # Package name
@@ -70,24 +77,23 @@ def _apply_defaults(
7077 cfg [k ] = v
7178 return cfg
7279
73- # %% ../nbs/09_API/01_config.ipynb 11
80+ # %% ../nbs/09_API/01_config.ipynb 12
7481def _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' ))
7784
7885 try : r = api .repos .get ()
7986 except HTTPError :
80- msg = [f"""Could not access repo: { owner } /{ repo } to find your default branch - `{ default_branch } assumed.
87+ msg = [f"""Could not access repo: { owner } /{ repo } to find your default branch - `{ default_branch } ` assumed.
8188Edit `settings.ini` if this is incorrect.
8289In the future, you can allow nbdev to see private repos by setting the environment variable GITHUB_TOKEN as described here:
83- https://nbdev.fast.ai/cli.html#Using-nbdev_new-with-private-repos
84- """ ]
90+ https://nbdev.fast.ai/cli.html#Using-nbdev_new-with-private-repos""" ]
8591 print ('' .join (msg ))
86- return ( default_branch ,default_kw ,'' )
92+ return default_branch ,default_kw ,''
8793
8894 return r .default_branch , default_kw if not r .topics else ' ' .join (r .topics ), r .description
8995
90- # %% ../nbs/09_API/01_config.ipynb 13
96+ # %% ../nbs/09_API/01_config.ipynb 14
9197def _fetch_from_git (raise_err = False ):
9298 "Get information for settings.ini from the user."
9399 res = {}
@@ -103,7 +109,7 @@ def _fetch_from_git(raise_err=False):
103109 else : res ['lib_name' ] = res ['repo' ].replace ('-' ,'_' )
104110 return res
105111
106- # %% ../nbs/09_API/01_config.ipynb 15
112+ # %% ../nbs/09_API/01_config.ipynb 16
107113def _prompt_user (cfg , inferred ):
108114 "Let user input values not in `cfg` or `inferred`."
109115 res = cfg .copy ()
@@ -117,7 +123,7 @@ def _prompt_user(cfg, inferred):
117123 print (msg + res [k ]+ ' # Automatically inferred from git' )
118124 return res
119125
120- # %% ../nbs/09_API/01_config.ipynb 17
126+ # %% ../nbs/09_API/01_config.ipynb 18
121127def _cfg2txt (cfg , head , sections , tail = '' ):
122128 "Render `cfg` with commented sections."
123129 nm = cfg .d .name
@@ -129,7 +135,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
129135 res += tail
130136 return res .strip ()
131137
132- # %% ../nbs/09_API/01_config.ipynb 19
138+ # %% ../nbs/09_API/01_config.ipynb 20
133139_nbdev_cfg_head = '''# All sections below are required unless otherwise specified.
134140# See https://github.com/fastai/nbdev/blob/master/settings.ini for examples.
135141
@@ -144,7 +150,7 @@ def _cfg2txt(cfg, head, sections, tail=''):
144150# console_scripts =
145151'''
146152
147- # %% ../nbs/09_API/01_config.ipynb 20
153+ # %% ../nbs/09_API/01_config.ipynb 21
148154@call_parse
149155@delegates (_apply_defaults , but = 'cfg' )
150156def nbdev_create_config (
@@ -169,19 +175,19 @@ def nbdev_create_config(
169175 cfg_fn = Path (path )/ cfg_name
170176 print (f'{ cfg_fn } created.' )
171177
172- # %% ../nbs/09_API/01_config.ipynb 23
178+ # %% ../nbs/09_API/01_config.ipynb 24
173179def _nbdev_config_file (cfg_name = _nbdev_cfg_name , path = None ):
174180 cfg_path = path = Path .cwd () if path is None else Path (path )
175181 while cfg_path != cfg_path .parent and not (cfg_path / cfg_name ).exists (): cfg_path = cfg_path .parent
176182 if not (cfg_path / cfg_name ).exists (): cfg_path = path
177183 return cfg_path / cfg_name
178184
179- # %% ../nbs/09_API/01_config.ipynb 25
185+ # %% ../nbs/09_API/01_config.ipynb 26
180186def _xdg_config_paths (cfg_name = _nbdev_cfg_name ):
181187 xdg_config_paths = reversed ([xdg_config_home ()]+ xdg_config_dirs ())
182188 return [o / _nbdev_home_dir / cfg_name for o in xdg_config_paths ]
183189
184- # %% ../nbs/09_API/01_config.ipynb 26
190+ # %% ../nbs/09_API/01_config.ipynb 27
185191_types = dict (custom_sidebar = bool , nbs_path = Path , lib_path = Path , doc_path = Path , recursive = bool ,
186192 black_formatting = bool , jupyter_hooks = bool , clean_ids = bool , custom_quarto_yml = bool )
187193
@@ -193,22 +199,22 @@ def get_config(cfg_name=_nbdev_cfg_name, path=None):
193199 cfg = Config (cfg_file .parent , cfg_file .name , extra_files = extra_files , types = _types )
194200 return _apply_defaults (cfg )
195201
196- # %% ../nbs/09_API/01_config.ipynb 41
202+ # %% ../nbs/09_API/01_config.ipynb 42
197203def config_key (c , default = None , path = True , missing_ok = None ):
198204 "Deprecated: use `get_config().get` or `get_config().path` instead."
199205 warn ("`config_key` is deprecated. Use `get_config().get` or `get_config().path` instead." , DeprecationWarning )
200206 return get_config ().path (c , default ) if path else get_config ().get (c , default )
201207
202- # %% ../nbs/09_API/01_config.ipynb 43
208+ # %% ../nbs/09_API/01_config.ipynb 44
203209def create_output (txt , mime ):
204210 "Add a cell output containing `txt` of the `mime` text MIME sub-type"
205211 return [{"data" : { f"text/{ mime } " : str (txt ).splitlines (True ) },
206212 "execution_count" : 1 , "metadata" : {}, "output_type" : "execute_result" }]
207213
208- # %% ../nbs/09_API/01_config.ipynb 44
214+ # %% ../nbs/09_API/01_config.ipynb 45
209215def show_src (src , lang = 'python' ): return Markdown (f'```{ lang } \n { src } \n ```' )
210216
211- # %% ../nbs/09_API/01_config.ipynb 47
217+ # %% ../nbs/09_API/01_config.ipynb 48
212218_re_version = re .compile ('^__version__\s*=.*$' , re .MULTILINE )
213219_init = '__init__.py'
214220
@@ -237,13 +243,13 @@ def add_init(path=None):
237243 if _has_py (fs ) or any (filter (_has_py , subds )) and not (r / _init ).exists (): (r / _init ).touch ()
238244 update_version (path )
239245
240- # %% ../nbs/09_API/01_config.ipynb 50
246+ # %% ../nbs/09_API/01_config.ipynb 51
241247def write_cells (cells , hdr , file , offset = 0 ):
242248 "Write `cells` to `file` along with header `hdr` starting at index `offset` (mainly for nbdev internal use)."
243249 for cell in cells :
244250 if cell .source .strip (): file .write (f'\n \n { hdr } { cell .idx_ + offset } \n { cell .source } ' )
245251
246- # %% ../nbs/09_API/01_config.ipynb 51
252+ # %% ../nbs/09_API/01_config.ipynb 52
247253def _basic_export_nb (fname , name , dest = None ):
248254 "Basic exporter to bootstrap nbdev."
249255 if dest is None : dest = get_config ().lib_path
0 commit comments