Skip to content

Commit 0902ba2

Browse files
authored
Read nbdev-test cell timeout and timing threshold, and nbdev-create-config identity fields, from user config
1 parent 750881d commit 0902ba2

5 files changed

Lines changed: 19 additions & 17 deletions

File tree

‎nbdev/config.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,13 @@ def nbdev_create_config(
123123
path.mkdir(exist_ok=True, parents=True)
124124

125125
# Infer from git if not provided
126-
inf = _fetch_from_git()
126+
inf,ucfg = _fetch_from_git(),_user_config()
127127
repo = repo or inf.get('repo') or path.resolve().name
128-
user = user or inf.get('user', '')
128+
user = user or inf.get('user') or ucfg.get('user', '')
129129
if not user: raise ValueError("Could not infer `user` from git. Please pass --user explicitly.")
130-
author = author or inf.get('author', '')
130+
author = author or inf.get('author') or ucfg.get('author', '')
131131
if not author: raise ValueError("Could not infer `author` from git. Please pass --author explicitly.")
132-
author_email = author_email or inf.get('author_email', '')
132+
author_email = author_email or inf.get('author_email') or ucfg.get('author_email', '')
133133
if not author_email: raise ValueError("Could not infer `author_email` from git. Please pass --author-email explicitly.")
134134
branch = branch or inf.get('branch', 'main')
135135
description = description or inf.get('description', '')
@@ -171,7 +171,7 @@ def _find_nbdev_pyproject(path=None):
171171
# %% ../nbs/api/01_config.ipynb #3dac70e0
172172
nbdev_defaults = dict(nbs_path='nbs', doc_path='_docs', tst_flags='notest', recursive=True, readme_nb='index.ipynb',
173173
clean_ids=True, clear_all=False, put_version_in_init=True, jupyter_hooks=False, custom_sidebar=False, branch='main',
174-
doc_procs=[], export_procs=[], exec_profile=True)
174+
doc_procs=[], export_procs=[], exec_profile=True, cell_timeout=600)
175175

176176
_path_keys = 'lib_path', 'nbs_path', 'doc_path'
177177

‎nbdev/skill.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,5 @@
8787
8888
A behavior change means revising the lesson cells it touches: prose, displayed output, and assertions move together. Where you revised or added an assertion, check it fails against the old code and passes against the new. Many changes need no new cell at all - never add one merely to witness a change. Re-read the touched section as a reader would, against the conventions above. Style damage breaks no test and no export, so the harm only shows on the docs page.
8989
90-
Run notebooks with `nbdev-test --cell-timeout 60 --cell-timing-min 2 <nb>`. The default cell timeout is 600s, so a stalled cell (a dead server, an unbounded network wait) sits silently for ten minutes; the short timeout fails loudly naming the stuck cell, and the timing report names any cell slower than 2s, which is how a notebook that quietly stopped replaying its recorded HTTP gets noticed. A genuinely slow notebook gets a higher bound stated per run, not a removed one.
90+
Run notebooks with `nbdev-test <nb>`.
9191
"""

‎nbdev/test.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ def nbdev_test(
135135
ignore_fname:str='.notest', # Filename that will result in siblings being ignored
136136
verbose:bool=False, # Print stdout/stderr from notebook cells?
137137
save:bool=False, # Write outputs back to notebooks on success?
138-
cell_timeout:int=600, # Seconds before each cell times out (0: no limit)
139-
cell_timing_min:float=None, # Print cells slower than this many seconds (None: no timing output)
138+
cell_timeout:int=None, # Seconds before each cell times out (0: no limit; default `cell_timeout` config, 600)
139+
cell_timing_min:float=None, # Print cells slower than this many seconds (default `cell_timing_min` config, else none)
140140
**kwargs
141141
):
142142
"Test in parallel notebooks matching `path`, passing along `flags`"
143143
cfg = get_config(Path(path).resolve() if path else None)
144+
cell_timeout,cell_timing_min = ifnone(cell_timeout, cfg.cell_timeout),ifnone(cell_timing_min, cfg.get('cell_timing_min'))
144145
skip_flags = cfg.tst_flags
145146
if isinstance(skip_flags, str): skip_flags = skip_flags.split()
146147
force_flags = flags.split()

‎nbs/api/01_config.ipynb‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -269,13 +269,13 @@
269269
" path.mkdir(exist_ok=True, parents=True)\n",
270270
" \n",
271271
" # Infer from git if not provided\n",
272-
" inf = _fetch_from_git()\n",
272+
" inf,ucfg = _fetch_from_git(),_user_config()\n",
273273
" repo = repo or inf.get('repo') or path.resolve().name\n",
274-
" user = user or inf.get('user', '')\n",
274+
" user = user or inf.get('user') or ucfg.get('user', '')\n",
275275
" if not user: raise ValueError(\"Could not infer `user` from git. Please pass --user explicitly.\")\n",
276-
" author = author or inf.get('author', '')\n",
276+
" author = author or inf.get('author') or ucfg.get('author', '')\n",
277277
" if not author: raise ValueError(\"Could not infer `author` from git. Please pass --author explicitly.\")\n",
278-
" author_email = author_email or inf.get('author_email', '')\n",
278+
" author_email = author_email or inf.get('author_email') or ucfg.get('author_email', '')\n",
279279
" if not author_email: raise ValueError(\"Could not infer `author_email` from git. Please pass --author-email explicitly.\")\n",
280280
" branch = branch or inf.get('branch', 'main')\n",
281281
" description = description or inf.get('description', '')\n",
@@ -356,7 +356,7 @@
356356
"#| export\n",
357357
"nbdev_defaults = dict(nbs_path='nbs', doc_path='_docs', tst_flags='notest', recursive=True, readme_nb='index.ipynb',\n",
358358
" clean_ids=True, clear_all=False, put_version_in_init=True, jupyter_hooks=False, custom_sidebar=False, branch='main',\n",
359-
" doc_procs=[], export_procs=[], exec_profile=True)\n",
359+
" doc_procs=[], export_procs=[], exec_profile=True, cell_timeout=600)\n",
360360
"\n",
361361
"_path_keys = 'lib_path', 'nbs_path', 'doc_path'"
362362
]
@@ -558,7 +558,7 @@
558558
"id": "78056483",
559559
"metadata": {},
560560
"source": [
561-
"You can customize nbdev for all your projects by creating a `~/.config/nbdev/config.toml` file (or following the [XDG specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)). For example, you could globally disable nbdev's Jupyter hooks with `jupyter_hooks = false`."
561+
"You can customize nbdev for all your projects by creating a `~/.config/nbdev/config.toml` file (or following the [XDG specification](https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html)). Any `[tool.nbdev]` key can go there, with the project's own setting winning: for example, `jupyter_hooks = false` globally disables nbdev's Jupyter hooks, and `cell_timeout = 60` gives `nbdev-test` a default cell timeout. `nbdev-create-config` also reads `user`, `author`, and `author_email` from it when neither the arguments nor the git remote supply them."
562562
]
563563
},
564564
{

‎nbs/api/12_test.ipynb‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@
221221
"id": "bae187da",
222222
"metadata": {},
223223
"source": [
224-
"Pass `cell_timing_min` to identify slow cells without flooding ordinary test output. Each cell over the threshold prints its notebook name, stable cell id, and elapsed seconds; `--cell-timing-min=0.1` is a useful first pass."
224+
"Pass `cell_timing_min` to identify slow cells without flooding ordinary test output. Each cell over the threshold prints its notebook name, stable cell id, and elapsed seconds; `--cell-timing-min=0.1` is a useful first pass. Both `cell_timeout` and `cell_timing_min` fall back to the config keys of the same name when not passed, so a preferred bound can live in `~/.config/nbdev/config.toml` or a project's `[tool.nbdev]` table."
225225
]
226226
},
227227
{
@@ -295,12 +295,13 @@
295295
" ignore_fname:str='.notest', # Filename that will result in siblings being ignored\n",
296296
" verbose:bool=False, # Print stdout/stderr from notebook cells?\n",
297297
" save:bool=False, # Write outputs back to notebooks on success?\n",
298-
" cell_timeout:int=600, # Seconds before each cell times out (0: no limit)\n",
299-
" cell_timing_min:float=None, # Print cells slower than this many seconds (None: no timing output)\n",
298+
" cell_timeout:int=None, # Seconds before each cell times out (0: no limit; default `cell_timeout` config, 600)\n",
299+
" cell_timing_min:float=None, # Print cells slower than this many seconds (default `cell_timing_min` config, else none)\n",
300300
" **kwargs\n",
301301
"):\n",
302302
" \"Test in parallel notebooks matching `path`, passing along `flags`\"\n",
303303
" cfg = get_config(Path(path).resolve() if path else None)\n",
304+
" cell_timeout,cell_timing_min = ifnone(cell_timeout, cfg.cell_timeout),ifnone(cell_timing_min, cfg.get('cell_timing_min'))\n",
304305
" skip_flags = cfg.tst_flags\n",
305306
" if isinstance(skip_flags, str): skip_flags = skip_flags.split()\n",
306307
" force_flags = flags.split()\n",

0 commit comments

Comments
 (0)