Create delightful software with Jupyter Notebooks
—
Development server, project migration, and various utility functions for nbdev development workflow. These tools support the day-to-day development process and help maintain nbdev projects.
Create new nbdev projects with proper structure and configuration.
def nbdev_new(name: str = None, lib_path: str = None,
git_url: str = None, branch: str = 'main',
author: str = None, author_email: str = None,
description: str = None, path: str = '.'):
"""
Create new nbdev project.
Args:
name: Project name
lib_path: Library path (defaults to name with underscores)
git_url: Git repository URL
branch: Default git branch
author: Package author name
author_email: Author email address
description: Project description
path: Directory to create project in
Creates complete nbdev project structure with:
- settings.ini configuration
- Initial notebook files
- Python package structure
- Git repository initialization
- GitHub Actions workflows
"""Usage Example:
from nbdev.cli import nbdev_new
# Create new project interactively
nbdev_new()
# Create project with specific parameters
nbdev_new(
name='my-awesome-lib',
author='Your Name',
author_email='you@example.com',
description='An awesome Python library'
)Migrate existing nbdev projects to newer versions.
def nbdev_migrate():
"""
Migrate nbdev project to current version.
Updates project structure, configuration files, and notebook
format to be compatible with the current version of nbdev.
Handles breaking changes and deprecated features.
"""Usage Example:
from nbdev.migrate import nbdev_migrate
# Migrate current project
nbdev_migrate()Serve notebooks and documentation for development.
def proc_nbs():
"""
Process notebooks for development server.
Prepares notebooks for serving by processing them through
the nbdev pipeline and making them available for live preview
and development.
"""Filter and process notebook content for various purposes.
def nbdev_filter():
"""
Filter notebook content.
Processes notebook cells through filters to remove or modify
content based on configuration and directives. Used for
preparing notebooks for different environments or outputs.
"""Extract and handle various file formats in nbdev workflows.
def extract_tgz(fname: str, dest: str = '.'):
"""
Extract tar.gz files.
Args:
fname: Path to tar.gz file
dest: Destination directory for extraction
Utility for extracting compressed archives, commonly used
in nbdev project templates and distribution.
"""Update license information across project files.
def nbdev_update_license():
"""
Update license information in project files.
Updates license headers, copyright notices, and license
files throughout the project based on settings.ini
configuration.
"""Watch for changes and automatically export notebooks.
def watch_export():
"""
Watch notebooks and automatically export on changes.
Monitors notebook files for changes and automatically
runs export process when modifications are detected.
Useful for development workflows with continuous export.
"""Enhanced help system for command-line tools.
def chelp(func):
"""
CLI help system.
Args:
func: Function to provide help for
Enhanced help display for nbdev command-line functions
with better formatting and examples.
"""mapping: dictDictionary mapping CLI command names to their corresponding functions.
from nbdev.cli import watch_export
from nbdev.export import nb_export
# Start watching for changes
print("Starting watch mode - notebooks will auto-export on changes")
watch_export()
# This runs continuously, exporting notebooks when they changefrom nbdev.cli import nbdev_update_license, nbdev_filter
from nbdev.migrate import nbdev_migrate
def maintain_project():
"""Maintain and update nbdev project."""
print("1. Migrating to latest nbdev version...")
nbdev_migrate()
print("2. Updating license information...")
nbdev_update_license()
print("3. Filtering notebooks...")
nbdev_filter()
print("✓ Project maintenance completed")
maintain_project()from nbdev.cli import nbdev_new
from nbdev.clean import nbdev_install_hooks
from nbdev.config import get_config
def setup_development_environment(project_name: str):
"""Set up complete development environment."""
# Create new project
nbdev_new(name=project_name)
# Install git hooks
nbdev_install_hooks()
# Verify setup
config = get_config()
print(f"✓ Development environment ready for {config.lib_name}")
print(f" Notebooks: {config.nbs_path}")
print(f" Library: {config.lib_path}")
print(f" Documentation: {config.doc_path}")
setup_development_environment("my-new-project")from nbdev.cli import nbdev_filter
from nbdev.process import NBProcessor
# Create custom notebook processing
def custom_development_workflow():
"""Custom development workflow with filtering."""
# Filter notebooks for development
nbdev_filter()
# Additional custom processing could go here
print("Custom development processing completed")
custom_development_workflow()from nbdev.migrate import nbdev_migrate
from nbdev.cli import nbdev_update_license
from nbdev.config import update_version
def update_project_to_latest():
"""Update project to latest standards and version."""
# Migrate project structure
nbdev_migrate()
# Update licenses
nbdev_update_license()
# Could add version bumping
# update_version("1.1.0")
print("Project updated to latest nbdev standards")
update_project_to_latest()from nbdev.serve import proc_nbs
from nbdev.export import nb_export
def start_development_server():
"""Start development server with live reload."""
# Process notebooks for serving
proc_nbs()
# Set up continuous export
print("Development server ready")
print("Notebooks will be processed for live preview")
start_development_server()from nbdev.cli import watch_export
from nbdev.sync import nbdev_update
def ide_friendly_workflow():
"""Set up IDE-friendly development workflow."""
# Start auto-export for IDE compatibility
print("Starting auto-export for IDE integration...")
# In practice, you'd run this in background
# watch_export()
print("IDE workflow ready:")
print("- Edit notebooks → Auto-export to .py")
print("- Edit .py files → Run nbdev_update()")
ide_friendly_workflow()from nbdev.cli import nbdev_filter, extract_tgz
from nbdev.test import nbdev_test
def ci_cd_preparation():
"""Prepare project for CI/CD pipelines."""
# Filter notebooks for CI
nbdev_filter()
# Run tests to ensure everything works
if nbdev_test():
print("✓ Project ready for CI/CD")
else:
print("❌ Tests failed - fix before deploying")
ci_cd_preparation()from nbdev.cli import extract_tgz
# Extract project templates or distributions
extract_tgz('project-template.tar.gz', 'new-project/')from nbdev.cli import chelp, mapping
# Get help for specific function
chelp(nb_export)
# See all available CLI commands
print("Available CLI commands:")
for cmd, func in mapping.items():
print(f" {cmd}: {func.__doc__.split('.')[0] if func.__doc__ else 'No description'}")Complete Development Tools Example:
from nbdev.cli import (nbdev_new, nbdev_filter, watch_export,
nbdev_update_license, extract_tgz, chelp)
from nbdev.migrate import nbdev_migrate
from nbdev.serve import proc_nbs
def complete_development_setup(project_name: str):
"""Complete development environment setup."""
print(f"Setting up development environment for {project_name}")
# 1. Create new project
print("1. Creating new project...")
nbdev_new(name=project_name)
# 2. Set up development tools
print("2. Setting up development tools...")
proc_nbs() # Prepare for development server
# 3. Configure project
print("3. Configuring project...")
nbdev_update_license() # Ensure licenses are correct
# 4. Start development workflow
print("4. Development environment ready!")
print(f" Project: {project_name}")
print(" Use 'watch_export()' for auto-export")
print(" Use 'nbdev_migrate()' to update later")
return True
# Set up new development environment
complete_development_setup("awesome-ml-lib")Install with Tessl CLI
npx tessl i tessl/pypi-nbdev