Fix Binder setup to generate notebooks at build time

- Add jupytext dependency to binder/requirements.txt
- Update postBuild to convert src/*.py files to modules/*.ipynb
- Document the notebook generation workflow in README.md

This ensures Binder users get ready-to-use notebooks that are
always in sync with the source Python files.
This commit is contained in:
Vijay Janapa Reddi
2025-12-02 20:51:18 -05:00
parent 354540b855
commit 6a99354213
3 changed files with 37 additions and 8 deletions

View File

@@ -14,8 +14,13 @@ This directory contains configuration files for running TinyTorch in cloud envir
When users click the "Launch Binder" button on any notebook page in the TinyTorch documentation:
1. Binder reads `binder/requirements.txt` to install Python dependencies
2. Binder runs `binder/postBuild` to install the TinyTorch package (`pip install -e .`)
3. Users get a fully configured JupyterLab environment with TinyTorch ready to use
2. Binder runs `binder/postBuild` which:
- Installs the TinyTorch package (`pip install -e .`)
- Generates student notebooks from `src/*.py` files using Jupytext
- Populates `modules/` with ready-to-use Jupyter notebooks
3. Users get a fully configured JupyterLab environment with TinyTorch and all notebooks ready to use
**Note**: The `modules/` directory is gitignored because notebooks are generated from the source `.py` files. This ensures students always get notebooks that match the current code.
**Binder URL Format:**
```

View File

@@ -7,14 +7,35 @@ set -e
echo "🔧 Installing TinyTorch package..."
pip install -e .
echo "✅ TinyTorch installation complete!"
echo ""
echo "📓 Generating student notebooks from source..."
# Convert all src/*.py files to notebooks in modules/
# This ensures students always get fresh notebooks matching the code
for module_dir in src/*/; do
module_name=$(basename "$module_dir")
py_file="$module_dir/${module_name}.py"
if [ -f "$py_file" ]; then
# Create output directory
mkdir -p "modules/$module_name"
# Convert .py to .ipynb using jupytext
echo " 📝 Converting $module_name..."
jupytext --to notebook "$py_file" --output "modules/$module_name/${module_name}.ipynb" 2>/dev/null || {
echo " ⚠️ Warning: Could not convert $module_name"
}
fi
done
echo ""
echo "✅ TinyTorch setup complete!"
echo ""
echo "📚 Available resources:"
echo " - TinyTorch modules: modules/"
echo " - Course assignments: assignments/"
echo " - TinyTorch modules: modules/ (Jupyter notebooks)"
echo " - Source files: src/ (Python files)"
echo " - Milestone examples: milestones/"
echo ""
echo "🚀 Start exploring with:"
echo " - jupyter lab"
echo " - Or open notebooks directly from the file browser"
echo " - Open any notebook from modules/ in the file browser"
echo " - Or import tinytorch in a new notebook"

View File

@@ -23,6 +23,9 @@ matplotlib>=3.9.0
# Type checking support
typing-extensions>=4.12.0
# Jupytext (required to convert src/*.py to notebooks)
jupytext>=1.16.0
# Note: tinytorch package itself is installed via postBuild script
# This ensures the latest code from the repository is used