diff --git a/napari_cellseg3d/_tests/test_plugins.py b/napari_cellseg3d/_tests/test_plugins.py index a91e67ea..5d487b9e 100644 --- a/napari_cellseg3d/_tests/test_plugins.py +++ b/napari_cellseg3d/_tests/test_plugins.py @@ -8,10 +8,11 @@ def test_all_plugins_import(make_napari_viewer_proxy): plugins.napari_experimental_provide_dock_widget() -def test_plugin_metrics(make_napari_viewer_proxy): +def test_plugin_metrics(make_napari_viewer_proxy, qtbot): viewer = make_napari_viewer_proxy() w = m.MetricsUtils(viewer=viewer, parent=None) - viewer.window.add_dock_widget(w) + qtbot.addWidget(w) + # viewer.window.add_dock_widget(w) im_path = str(Path(__file__).resolve().parent / "res/test.tif") labels_path = im_path diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index c31206da..b1703f2c 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -7,7 +7,7 @@ "id": "view-in-github" }, "source": [ - "\"Open" + "\"Open" ] }, { @@ -53,9 +53,131 @@ }, "outputs": [], "source": [ - "# @markdown ##Install CellSeg3D and grab demo data\n", - "!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n", - "!pip install napari-cellseg3d" + "# @markdown ## Install CellSeg3D and ensure demo data\n", + "\n", + "import os\n", + "import shutil\n", + "import subprocess\n", + "import sys\n", + "import time\n", + "from pathlib import Path\n", + "\n", + "REPO_DIR = Path(\"/content/CellSeg3D\")\n", + "DEMO_FILE = REPO_DIR / \"examples\" / \"c5image.tif\"\n", + "REPO_URL = \"https://github.com/AdaptiveMotorControlLab/CellSeg3D.git\"\n", + "\n", + "\n", + "def run(cmd, **kwargs):\n", + " print(\"+\", \" \".join(map(str, cmd)))\n", + " subprocess.check_call(cmd, **kwargs)\n", + "\n", + "\n", + "def cellseg3d_ok():\n", + " try:\n", + " import napari_cellseg3d\n", + " from napari_cellseg3d.dev_scripts import remote_inference\n", + "\n", + " print(\"CellSeg3D import OK.\")\n", + " return True\n", + "\n", + " except Exception as e:\n", + " print(\"CellSeg3D import failed:\")\n", + " print(type(e).__name__, e)\n", + " return False\n", + "\n", + "\n", + "def ensure_demo_data():\n", + " if DEMO_FILE.is_file():\n", + " print(f\"Demo data found: {DEMO_FILE}\")\n", + " return\n", + "\n", + " print(\"Demo data not found. Cloning CellSeg3D repository...\")\n", + "\n", + " if REPO_DIR.exists():\n", + " print(f\"Removing incomplete existing directory: {REPO_DIR}\")\n", + " shutil.rmtree(REPO_DIR)\n", + "\n", + " run(\n", + " [\n", + " \"git\",\n", + " \"clone\",\n", + " REPO_URL,\n", + " \"--branch\",\n", + " \"main\",\n", + " \"--single-branch\",\n", + " str(REPO_DIR),\n", + " ]\n", + " )\n", + "\n", + " if not DEMO_FILE.is_file():\n", + " raise FileNotFoundError(\n", + " f\"Expected demo file was not found after cloning: {DEMO_FILE}\"\n", + " )\n", + "\n", + " print(f\"Demo data ready: {DEMO_FILE}\")\n", + "\n", + "\n", + "package_ok = cellseg3d_ok()\n", + "installed_package = False\n", + "\n", + "if not package_ok:\n", + " print(\"Installing CellSeg3D...\")\n", + "\n", + " if shutil.which(\"uv\") is None:\n", + " run([sys.executable, \"-m\", \"pip\", \"install\", \"-q\", \"uv\"])\n", + " else:\n", + " print(\"uv already installed.\")\n", + "\n", + " run(\n", + " [\n", + " \"uv\",\n", + " \"pip\",\n", + " \"install\",\n", + " \"--system\",\n", + " \"napari-cellseg3d\",\n", + " ]\n", + " )\n", + "\n", + " installed_package = True\n", + "\n", + "else:\n", + " print(\"CellSeg3D already available — skipping package install.\")\n", + "\n", + "\n", + "ensure_demo_data()\n", + "\n", + "\n", + "if installed_package:\n", + " print(\"Restarting runtime to reload installed binary dependencies...\")\n", + " print(\n", + " \"Colab may show this as a crash, but it is expected. \"\n", + " \"After the runtime reconnects, run the notebook again from the beginning. \"\n", + " \"This cell should then skip installation and continue normally.\"\n", + " )\n", + "\n", + " time.sleep(1)\n", + " os.kill(os.getpid(), 9)\n", + "\n", + "else:\n", + " print(\"Setup complete.\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "
\n", + " ⚠️ Runtime restart is required after installation
\n", + "The runtime must be restarted after installing CellSeg3D to use the newly installed package. \n", + "\n", + "The notebook will \"crash\" after installing, but this is expected, you may simply run the notebook again from the beginning after the runtime restarts.\n", + "
" ] }, {