Note: If no pyproject.toml with [tool.nbdev] is found, get_config() returns a minimal config with defaults based on the current directory. Use is_nbdev() to check if you’re in an nbdev project.
Set defaults for all projects in ~/.config/nbdev/config.toml, or its XDG location. It accepts any [tool.nbdev] key. Project settings override these defaults.
For example, jupyter_hooks = false disables the Jupyter hooks by default. cell_timeout = 60 sets a 60-second default for nbdev-test.
nbdev-create-config also reads user, author and author_email from this file when arguments and Git don’t supply them.
Add __init__.py in all subdirs of path containing python files if it’s not there already.
The package docstring helps readers of doc(pkg) choose which modules to read next. pkg_mdoc lists modules whose docstrings extend beyond the default summary and Docs: link. Each entry uses the module docstring’s first paragraph.
update_init_mdoc writes this documentation into __init__.py without changing its code. nbdev-export runs it through add_init.
pyskills’ doc() uses this package documentation instead of adding its usual submodule listing. For example, see doc('pyskills').
Write pkg_mdoc as the docstring of path/__init__.py, replacing any existing docstring
pkg_llms builds an llms.txt from the same documentation. It includes the title, summary, index-notebook introduction and module list. Module links use the .html.md URLs from their docstrings’ Docs: lines.
update_llms_txt writes the file to the notebooks folder for Quarto to copy to the site root. It marks generated files with an HTML comment. It never overwrites an existing file without that marker.
llms.txt for the package at path, from the same sources as pkg_mdoc (’’ if no intro or modules)
with tempfile.TemporaryDirectory() as d: d = Path(d) cfg_text = (pyproj_tmpl.replace('name = "FILL_IN"', 'name = "testpkg"').replace('requires-python="FILL_IN"', 'requires-python=">=3.10"')) cfg_text +='\n[tool.nbdev]\n' (d/_pyproj).write_text(cfg_text) (d/'testpkg').mkdir()with working_directory(d): update_proj(d) result = (d/_pyproj).read_text()assert'name = "testpkg"'in result
Python modules require a __init.py__ file in all directories that are modules. We assume that all directories containing a python file (including in subdirectories of any depth) is a module, and therefore add a __init__.py to each.
with tempfile.TemporaryDirectory() as d: d = Path(d) (d/'a/b').mkdir(parents=True) (d/'a/b/f.py').touch() (d/'a/c').mkdir() add_init(d)assertnot (d/'a/c'/_init).exists(), "Should not add init to dir without py file"for e in [d, d/'a', d/'a/b']: assert (e/_init).exists(),f"Missing init in {e}"