Skip to content

Commit

Permalink
Merge pull request #152 from ocefpaf/install_missing_colab
Browse files Browse the repository at this point in the history
add hidden cell to install colab missing deps
  • Loading branch information
MathewBiddle authored Sep 1, 2023
2 parents a615c54 + fe955a3 commit cb0082a
Show file tree
Hide file tree
Showing 26 changed files with 956 additions and 42 deletions.
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ repos:
- id: double-quote-string-fixer

- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.0.0
rev: v3.0.3
hooks:
- id: prettier
types_or: [html]
Expand All @@ -30,12 +30,12 @@ repos:
language_version: python3

- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.1
rev: v3.1.0
hooks:
- id: add-trailing-comma

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.281
rev: v0.0.287
hooks:
- id: ruff

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"erddapy\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"cf_xarray\", \"palettable\", \"seawater\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"iris\", \"seawater\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,15 @@
"catalog = TDSCatalog(\"https://thredds.cencoos.org/thredds/catalog.xml\")\n",
"\n",
"\n",
"info = \"\"\"\n",
"info = f\"\"\"\n",
"Catalog information\n",
"-------------------\n",
"\n",
"Base THREDDS URL: {}\n",
"Catalog name: {}\n",
"Catalog URL: {}\n",
"Metadata: {}\n",
"\"\"\".format(\n",
" catalog.base_tds_url, catalog.catalog_name, catalog.catalog_url, catalog.metadata\n",
")\n",
"Base THREDDS URL: {catalog.base_tds_url}\n",
"Catalog name: {catalog.catalog_name}\n",
"Catalog URL: {catalog.catalog_url}\n",
"Metadata: {catalog.metadata}\n",
"\"\"\"\n",
"\n",
"print(info)"
]
Expand Down Expand Up @@ -234,13 +232,11 @@
}
],
"source": [
"info = \"\"\"\n",
"Href: {}\n",
"Name: {}\n",
"Title: {}\n",
"\"\"\".format(\n",
" ref.href, ref.name, ref.title\n",
")\n",
"info = f\"\"\"\n",
"Href: {ref.href}\n",
"Name: {ref.name}\n",
"Title: {ref.title}\n",
"\"\"\"\n",
"\n",
"print(info)"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"erddapy\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"owslib\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {
Expand Down Expand Up @@ -113,10 +153,8 @@
" \"SCCOOS\": \"Southern California Coastal Ocean Observing System\",\n",
" \"SECOORA\": \"Southeast Coastal Ocean Observing Regional Association\",\n",
" }\n",
" reg_assoc = '(dataThemeinstitutions_s:\"{}\" dataThemeprojects_s:\"{} ({})\")'.format(\n",
" RAs[ra],\n",
" RAs[ra],\n",
" ra,\n",
" reg_assoc = (\n",
" f'(dataThemeinstitutions_s:\"{RAs[ra]}\" dataThemeprojects_s:\"{RAs[ra]} ({ra})\")'\n",
" )\n",
"\n",
"# Identify the project.\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,45 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"tags": [
"remove-cell"
]
},
"outputs": [],
"source": [
"import subprocess\n",
"import sys\n",
"\n",
"COLAB = \"google.colab\" in sys.modules\n",
"\n",
"\n",
"def _install(package):\n",
" if COLAB:\n",
" ans = input(f\"Install { package }? [y/n]:\")\n",
" if ans.lower() in [\"y\", \"yes\"]:\n",
" subprocess.check_call(\n",
" [sys.executable, \"-m\", \"pip\", \"install\", \"--quiet\", package]\n",
" )\n",
" print(f\"{ package } installed!\")\n",
"\n",
"\n",
"def _colab_install_missing_deps(deps):\n",
" import importlib\n",
"\n",
" for dep in deps:\n",
" if importlib.util.find_spec(dep) is None:\n",
" if dep == \"iris\":\n",
" dep = \"scitools-iris\"\n",
" _install(dep)\n",
"\n",
"\n",
"deps = [\"cf-units\", \"ioos-tools\", \"pyoos\", \"retrying\"]\n",
"_colab_install_missing_deps(deps)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -46,7 +86,7 @@
},
"outputs": [],
"source": [
"import sys\n",
"import sys # noqa\n",
"from pathlib import Path\n",
"from urllib.request import urlopen, urlretrieve\n",
"\n",
Expand Down Expand Up @@ -6518,7 +6558,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.4"
"version": "3.11.5"
}
},
"nbformat": 4,
Expand Down
Loading

0 comments on commit cb0082a

Please sign in to comment.