Skip to content

Commit

Permalink
v0.1.389
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 603356358
  • Loading branch information
Google Earth Engine Authors authored and schwehr committed Feb 8, 2024
1 parent cdfe00b commit b5cde4e
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 225 deletions.
32 changes: 16 additions & 16 deletions javascript/build/ee_api_js.js

Large diffs are not rendered by default.

128 changes: 64 additions & 64 deletions javascript/build/ee_api_js_debug.js

Large diffs are not rendered by default.

172 changes: 86 additions & 86 deletions javascript/build/ee_api_js_npm.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion javascript/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@google/earthengine",
"version": "0.1.388",
"version": "0.1.389",
"description": "JavaScript client for Google Earth Engine API.",
"author": "Google LLC",
"license": "Apache-2.0",
Expand Down
2 changes: 1 addition & 1 deletion javascript/src/apiclient.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const {trustedResourceUrl} = goog.require('safevalues');
/** @namespace */
const apiclient = {};

const API_CLIENT_VERSION = '0.1.388';
const API_CLIENT_VERSION = '0.1.389';

exports.VERSION = apiVersion.VERSION;
exports.API_CLIENT_VERSION = API_CLIENT_VERSION;
Expand Down
23 changes: 17 additions & 6 deletions python/ee/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""The EE Python library."""

__version__ = '0.1.388'
__version__ = '0.1.389'

# Using lowercase function naming to match the JavaScript names.
# pylint: disable=g-bad-name
Expand All @@ -9,6 +9,7 @@
import datetime
import inspect
import os
import re
from typing import Any, Hashable, List as ListType, Optional, Sequence, Tuple, Type, Union

from ee import _utils
Expand Down Expand Up @@ -61,6 +62,9 @@
# A list of autogenerated class names added by _InitializeGenerateClasses.
_generatedClasses: ListType[str] = []

NO_PROJECT_EXCEPTION = ('ee.Initialize: no project found. Call with project='
' or see http://goo.gle/ee-auth.')


class _AlgorithmsContainer(dict):
"""A lightweight class that is used as a dictionary with dot notation."""
Expand Down Expand Up @@ -148,10 +152,7 @@ def Initialize(
project = credentials.quota_project_id
# SDK credentials are not authorized for EE so a project must be given.
if not project and oauth.is_sdk_credentials(credentials):
raise EEException(
'ee.Initialize: no project found. '
'Call with project= or see Earth Engine Authentication docs.'
)
raise EEException(NO_PROJECT_EXCEPTION)

data.initialize(
credentials=credentials,
Expand All @@ -164,7 +165,17 @@ def Initialize(
)

# Initialize the dynamically loaded functions on the objects that want them.
ApiFunction.initialize()
try:
ApiFunction.initialize()
except EEException as e:
# We tried to detect missing projects before initialization, but some cases
# like Colab hide the project, so check errors from missing projects too.
adc_err = 'authenticating by using local Application Default Credentials'
api_err = 'Earth Engine API has not been used in project ([0-9]+) before'
matches = re.search(api_err, str(e))
if (adc_err in str(e)) or (matches and oauth.is_sdk_project(matches[1])):
raise EEException(NO_PROJECT_EXCEPTION) from None
raise e
Array.initialize()
Blob.initialize()
Collection.initialize()
Expand Down
8 changes: 2 additions & 6 deletions python/ee/cli/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,9 +432,7 @@ def run(
config = {}

config['project'] = args.project
# Existing file permissions will be left unchanged if file already exists.
with open(config_path, 'w') as json_config_file:
json.dump(config, json_config_file)
ee.oauth.write_private_json(config_path, config)
print('Successfully saved project id')


Expand Down Expand Up @@ -462,9 +460,7 @@ def run(

if 'project' in config:
del config['project']
# Existing file permissions will be left unchanged if file already exists.
with open(config_path, 'w') as json_config_file:
json.dump(config, json_config_file)
ee.oauth.write_private_json(config_path, config)
print('Successfully unset project id')


Expand Down
10 changes: 9 additions & 1 deletion python/ee/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import threading
from typing import Any, Callable, Dict, Iterator, List, Optional, Sequence, Union
import uuid
import warnings

import google.auth
# Rename to avoid redefined-outer-name warning.
Expand Down Expand Up @@ -251,14 +252,21 @@ def get_persistent_credentials() -> credentials_lib.Credentials:
args = oauth.get_credentials_arguments()
except IOError:
pass

if args.get('refresh_token'):
credentials = credentials_lib.Credentials(None, **args)
else:
# If EE credentials aren't available, try application default credentials.
try:
credentials, unused_project_id = google.auth.default()
with warnings.catch_warnings():
# _default.py gives incorrect advice here: gcloud config set project
# sets the default resource project but we need the quota project.
warnings.filterwarnings('ignore', '.*(No project ID|quota project).*')

credentials, unused_project_id = google.auth.default()
except google.auth.exceptions.DefaultCredentialsError:
pass

if credentials:
# earthengine set_project always overrides gcloud set-quota-project
project = args.get('quota_project_id') or oauth.get_appdefault_project()
Expand Down
6 changes: 5 additions & 1 deletion python/ee/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ def get_credentials_arguments() -> Dict[str, Any]:

def is_sdk_credentials(credentials: Optional[Any]) -> bool:
client = (credentials and getattr(credentials, 'client_id', None)) or ''
return client.split('-')[0] in SDK_PROJECTS
return is_sdk_project(client.split('-')[0])


def is_sdk_project(project: str) -> bool:
return project in SDK_PROJECTS


def get_appdefault_project() -> Optional[str]:
Expand Down
2 changes: 1 addition & 1 deletion python/ee/tests/_cloud_api_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def setUp(self):

def test_build_cloud_resource(self):
base = 'https://earthengine.basetest'
path = '$discovery/rest?version=v1&labels=GOOGLE_INTERNAL&prettyPrint=false'
path = '$discovery/rest?version=v1&prettyPrint=false'
def check_build(api, unused_version, **kwargs):
self.assertEqual('earthengine', api)
self.assertEqual(base + '/' + path, kwargs.get('discoveryServiceUrl'))
Expand Down
41 changes: 0 additions & 41 deletions python/ee/tests/ee_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,47 +53,6 @@ def MockAlgorithms():
self.assertEqual(ee.ApiFunction._api, {})
self.assertFalse(ee.Image._initialized)

def testProjectInitialization(self):
"""Verifies that we can fetch the client project from many locations.
This also exercises the logic in data.get_persistent_credentials.
"""

cred_args = dict(refresh_token='rt', quota_project_id='qp1')
google_creds = credentials.Credentials(token=None, quota_project_id='qp2')
expected_project = None

def CheckDataInit(**kwargs):
self.assertEqual(expected_project, kwargs.get('project'))

moc = mock.patch.object
with (moc(ee.oauth, 'get_credentials_arguments', new=lambda: cred_args),
moc(google.auth, 'default', new=lambda: (google_creds, None)),
moc(ee.data, 'initialize', side_effect=CheckDataInit) as inits):
expected_project = 'qp0'
ee.Initialize(project='qp0')

expected_project = 'qp1'
ee.Initialize()

cred_args['refresh_token'] = None
ee.Initialize()

cred_args['quota_project_id'] = None
expected_project = 'qp2'
ee.Initialize()

google_creds = google_creds.with_quota_project(None)
expected_project = None
ee.Initialize()
self.assertEqual(5, inits.call_count)

cred_args['client_id'] = '764086051850-xxx' # dummy usable-auth client
cred_args['refresh_token'] = 'rt'
with self.assertRaisesRegex(ee.EEException, '.*no project found..*'):
ee.Initialize()
self.assertEqual(5, inits.call_count)

def testCallAndApply(self):
"""Verifies library initialization."""

Expand Down
2 changes: 1 addition & 1 deletion python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "earthengine-api"
version = "0.1.388"
version = "0.1.389"
description = "Earth Engine Python API"
requires-python = ">=3.7"
keywords = [
Expand Down

0 comments on commit b5cde4e

Please sign in to comment.