Create delightful software with Jupyter Notebooks
—
Project setup, configuration management, and bootstrapping functionality for new nbdev projects. The configuration system uses settings.ini files to manage project settings and supports both project-level and global configuration.
Create and initialize configuration for new nbdev projects with sensible defaults.
def nbdev_create_config(
repo: str = None,
branch: str = None,
user: str = None,
author: str = None,
author_email: str = None,
description: str = None,
path: str = '.',
cfg_name: str = 'settings.ini',
**kwargs
):
"""
Create configuration for new nbdev project.
Creates a settings.ini file with default values for lib_name, version,
description, and other project settings. Prompts user for required information
and attempts to infer settings from git repository.
"""Usage Example:
from nbdev.config import nbdev_create_config
# Create new project configuration
nbdev_create_config()
# This will create settings.ini with project defaultsAccess and query current project configuration settings.
def get_config():
"""
Get current configuration settings.
Returns:
Config object with all project settings loaded from settings.ini
Raises:
FileNotFoundError: If no settings.ini found in current directory or parents
"""
def config_key(key: str):
"""
Get specific configuration value by key.
Args:
key: Configuration key to retrieve
Returns:
Configuration value for the specified key
"""
def is_nbdev() -> bool:
"""
Check if current directory is an nbdev project.
Returns:
True if settings.ini exists and contains nbdev configuration
"""Usage Examples:
from nbdev.config import get_config, config_key, is_nbdev
# Check if current directory is nbdev project
if is_nbdev():
# Get full configuration
config = get_config()
print(f"Library: {config.lib_name}")
print(f"Version: {config.version}")
print(f"Description: {config.description}")
# Get specific configuration values
lib_path = config_key('lib_path')
doc_path = config_key('doc_path')Create output directories and project structure based on configuration.
def create_output():
"""
Create output directories based on configuration.
Creates lib_path and doc_path directories if they don't exist,
based on current project configuration settings.
"""
def add_init():
"""
Add __init__.py files to package directories.
Ensures proper Python package structure by adding __init__.py files
to all subdirectories in the library path.
"""Update and manage project version information across multiple files.
def update_version(version: str):
"""
Update package version across project files.
Args:
version: New version string (e.g., "1.2.3")
Updates version in:
- settings.ini
- __init__.py (if put_version_in_init is True)
- pyproject.toml (if update_pyproject is True)
"""
def update_proj():
"""
Update project configuration and dependencies.
Updates pyproject.toml with current settings and ensures
project metadata is consistent across configuration files.
"""Display source code of objects for debugging and exploration.
def show_src(obj):
"""
Show source code of an object.
Args:
obj: Python object to display source for
Returns:
Formatted source code display
"""Write notebook cells to files with proper formatting and structure.
def write_cells(cells, path):
"""
Write notebook cells to a file.
Args:
cells: List of notebook cells to write
path: Output file path
Writes cells to the specified path with proper Python formatting,
imports, and structure.
"""pyproj_tmpl: strTemplate string for generating pyproject.toml files with correct project structure and dependencies.
Common configuration keys available through config_key():
lib_name: Package namelib_path: Path to package source codeversion: Package versiondescription: Package descriptionauthor: Package authorauthor_email: Author email addresscopyright: Copyright noticelicense: License typegit_url: Git repository URLdoc_host: Documentation host URLdoc_baseurl: Documentation base URLdoc_path: Documentation output pathnbs_path: Notebooks source pathtst_flags: Test execution flagscustom_sidebar: Use custom sidebarblack_formatting: Enable black code formattingclean_ids: Remove notebook cell IDsjupyter_hooks: Enable Jupyter git hooksUsage Example:
from nbdev.config import get_config
config = get_config()
# Access common settings
print(f"Package: {config.lib_name}")
print(f"Source: {config.lib_path}")
print(f"Docs: {config.doc_path}")
print(f"Notebooks: {config.nbs_path}")
print(f"Version: {config.version}")
print(f"Git URL: {config.git_url}")Install with Tessl CLI
npx tessl i tessl/pypi-nbdev