Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wait to import httplib2 until paths to external libraries are added #114

Merged
merged 1 commit into from
Jun 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
import site
import pkg_resources
import builtins
import httplib2


def pre_init_plugin():
if platform.system() == "Windows":
extlib_path = 'extlibs_windows'
extlib_path = "extlibs_windows"
if platform.system() == "Darwin":
extlib_path = 'extlibs_darwin'
extlib_path = "extlibs_darwin"
if platform.system() == "Linux":
extlib_path = 'extlibs_linux'
extra_libs_path = os.path.abspath(os.path.join(os.path.dirname(__file__), extlib_path))
extlib_path = "extlibs_linux"
extra_libs_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), extlib_path)
)

# add to python path
site.addsitedir(extra_libs_path)
Expand All @@ -27,19 +28,25 @@ def import_ee():
purpose of initializing or starting ee authentication when the
user or the plugin import ee library.
"""
# we can now import the libraries
# Work around bug https://github.com/google/earthengine-api/issues/181
import httplib2

from ee_plugin.ee_auth import authenticate

def __wrapping_ee_import__(name, *args, **kwargs):
_module_ = __builtin_import__(name, *args, **kwargs)
if name == 'ee':
if name == "ee":
if not _module_.data._credentials:
try:
_module_.Initialize(http_transport=httplib2.Http())
except _module_.ee_exception.EEException:
if authenticate(ee=_module_):
_module_.Initialize(http_transport=httplib2.Http()) # retry initialization once the user logs in
_module_.Initialize(
http_transport=httplib2.Http()
) # retry initialization once the user logs in
else:
print('\nGoogle Earth Engine authorization failed!\n')
print("\nGoogle Earth Engine authorization failed!\n")

return _module_

Expand All @@ -63,4 +70,5 @@ def classFactory(iface): # pylint: disable=invalid-name

# start
from .ee_plugin import GoogleEarthEnginePlugin

return GoogleEarthEnginePlugin(iface)