Skip to content

Commit a4eb9ca

Browse files
zivyMasood-Akram
andcommitted
Propagate improved support for google colab.
Propagate the changes proposed by Masood-Akram in previous commit. More robust runtime environment identification, are we on colab or not. Also more efficient shallow repository cloning. Co-authored-by: Masood-Akram <masoodakram@mednet.ucla.edu>
1 parent bb86266 commit a4eb9ca

22 files changed

Lines changed: 242 additions & 88 deletions

Python/02_Pythonic_Image.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/03_Image_Details.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/04_Image_Display.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/05_Results_Visualization.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/10_matplotlibs_imshow.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/11_Progress.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/20_Expand_With_Interpolators.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/21_Transforms_and_Resampling.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/22_Transforms.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

Python/300_Segmentation_Overview.ipynb

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,19 @@
2323
"outputs": [],
2424
"source": [
2525
"# Setup to enable running the notebook in the Google Colab environment\n",
26-
"import os\n",
2726
"\n",
28-
"if \"COLAB_NOTEBOOK_ID\" in os.environ:\n",
29-
" !git clone https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
27+
"try:\n",
28+
" import google.colab\n",
29+
" import pathlib\n",
30+
"\n",
31+
" repo_dir = pathlib.Path(\"SimpleITK-Notebooks\")\n",
32+
" if not repo_dir.exists():\n",
33+
" !git clone --depth 1 https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks\n",
3034
" %cd SimpleITK-Notebooks/Python\n",
31-
" !pip install -q -r requirements.txt"
35+
" !pip install -q -r requirements.txt\n",
36+
"\n",
37+
"except ImportError:\n",
38+
" pass # not on Colab"
3239
]
3340
},
3441
{

0 commit comments

Comments
 (0)