Skip to content

Commit f6ae8b8

Browse files
committed
colab: make setup cell more robust
1 parent f4a4163 commit f6ae8b8

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

Python/01_Image_Basics.ipynb

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,21 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
26+
"import pathlib\n",
2727
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
28+
"def _in_colab() -> bool:\n",
29+
" try:\n",
30+
" import google.colab # noqa: F401\n",
31+
" return True\n",
32+
" except Exception:\n",
33+
" return False\n",
34+
"\n",
35+
"if _in_colab():\n",
36+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
37+
" if not repo_dir.exists():\n",
38+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3039
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
40+
" !pip install -q -r requirements.txt\n"
3241
]
3342
},
3443
{

0 commit comments

Comments
 (0)