|
| 1 | +# Binder Configuration |
| 2 | + |
| 3 | +This directory contains configuration files for [MyBinder.org](https://mybinder.org), |
| 4 | +which allows users to launch interactive Jupyter notebooks in the cloud. |
| 5 | + |
| 6 | +## Single Source of Truth |
| 7 | + |
| 8 | +The binder setup draws from the same source as Docker and DevContainer: |
| 9 | + |
| 10 | +| Component | Source | |
| 11 | +|-----------|--------| |
| 12 | +| Python dependencies | `pyproject.toml` (installed via `uv`) | |
| 13 | +| System dependencies | Same as `Dockerfile` (Node.js 18, curl, git, make) | |
| 14 | +| Environment setup | Mirrors `reproduce/docker/setup.sh` | |
| 15 | + |
| 16 | +## Files |
| 17 | + |
| 18 | +| File | Purpose | |
| 19 | +|------|---------| |
| 20 | +| `environment.yml` | Minimal conda env (Python 3.12 + pip) | |
| 21 | +| `apt.txt` | System packages (curl, git, make) | |
| 22 | +| `postBuild` | Installs Node.js 18, uv, and project dependencies | |
| 23 | +| `README.md` | This file | |
| 24 | + |
| 25 | +## How It Works |
| 26 | + |
| 27 | +1. **Binder reads `environment.yml`** → Creates conda environment with Python 3.12 |
| 28 | +2. **Binder reads `apt.txt`** → Installs system packages via apt-get |
| 29 | +3. **Binder runs `postBuild`** → Installs Node.js 18, uv, and all Python dependencies |
| 30 | + |
| 31 | +The `postBuild` script: |
| 32 | +- Installs Node.js 18 from nodesource (required by MyST) |
| 33 | +- Installs `uv` package manager |
| 34 | +- Runs `uv pip install --system -e .` to install from `pyproject.toml` |
| 35 | +- Configures `PYTHONPATH` for the `code/` directory |
| 36 | +- Warms up matplotlib and numba caches |
| 37 | + |
| 38 | +## Launching on MyBinder |
| 39 | + |
| 40 | +Click the binder badge in the main README, or use this URL: |
| 41 | + |
| 42 | +``` |
| 43 | +https://mybinder.org/v2/gh/econ-ark/method-of-moderation/main |
| 44 | +``` |
| 45 | + |
| 46 | +## Testing Locally |
| 47 | + |
| 48 | +To test the binder configuration locally: |
| 49 | + |
| 50 | +```bash |
| 51 | +# Option 1: Use Docker (recommended) |
| 52 | +docker build -t method-of-moderation . |
| 53 | +docker run -it --rm -p 8888:8888 method-of-moderation jupyter lab --ip=0.0.0.0 --no-browser |
| 54 | + |
| 55 | +# Option 2: Use the setup script directly |
| 56 | +bash reproduce/docker/setup.sh |
| 57 | +source .venv-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m)/bin/activate |
| 58 | +jupyter lab |
| 59 | +``` |
| 60 | + |
| 61 | +## Relationship to Other Environments |
| 62 | + |
| 63 | +``` |
| 64 | + ┌─────────────────────┐ |
| 65 | + │ pyproject.toml │ ← Single Source of Truth |
| 66 | + │ (dependencies) │ |
| 67 | + └─────────┬───────────┘ |
| 68 | + │ |
| 69 | + ┌─────────────────────┼─────────────────────┐ |
| 70 | + │ │ │ |
| 71 | + ▼ ▼ ▼ |
| 72 | +┌───────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 73 | +│ Dockerfile │ │ devcontainer │ │ Binder │ |
| 74 | +│ │ │ .json │ │ postBuild │ |
| 75 | +└───────┬───────┘ └────────┬────────┘ └────────┬────────┘ |
| 76 | + │ │ │ |
| 77 | + ▼ ▼ ▼ |
| 78 | +┌───────────────┐ ┌─────────────────┐ ┌─────────────────┐ |
| 79 | +│ reproduce/ │ │ reproduce/ │ │ uv pip install │ |
| 80 | +│ docker/ │ │ docker/ │ │ --system -e . │ |
| 81 | +│ setup.sh │ │ setup.sh │ │ │ |
| 82 | +└───────────────┘ └─────────────────┘ └─────────────────┘ |
| 83 | +``` |
| 84 | + |
| 85 | +All three environments install the same dependencies from `pyproject.toml`, |
| 86 | +ensuring consistency across local development, CI, and cloud notebooks. |
0 commit comments