Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

Commit

Permalink
Move code to install the module outside of the module
Browse files Browse the repository at this point in the history
Fixes #12
  • Loading branch information
tylere committed Sep 20, 2022
1 parent ce268bb commit c18497d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
25 changes: 5 additions & 20 deletions 00_core.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,18 @@
"outputs": [],
"source": [
"#|export\n",
"def colab_gee_setup():\n",
" \"\"\"Setup Colab so it can use the earthengine-jupyter package.\n",
"def authenticate_if_needed():\n",
" \"\"\"Authenticate Earth Engine, if credentials do not exist.\n",
" \n",
" * Install earthengine-jupyter package.\n",
" * Authenticate, if needed.\"\"\"\n",
" \n",
" import ee\n",
" import os\n",
"\n",
" print('Verifying environment is setup for earthengine-jupyter...')\n",
" \n",
" try:\n",
" import ee_jupyter\n",
" print('\\N{check mark} The package earthengine-jupyter is already installed.')\n",
" except ModuleNotFoundError:\n",
" print('\\N{check mark} Installing earthengine-jupyter...')\n",
" result = os.system('pip -q install earthengine-jupyter')\n",
" \n",
" if os.path.exists(ee.oauth.get_credentials_path()):\n",
" print('\\N{check mark} Authentication credentials were found.')\n",
" else:\n",
" ee.Authenticate()\n",
"\n",
" print('\\N{check mark} Done.')"
" ee.Authenticate()"
]
},
{
Expand All @@ -106,15 +94,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Verifying environment is setup for earthengine-jupyter...\n",
"✓ The package earthengine-jupyter is already installed.\n",
"✓ Authentication credentials were found.\n",
"✓ Done.\n"
"✓ Authentication credentials were found.\n"
]
}
],
"source": [
"colab_gee_setup()"
"authenticate_if_needed()"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion ee_jupyter/_modidx.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'doc_host': 'https://googlestaging.github.io',
'git_url': 'https://github.com/googlestaging/earthengine-jupyter',
'lib_path': 'ee_jupyter'},
'syms': { 'ee_jupyter.core': {'ee_jupyter.core.colab_gee_setup': ('core.html#colab_gee_setup', 'ee_jupyter/core.py')},
'syms': { 'ee_jupyter.core': {'ee_jupyter.core.authenticate_if_needed': ('core.html#authenticate_if_needed', 'ee_jupyter/core.py')},
'ee_jupyter.ipyleaflet': { 'ee_jupyter.ipyleaflet.Inspector': ('ipyleaflet.html#inspector', 'ee_jupyter/ipyleaflet.py'),
'ee_jupyter.ipyleaflet.Inspector.__init__': ( 'ipyleaflet.html#inspector.__init__',
'ee_jupyter/ipyleaflet.py'),
Expand Down
18 changes: 3 additions & 15 deletions ee_jupyter/core.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,18 @@
# AUTOGENERATED! DO NOT EDIT! File to edit: ../00_core.ipynb.

# %% auto 0
__all__ = ['colab_gee_setup']
__all__ = ['authenticate_if_needed']

# %% ../00_core.ipynb 5
def colab_gee_setup():
"""Setup Colab so it can use the earthengine-jupyter package.
def authenticate_if_needed():
"""Authenticate Earth Engine, if credentials do not exist.
* Install earthengine-jupyter package.
* Authenticate, if needed."""

import ee
import os

print('Verifying environment is setup for earthengine-jupyter...')

try:
import ee_jupyter
print('\N{check mark} The package earthengine-jupyter is already installed.')
except ModuleNotFoundError:
print('\N{check mark} Installing earthengine-jupyter...')
result = os.system('pip -q install earthengine-jupyter')

if os.path.exists(ee.oauth.get_credentials_path()):
print('\N{check mark} Authentication credentials were found.')
else:
ee.Authenticate()

print('\N{check mark} Done.')
49 changes: 35 additions & 14 deletions index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,35 @@
"**NOTICE: This is an experimental project and is not an officially supported Google project. You are welcome to use it, but we do not guarantee stability.**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Setup"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Make sure that the earthengine-jupyter package is installed...\n"
]
}
],
"source": [
"print('Make sure that the earthengine-jupyter package is installed...')\n",
"try:\n",
" import ee_jupyter\n",
"except ModuleNotFoundError:\n",
" import os\n",
" result = os.system('pip -q install earthengine-jupyter')"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -69,7 +98,7 @@
"outputs": [],
"source": [
"import ee\n",
"from ee_jupyter.core import colab_gee_setup\n",
"from ee_jupyter.core import authenticate_if_needed\n",
"from ee_jupyter.ipyleaflet import Map"
]
},
Expand All @@ -82,15 +111,12 @@
"name": "stdout",
"output_type": "stream",
"text": [
"Verifying environment is setup for earthengine-jupyter...\n",
"✓ The package earthengine-jupyter is already installed.\n",
"✓ Authentication credentials were found.\n",
"✓ Done.\n"
"✓ Authentication credentials were found.\n"
]
}
],
"source": [
"colab_gee_setup()"
"authenticate_if_needed()"
]
},
{
Expand All @@ -111,7 +137,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d878454fc87641d19f73cccd7eaaf025",
"model_id": "df4163a7f7184170a32cc03c965cd04f",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -166,7 +192,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "5746ef56f682462a89534aaa96969577",
"model_id": "d30267e4c6cf4dae9c4042049209f238",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -201,7 +227,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "9b76973a611d4684a21065935eea2859",
"model_id": "3b04e9f3577b4778a04a8abe00300ae8",
"version_major": 2,
"version_minor": 0
},
Expand Down Expand Up @@ -270,11 +296,6 @@
"\n",
"Image(url=url, format='png', embed=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": []
}
],
"metadata": {
Expand Down

0 comments on commit c18497d

Please sign in to comment.