mirror of
https://github.com/MLSysBook/TinyTorch.git
synced 2026-03-12 00:03:35 -05:00
Reorganize TinyTorch CLI from flat structure to hierarchical organization with subfolders for complex commands with subcommands. Changes: - Create subfolders: module/, system/, package/ - Move module commands: module_workflow.py → module/workflow.py - Move module_reset.py → module/reset.py - Move system commands: system.py → system/system.py - Move system subcommands: info.py, health.py, jupyter.py → system/ - Move package commands: package.py → package/package.py - Move package helpers: reset.py, nbdev.py → package/ - Archive deprecated files: clean.py, help.py, notebooks.py, status.py - Update all imports in moved files and main.py - Add __init__.py exports for each subfolder - Create comprehensive CLI test suite (52 tests) - test_cli_registry.py: Validate command registration - test_cli_execution.py: Smoke tests for all commands - test_cli_help_consistency.py: Help text validation - Update tests to match new structure Benefits: - Clear ownership: Easy to see which helpers belong to which commands - Better organization: Related files grouped together - Scales cleanly: Adding subcommands is straightforward - Zero user impact: All commands work exactly the same All 52 tests passing ✅ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
87 lines
3.9 KiB
Python
87 lines
3.9 KiB
Python
"""
|
|
nbdev command for TinyTorch CLI: runs nbdev commands for notebook development.
|
|
"""
|
|
|
|
import subprocess
|
|
from argparse import ArgumentParser, Namespace
|
|
from rich.panel import Panel
|
|
|
|
from ..base import BaseCommand
|
|
|
|
class NbdevCommand(BaseCommand):
|
|
@property
|
|
def name(self) -> str:
|
|
return "nbdev"
|
|
|
|
@property
|
|
def description(self) -> str:
|
|
return "nbdev notebook development commands"
|
|
|
|
def add_arguments(self, parser: ArgumentParser) -> None:
|
|
parser.add_argument("--export", action="store_true", help="Export notebooks to Python package")
|
|
parser.add_argument("--build-docs", action="store_true", help="Build documentation from notebooks")
|
|
parser.add_argument("--test", action="store_true", help="Run notebook tests")
|
|
parser.add_argument("--clean", action="store_true", help="Clean notebook outputs")
|
|
parser.add_argument("--all", action="store_true", help="Export all modules (use with --export)")
|
|
parser.add_argument("module", nargs="?", help="Export specific module (use with --export)")
|
|
|
|
def run(self, args: Namespace) -> int:
|
|
console = self.console
|
|
|
|
console.print(Panel("📓 nbdev Notebook Development",
|
|
title="Notebook Tools", border_style="bright_cyan"))
|
|
|
|
if args.export:
|
|
# Use the export command logic
|
|
from ..export import ExportCommand
|
|
export_cmd = ExportCommand(self.config)
|
|
export_args = ArgumentParser()
|
|
export_cmd.add_arguments(export_args)
|
|
|
|
# Build the arguments for export command
|
|
export_arg_list = []
|
|
if args.all:
|
|
export_arg_list.append("--all")
|
|
elif args.module:
|
|
export_arg_list.append(args.module)
|
|
|
|
export_args = export_args.parse_args(export_arg_list)
|
|
return export_cmd.run(export_args)
|
|
|
|
elif args.build_docs:
|
|
console.print("📚 Building documentation from notebooks...")
|
|
result = subprocess.run(["nbdev_docs"], capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
console.print(Panel("[green]✅ Documentation built successfully![/green]",
|
|
title="Docs Success", border_style="green"))
|
|
else:
|
|
console.print(Panel(f"[red]❌ Docs build failed: {result.stderr}[/red]",
|
|
title="Docs Error", border_style="red"))
|
|
return result.returncode
|
|
|
|
elif args.test:
|
|
console.print("🧪 Running notebook tests...")
|
|
result = subprocess.run(["nbdev_test"], capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
console.print(Panel("[green]✅ Notebook tests passed![/green]",
|
|
title="Test Success", border_style="green"))
|
|
else:
|
|
console.print(Panel(f"[red]❌ Notebook tests failed: {result.stderr}[/red]",
|
|
title="Test Error", border_style="red"))
|
|
return result.returncode
|
|
|
|
elif args.clean:
|
|
console.print("🧹 Cleaning notebook outputs...")
|
|
result = subprocess.run(["nbdev_clean"], capture_output=True, text=True)
|
|
if result.returncode == 0:
|
|
console.print(Panel("[green]✅ Notebook outputs cleaned![/green]",
|
|
title="Clean Success", border_style="green"))
|
|
else:
|
|
console.print(Panel(f"[red]❌ Clean failed: {result.stderr}[/red]",
|
|
title="Clean Error", border_style="red"))
|
|
return result.returncode
|
|
|
|
else:
|
|
console.print(Panel("[yellow]⚠️ No nbdev action specified. Use --export, --build-docs, --test, or --clean[/yellow]",
|
|
title="No Action", border_style="yellow"))
|
|
return 1 |