Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Sep 2, 2025

This PR implements Docker backend support for micropython-magic, allowing users to run MicroPython code in Docker containers instead of requiring physical MCU hardware.

Key Changes

🐳 Docker Backend Implementation

  • New DockerMicroPython class that interfaces with micropython/unix:latest Docker containers
  • Modified MPRemote2 to support both serial and Docker backends via a backend parameter
  • Enhanced magic commands with --backend docker and --docker-image options
  • Container lifecycle management that automatically creates, starts, and reuses containers between magic calls

🎯 Usage Examples

Basic Docker execution:

%%micropython --backend docker
print("Hello from MicroPython in Docker!")
import sys
print(f"Running: {sys.version}")

Line magic with system info:

%micropython --backend docker --info

Custom Docker image:

%%micropython --backend docker --docker-image micropython/unix:latest
print("Using specific image version")

🔧 Backend Selection

  • Seamless switching between --backend serial (default, existing behavior) and --backend docker
  • Full backward compatibility - existing notebooks continue to work unchanged
  • Graceful fallback when Docker is not available with clear error messages

📚 Documentation & Testing

  • Comprehensive demo notebook (samples/docker_backend_demo.ipynb) showcasing all features
  • Updated README with installation instructions and usage examples
  • Complete test suite covering Docker backend functionality and integration
  • Unit tests for both backend selection and container management

🎯 Benefits

  • No hardware required - Perfect for learning, development, and CI/CD
  • Consistent environment - Same MicroPython version across different machines
  • Easy setup - Just requires Docker installation
  • Safe experimentation - No risk of damaging physical hardware
  • Educational friendly - Ideal for workshops and tutorials

🚧 Limitations

  • No GPIO/hardware access (no machine module functionality)
  • No hardware-specific features (WiFi, sensors, etc.)
  • Variables don't persist between cells (each execution is independent)

The Docker backend uses the official micropython/unix:latest image and is ideal for algorithm development, code validation, and educational use cases before deploying to physical hardware.

Fixes #54.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Josverl Josverl changed the title [WIP] use unix or windows versions of micropython to be used [WIP] use unix or windows versions of micropython Sep 2, 2025
Copilot AI and others added 3 commits September 2, 2025 12:22
- Added DockerMicroPython class supporting micropython/unix containers
- Modified MPRemote2 to support both serial and docker backends
- Added --backend and --docker-image arguments to magic commands
- Implemented container lifecycle management with persistence
- All basic functionality working: exec, eval, cell magic, line magic
- Container automatically starts and stays alive between cells

Co-authored-by: Josverl <[email protected]>
- Added comprehensive Docker backend tests
- Created docker_backend_demo.ipynb showcasing all functionality
- Updated README with Docker backend installation and usage instructions
- Added graceful handling for missing docker dependency
- All tests passing for both serial and Docker backends

Co-authored-by: Josverl <[email protected]>
@Copilot Copilot AI changed the title [WIP] use unix or windows versions of micropython Add Docker backend support for MicroPython execution without hardware Sep 2, 2025
@Copilot Copilot AI requested a review from Josverl September 2, 2025 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

use unix or windows versions of micropython
2 participants