From 4244ebe8914d1e869e6d1dfac6a847dd4885c48d Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:16:22 +0200 Subject: [PATCH 01/11] Fix URL --- notebooks/Colab_inference_demo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index c31206da..783a5bb6 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -7,7 +7,7 @@ "id": "view-in-github" }, "source": [ - "\"Open" + "\"Open" ] }, { From 062f994f55dc75fffaea5345472c65f5bc8303df Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:18:31 +0200 Subject: [PATCH 02/11] Add uv install --- notebooks/Colab_inference_demo.ipynb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 783a5bb6..4c666fba 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -54,8 +54,16 @@ "outputs": [], "source": [ "# @markdown ##Install CellSeg3D and grab demo data\n", + "!curl -LsSf https://astral.sh/uv/install.sh | sh\n", + "import os\n", + "\n", + "os.environ[\"PATH\"] += \":/root/.local/bin\"\n", + "\n", + "# Clone CellSeg3D\n", "!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n", - "!pip install napari-cellseg3d" + "\n", + "# Install with uv\n", + "!uv pip install napari-cellseg3d" ] }, { From 949d0d093048ed6aa9ea4594266e598086463a9b Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:28:27 +0200 Subject: [PATCH 03/11] Add force restart after install --- notebooks/Colab_inference_demo.ipynb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 4c666fba..0670e407 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -66,6 +66,27 @@ "!uv pip install napari-cellseg3d" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "After installing the dependencies, the runtime must be restarted to use the newly installed packages.\n", + "\n", + "The following cell will force the runtime to restart; **please run it and then re-run the notebook from the beginning.**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# @markdown Force Colab runtime restart\n", + "import os\n", + "\n", + "os.kill(os.getpid(), 9)" + ] + }, { "cell_type": "markdown", "metadata": { From e325c4e3eeb17f5c0a672076a26819b26e4411b8 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:36:42 +0200 Subject: [PATCH 04/11] Add better checks for install --- notebooks/Colab_inference_demo.ipynb | 61 +++++++++++++++++----------- 1 file changed, 38 insertions(+), 23 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 0670e407..81d157e9 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -53,38 +53,53 @@ }, "outputs": [], "source": [ - "# @markdown ##Install CellSeg3D and grab demo data\n", - "!curl -LsSf https://astral.sh/uv/install.sh | sh\n", - "import os\n", + "# @markdown ## Install CellSeg3D only if needed\n", + "def cellseg3d_ok():\n", + " try:\n", + " import napari_cellseg3d\n", + " from napari_cellseg3d.dev_scripts import remote_inference\n", "\n", - "os.environ[\"PATH\"] += \":/root/.local/bin\"\n", + " return True\n", + " except Exception as e:\n", + " print(\"CellSeg3D import failed:\")\n", + " print(e)\n", + " return False\n", "\n", - "# Clone CellSeg3D\n", - "!git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git --branch main --single-branch ./CellSeg3D\n", "\n", - "# Install with uv\n", - "!uv pip install napari-cellseg3d" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "After installing the dependencies, the runtime must be restarted to use the newly installed packages.\n", + "if not cellseg3d_ok():\n", + " # Install uv\n", + " !curl -LsSf https://astral.sh/uv/install.sh | sh\n", + "\n", + " import os\n", + "\n", + " os.environ[\"PATH\"] += \":/root/.local/bin\"\n", + "\n", + " # Clone repo\n", + " !git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git \\\n", + " --branch main \\\n", + " --single-branch \\\n", + " ./CellSeg3D\n", "\n", - "The following cell will force the runtime to restart; **please run it and then re-run the notebook from the beginning.**" + " # Install compatible stack\n", + " !uv pip install napari-cellseg3d\n", + "\n", + " print(\"Restarting runtime...\")\n", + "\n", + " # Restart only after installation\n", + " os.kill(os.getpid(), 9)\n", + "\n", + "else:\n", + " print(\"CellSeg3D already available — skipping install.\")" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# @markdown Force Colab runtime restart\n", - "import os\n", - "\n", - "os.kill(os.getpid(), 9)" + "```{important}\n", + "The runtime must be restarted after installing CellSeg3D to use the newly installed package. \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", + "```" ] }, { From c84d6ee05e75bc569ac4d72aa363a702f85f0685 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:37:16 +0200 Subject: [PATCH 05/11] Fix URL again --- notebooks/Colab_inference_demo.ipynb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 81d157e9..d28755d5 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -7,7 +7,7 @@ "id": "view-in-github" }, "source": [ - "\"Open" + "\"Open" ] }, { @@ -96,10 +96,17 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "```{important}\n", + "\n", + "
\n", + " ⚠️ Runtime restart is required after installation
\n", "The runtime must be restarted after installing CellSeg3D to use the newly installed package. \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", - "```" + "
" ] }, { From f0653cc8db9642aa4479d7f4e10e11d9f15d4f06 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 13:39:53 +0200 Subject: [PATCH 06/11] Fix commands syntax --- notebooks/Colab_inference_demo.ipynb | 66 +++++++++++++++++++++------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index d28755d5..ff5c8382 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -54,42 +54,78 @@ "outputs": [], "source": [ "# @markdown ## Install CellSeg3D only if needed\n", + "\n", + "import os\n", + "import shutil\n", + "import subprocess\n", + "import sys\n", + "from pathlib import Path\n", + "\n", + "\n", + "def run(cmd, **kwargs):\n", + " print(\"+\", \" \".join(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(e)\n", + " print(type(e).__name__, e)\n", " return False\n", "\n", "\n", "if not cellseg3d_ok():\n", - " # Install uv\n", - " !curl -LsSf https://astral.sh/uv/install.sh | sh\n", + " print(\"Installing CellSeg3D environment...\")\n", "\n", - " import os\n", + " # Install uv into the current Colab Python environment\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", - " os.environ[\"PATH\"] += \":/root/.local/bin\"\n", + " # Clone repo only if missing\n", + " if not Path(\"CellSeg3D\").is_dir():\n", + " run(\n", + " [\n", + " \"git\",\n", + " \"clone\",\n", + " \"https://github.com/AdaptiveMotorControlLab/CellSeg3D.git\",\n", + " \"--branch\",\n", + " \"main\",\n", + " \"--single-branch\",\n", + " \"./CellSeg3D\",\n", + " ]\n", + " )\n", + " else:\n", + " print(\"CellSeg3D repo already cloned.\")\n", "\n", - " # Clone repo\n", - " !git clone https://github.com/AdaptiveMotorControlLab/CellSeg3d.git \\\n", - " --branch main \\\n", - " --single-branch \\\n", - " ./CellSeg3D\n", + " # Install into the active Colab environment\n", + " run(\n", + " [\n", + " \"uv\",\n", + " \"pip\",\n", + " \"install\",\n", + " \"--system\",\n", + " \"napari-cellseg3d\",\n", + " ]\n", + " )\n", "\n", - " # Install compatible stack\n", - " !uv pip install napari-cellseg3d\n", + " # Optional dependency consistency check\n", + " run([\"uv\", \"pip\", \"check\", \"--system\"])\n", "\n", - " print(\"Restarting runtime...\")\n", + " print(\"Restarting runtime to reload installed binary dependencies...\")\n", "\n", - " # Restart only after installation\n", " os.kill(os.getpid(), 9)\n", "\n", "else:\n", - " print(\"CellSeg3D already available — skipping install.\")" + " print(\"CellSeg3D already available — skipping install and restart.\")" ] }, { From 265e0a1bdba995d3205f756ce88335f029b98354 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 14:00:53 +0200 Subject: [PATCH 07/11] Update Colab_inference_demo.ipynb --- notebooks/Colab_inference_demo.ipynb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index ff5c8382..d59bfb09 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -121,6 +121,9 @@ " run([\"uv\", \"pip\", \"check\", \"--system\"])\n", "\n", " print(\"Restarting runtime to reload installed binary dependencies...\")\n", + " print(\n", + " \"This will be shown as a crash, but this is expected. Please simply run the notebook again from the beginning after the runtime restarts.\"\n", + " )\n", "\n", " os.kill(os.getpid(), 9)\n", "\n", @@ -141,7 +144,8 @@ "\">\n", " ⚠️ Runtime restart is required after installation
\n", "The runtime must be restarted after installing CellSeg3D to use the newly installed package. \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", + "\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", "" ] }, From 5be31ff77d4a8c425ee518016ce4a3cf09a780ae Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 14:03:07 +0200 Subject: [PATCH 08/11] Update Colab_inference_demo.ipynb --- notebooks/Colab_inference_demo.ipynb | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index d59bfb09..24a7d49f 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -82,15 +82,13 @@ "\n", "\n", "if not cellseg3d_ok():\n", - " print(\"Installing CellSeg3D environment...\")\n", + " print(\"Installing CellSeg3D...\")\n", "\n", - " # Install uv into the current Colab Python environment\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", - " # Clone repo only if missing\n", " if not Path(\"CellSeg3D\").is_dir():\n", " run(\n", " [\n", @@ -106,7 +104,6 @@ " else:\n", " print(\"CellSeg3D repo already cloned.\")\n", "\n", - " # Install into the active Colab environment\n", " run(\n", " [\n", " \"uv\",\n", @@ -117,9 +114,6 @@ " ]\n", " )\n", "\n", - " # Optional dependency consistency check\n", - " run([\"uv\", \"pip\", \"check\", \"--system\"])\n", - "\n", " print(\"Restarting runtime to reload installed binary dependencies...\")\n", " print(\n", " \"This will be shown as a crash, but this is expected. Please simply run the notebook again from the beginning after the runtime restarts.\"\n", From b3d6cacb4de0d92a5dba8ac678d8cb8edbf03547 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 15:13:46 +0200 Subject: [PATCH 09/11] Colab demo: ensure demo data; refine install flow Update Colab_inference_demo.ipynb to ensure demo data and improve setup flow. Add REPO_DIR/DEMO_FILE/REPO_URL constants, import time, and a run() print fix. Introduce ensure_demo_data() to clone the CellSeg3D repo and verify the expected example file, removing previous ad-hoc cloning logic. Track whether the package was installed with installed_package, improve user messages about runtime restart, add a short sleep before killing the process, and print a concise completion message when setup is already satisfied. --- notebooks/Colab_inference_demo.ipynb | 77 ++++++++++++++++++++-------- 1 file changed, 57 insertions(+), 20 deletions(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index 24a7d49f..b1087599 100644 --- a/notebooks/Colab_inference_demo.ipynb +++ b/notebooks/Colab_inference_demo.ipynb @@ -53,17 +53,22 @@ }, "outputs": [], "source": [ - "# @markdown ## Install CellSeg3D only if needed\n", + "# @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(cmd))\n", + " print(\"+\", \" \".join(map(str, cmd)))\n", " subprocess.check_call(cmd, **kwargs)\n", "\n", "\n", @@ -81,7 +86,41 @@ " return False\n", "\n", "\n", - "if not cellseg3d_ok():\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", @@ -89,21 +128,6 @@ " else:\n", " print(\"uv already installed.\")\n", "\n", - " if not Path(\"CellSeg3D\").is_dir():\n", - " run(\n", - " [\n", - " \"git\",\n", - " \"clone\",\n", - " \"https://github.com/AdaptiveMotorControlLab/CellSeg3D.git\",\n", - " \"--branch\",\n", - " \"main\",\n", - " \"--single-branch\",\n", - " \"./CellSeg3D\",\n", - " ]\n", - " )\n", - " else:\n", - " print(\"CellSeg3D repo already cloned.\")\n", - "\n", " run(\n", " [\n", " \"uv\",\n", @@ -114,15 +138,28 @@ " ]\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", - " \"This will be shown as a crash, but this is expected. Please simply run the notebook again from the beginning after the runtime restarts.\"\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(\"CellSeg3D already available — skipping install and restart.\")" + " print(\"Setup complete.\")" ] }, { From eb8c2926e04d3528ab1d122245f6b6dc64fd66b4 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 15:19:23 +0200 Subject: [PATCH 10/11] URL case fix --- notebooks/Colab_inference_demo.ipynb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notebooks/Colab_inference_demo.ipynb b/notebooks/Colab_inference_demo.ipynb index b1087599..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" ] }, { From 8a32c378b3354902b8871492fd7863b909f117d3 Mon Sep 17 00:00:00 2001 From: Cyril Achard Date: Thu, 21 May 2026 15:37:03 +0200 Subject: [PATCH 11/11] Update test_plugins.py --- napari_cellseg3d/_tests/test_plugins.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) 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