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

cannot use geemap in my test suit #189

Closed
12rambau opened this issue Dec 2, 2020 · 4 comments
Closed

cannot use geemap in my test suit #189

12rambau opened this issue Dec 2, 2020 · 4 comments

Comments

@12rambau
Copy link
Member

12rambau commented Dec 2, 2020

I am building a lib (https://github.com/12rambau/sepal_ui) that offer the jupyter notebook a dashboard interface. I decided 6 month ago that geemap was the best tool to deal with local and GEE mapping.

I'm starting the very boring but essential testing moment and I'm bumping into a lot of problem with the GEE authentification.

I created a function to initialize ee in the user env and the test env :

def init_ee():
    """Initialize earth engine according to the environment"""
    
    # only do the initialization if the credential are missing
    if not ee.data._credentials:
        
        # if in test env use the private key
        if 'EE_PRIVATE_KEY' in os.environ:
            
            # key need to be decoded in a file
            content = base64.b64decode(os.environ['EE_PRIVATE_KEY']).decode()
            with open('ee_private_key.json', 'w') as f:
                f.write(content)
    
            # connection to the service account
            service_account = 'test-sepal-ui@sepal-ui.iam.gserviceaccount.com'
            credentials = ee.ServiceAccountCredentials(service_account, 'ee_private_key.json')
            ee.Initialize(credentials)
        
        # if in local env use the local user credential
        else:
            ee.Initialize()
            
    return 0

But when I try to instanciate a geemap.Map()

google is asking me to authenticate (which is not possible in the travis build).

It seems that I'm stuck here : https://github.com/giswqs/geemap/blob/0af4b82e19e6355bac6c0e068f890f707b5bbea5/geemap/common.py#L47

would it be possible to only launch the init in ee_initialize if the credentials are missing ?

def ee_initialize(token_name='EARTHENGINE_TOKEN'):
    """Authenticates Earth Engine and initialize an Earth Engine session
    """
    
    # only do the initialization if the credential are missing
    if not ee.data._credentials:
        try:
            ee_token = os.environ.get(token_name)
            if ee_token is not None:
                credential = '{"refresh_token":"%s"}' % ee_token
                credential_file_path = os.path.expanduser("~/.config/earthengine/")
                os.makedirs(credential_file_path, exist_ok=True)
                with open(credential_file_path + 'credentials', 'w') as file:
                    file.write(credential)
            elif in_colab_shell():
                if credentials_in_drive() and (not credentials_in_colab()):
                    copy_credentials_to_colab()
                elif not credentials_in_colab:
                    ee.Authenticate()
                    if is_drive_mounted() and (not credentials_in_drive()):
                        copy_credentials_to_drive()
                else:
                    if is_drive_mounted():
                        copy_credentials_to_drive()

            ee.Initialize()
        except:
            ee.Authenticate()
            ee.Initialize()

    out_dir = os.path.join(os.path.expanduser('~'), 'Downloads')
    if not os.path.exists(out_dir):
        os.makedirs(out_dir)
@giswqs
Copy link
Member

giswqs commented Dec 2, 2020

Good suggestion. I have incorporated your suggestion into the latest commit. Feel free to reopen this issue if the problem persists. Thanks.

@giswqs giswqs closed this as completed Dec 2, 2020
@12rambau
Copy link
Member Author

12rambau commented Dec 2, 2020

As always your reactivity is amazing. Do you plan on releasing a new version integrating these modifications soon ?

@giswqs
Copy link
Member

giswqs commented Dec 2, 2020

Yes, I will release a new version in a few hours. Stay tuned

@giswqs
Copy link
Member

giswqs commented Dec 2, 2020

v0.8.3 has been released. Note that conda-forge might take a couple of hours to build, which I have no control.

image image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants