|
50 | 50 | "id": "a1b2c3d4-0000-0000-0000-000000000003", |
51 | 51 | "metadata": {}, |
52 | 52 | "outputs": [], |
53 | | - "source": "import os, sys, subprocess\n\nIN_COLAB = \"google.colab\" in sys.modules\n\n# Install coordinode-embedded only when running in Colab AND no gRPC server is configured.\n# If COORDINODE_ADDR is set, a live server is already available — skip the 5-min Rust build.\nif IN_COLAB and not os.environ.get(\"COORDINODE_ADDR\"):\n # Install Rust toolchain via rustup (https://rustup.rs).\n # Colab's apt packages ship rustc ≤1.75, which cannot build coordinode-embedded\n # (requires Rust ≥1.80 for maturin/pyo3). apt-get is not a viable alternative here.\n # Download the installer to a temp file and execute it explicitly — this avoids\n # piping remote content directly into a shell while maintaining HTTPS/TLS security\n # through Python's default ssl context (cert-verified, TLS 1.2+).\n # SHA256 pinning of rustup-init is intentionally omitted: rustup.rs does not\n # publish a stable per-release checksum for sh.rustup.rs itself (only for\n # platform-specific rustup-init binaries), and pinning a hash here would break\n # silently on every rustup release. The HTTPS/TLS verification + temp-file\n # execution (not piped to shell) is the rustup team's recommended trust model.\n # No additional env-var gate (e.g. COORDINODE_ENABLE_RUSTUP) is needed:\n # the `IN_COLAB and not COORDINODE_ADDR` check above already ensures this block\n # never runs when a live gRPC server is available, so there is no risk of\n # unintentional execution in local or server environments.\n import ssl as _ssl, tempfile as _tmp, urllib.request as _ur\n\n _ctx = _ssl.create_default_context()\n with _tmp.NamedTemporaryFile(mode=\"wb\", suffix=\".sh\", delete=False) as _f:\n with _ur.urlopen(\"https://sh.rustup.rs\", context=_ctx, timeout=30) as _r:\n _f.write(_r.read())\n _rustup_path = _f.name\n try:\n subprocess.run([\"/bin/sh\", _rustup_path, \"-s\", \"--\", \"-y\", \"-q\"], check=True, timeout=300)\n finally:\n os.unlink(_rustup_path)\n # Add cargo to PATH so maturin/pip can find it.\n _cargo_bin = os.path.expanduser(\"~/.cargo/bin\")\n os.environ[\"PATH\"] = f\"{_cargo_bin}{os.pathsep}{os.environ.get('PATH', '')}\"\n subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"maturin\"], check=True, timeout=300)\n subprocess.run(\n [\n sys.executable,\n \"-m\",\n \"pip\",\n \"install\",\n \"-q\",\n \"git+https://github.com/structured-world/coordinode-python.git@4efc7b287211f4cfcf203ce92c83773d7d72ff61#subdirectory=coordinode-embedded\",\n ],\n check=True,\n timeout=600,\n )\n\nsubprocess.run(\n [\n sys.executable,\n \"-m\",\n \"pip\",\n \"install\",\n \"-q\",\n \"coordinode\",\n \"nest_asyncio\",\n ],\n check=True,\n timeout=300,\n)\n\nimport nest_asyncio\n\nnest_asyncio.apply()\n\nprint(\"Ready\")" |
| 53 | + "source": [ |
| 54 | + "import os, sys, subprocess\n", |
| 55 | + "\n", |
| 56 | + "IN_COLAB = \"google.colab\" in sys.modules\n", |
| 57 | + "\n", |
| 58 | + "# Install coordinode-embedded only when running in Colab AND no gRPC server is configured.\n", |
| 59 | + "# If COORDINODE_ADDR is set, a live server is already available — skip the 5-min Rust build.\n", |
| 60 | + "if IN_COLAB and not os.environ.get(\"COORDINODE_ADDR\"):\n", |
| 61 | + " # Install Rust toolchain via rustup (https://rustup.rs).\n", |
| 62 | + " # Colab's apt packages ship rustc ≤1.75, which cannot build coordinode-embedded\n", |
| 63 | + " # (requires Rust ≥1.80 for maturin/pyo3). apt-get is not a viable alternative here.\n", |
| 64 | + " # Download the installer to a temp file and execute it explicitly — this avoids\n", |
| 65 | + " # piping remote content directly into a shell while maintaining HTTPS/TLS security\n", |
| 66 | + " # through Python's default ssl context (cert-verified, TLS 1.2+).\n", |
| 67 | + " # SHA256 pinning of rustup-init is intentionally omitted: rustup.rs does not\n", |
| 68 | + " # publish a stable per-release checksum for sh.rustup.rs itself (only for\n", |
| 69 | + " # platform-specific rustup-init binaries), and pinning a hash here would break\n", |
| 70 | + " # silently on every rustup release. The HTTPS/TLS verification + temp-file\n", |
| 71 | + " # execution (not piped to shell) is the rustup team's recommended trust model.\n", |
| 72 | + " # No additional env-var gate (e.g. COORDINODE_ENABLE_RUSTUP) is needed:\n", |
| 73 | + " # the `IN_COLAB and not COORDINODE_ADDR` check above already ensures this block\n", |
| 74 | + " # never runs when a live gRPC server is available, so there is no risk of\n", |
| 75 | + " # unintentional execution in local or server environments.\n", |
| 76 | + " import ssl as _ssl, tempfile as _tmp, urllib.request as _ur\n", |
| 77 | + "\n", |
| 78 | + " _ctx = _ssl.create_default_context()\n", |
| 79 | + " with _tmp.NamedTemporaryFile(mode=\"wb\", suffix=\".sh\", delete=False) as _f:\n", |
| 80 | + " with _ur.urlopen(\"https://sh.rustup.rs\", context=_ctx, timeout=30) as _r:\n", |
| 81 | + " _f.write(_r.read())\n", |
| 82 | + " _rustup_path = _f.name\n", |
| 83 | + " try:\n", |
| 84 | + " subprocess.run([\"/bin/sh\", _rustup_path, \"-y\", \"-q\"], check=True, timeout=300)\n", |
| 85 | + " finally:\n", |
| 86 | + " os.unlink(_rustup_path)\n", |
| 87 | + " # Add cargo to PATH so maturin/pip can find it.\n", |
| 88 | + " _cargo_bin = os.path.expanduser(\"~/.cargo/bin\")\n", |
| 89 | + " os.environ[\"PATH\"] = f\"{_cargo_bin}{os.pathsep}{os.environ.get('PATH', '')}\"\n", |
| 90 | + " subprocess.run([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"maturin\"], check=True, timeout=300)\n", |
| 91 | + " subprocess.run(\n", |
| 92 | + " [\n", |
| 93 | + " sys.executable,\n", |
| 94 | + " \"-m\",\n", |
| 95 | + " \"pip\",\n", |
| 96 | + " \"install\",\n", |
| 97 | + " \"-q\",\n", |
| 98 | + " \"git+https://github.com/structured-world/coordinode-python.git@4efc7b287211f4cfcf203ce92c83773d7d72ff61#subdirectory=coordinode-embedded\",\n", |
| 99 | + " ],\n", |
| 100 | + " check=True,\n", |
| 101 | + " timeout=600,\n", |
| 102 | + " )\n", |
| 103 | + "\n", |
| 104 | + "subprocess.run(\n", |
| 105 | + " [\n", |
| 106 | + " sys.executable,\n", |
| 107 | + " \"-m\",\n", |
| 108 | + " \"pip\",\n", |
| 109 | + " \"install\",\n", |
| 110 | + " \"-q\",\n", |
| 111 | + " \"coordinode\",\n", |
| 112 | + " \"nest_asyncio\",\n", |
| 113 | + " ],\n", |
| 114 | + " check=True,\n", |
| 115 | + " timeout=300,\n", |
| 116 | + ")\n", |
| 117 | + "\n", |
| 118 | + "import nest_asyncio\n", |
| 119 | + "\n", |
| 120 | + "nest_asyncio.apply()\n", |
| 121 | + "\n", |
| 122 | + "print(\"Ready\")" |
| 123 | + ] |
54 | 124 | }, |
55 | 125 | { |
56 | 126 | "cell_type": "markdown", |
|
0 commit comments