ee-client 1.2.0__tar.gz → 1.2.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (24) hide show
  1. {ee_client-1.2.0 → ee_client-1.2.2}/PKG-INFO +1 -1
  2. {ee_client-1.2.0 → ee_client-1.2.2}/ee_client.egg-info/PKG-INFO +1 -1
  3. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/__init__.py +1 -1
  4. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/client.py +13 -4
  5. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/data.py +1 -1
  6. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/typing.py +5 -5
  7. {ee_client-1.2.0 → ee_client-1.2.2}/pyproject.toml +2 -2
  8. {ee_client-1.2.0 → ee_client-1.2.2}/tests/test_data.py +1 -1
  9. {ee_client-1.2.0 → ee_client-1.2.2}/tests/test_models.py +7 -0
  10. {ee_client-1.2.0 → ee_client-1.2.2}/LICENSE +0 -0
  11. {ee_client-1.2.0 → ee_client-1.2.2}/README.rst +0 -0
  12. {ee_client-1.2.0 → ee_client-1.2.2}/ee_client.egg-info/SOURCES.txt +0 -0
  13. {ee_client-1.2.0 → ee_client-1.2.2}/ee_client.egg-info/dependency_links.txt +0 -0
  14. {ee_client-1.2.0 → ee_client-1.2.2}/ee_client.egg-info/requires.txt +0 -0
  15. {ee_client-1.2.0 → ee_client-1.2.2}/ee_client.egg-info/top_level.txt +0 -0
  16. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/exceptions.py +0 -0
  17. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/export/image.py +0 -0
  18. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/export/table.py +0 -0
  19. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/helpers.py +0 -0
  20. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/logger.py +0 -0
  21. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/oauth_app.py +0 -0
  22. {ee_client-1.2.0 → ee_client-1.2.2}/eeclient/tasks.py +0 -0
  23. {ee_client-1.2.0 → ee_client-1.2.2}/setup.cfg +0 -0
  24. {ee_client-1.2.0 → ee_client-1.2.2}/tests/test_client.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ee-client
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: extends the capabilities of the earthengine-api by providing custom session management and client interactions
5
5
  Author-email: Daniel Guerrero <dfgm2006@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/dfguerrerom/ee-client
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: ee-client
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: extends the capabilities of the earthengine-api by providing custom session management and client interactions
5
5
  Author-email: Daniel Guerrero <dfgm2006@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/dfguerrerom/ee-client
@@ -1,6 +1,6 @@
1
1
  __title__ = "eeclient"
2
2
  __summary__ = "A client for Google Earth Engine"
3
- __version__ = "1.2.0"
3
+ __version__ = "1.2.2"
4
4
 
5
5
  __author__ = "Daniel Guerrero"
6
6
  __email__ = "dfgm2006@gmail.com"
@@ -65,11 +65,16 @@ class EESession:
65
65
  """Initialize credentials from the initial Google tokens"""
66
66
  _google_tokens = self.sepal_user_data.google_tokens
67
67
 
68
+ if not _google_tokens:
69
+ raise EEClientError("No google tokens found in the user data.")
70
+
68
71
  self.expiry_date = _google_tokens.access_token_expiry_date
69
72
  self.project_id = _google_tokens.project_id
70
73
  self._credentials = _google_tokens
71
74
 
72
- def get_assets_folder(self) -> str:
75
+ async def get_assets_folder(self) -> str:
76
+ if self.is_expired():
77
+ await self.set_credentials()
73
78
  return f"projects/{self.project_id}/assets/"
74
79
 
75
80
  def is_expired(self) -> bool:
@@ -81,6 +86,8 @@ class EESession:
81
86
  if not self._credentials:
82
87
  raise EEClientError("No credentials available")
83
88
 
89
+ logger.debug(f"Getting headers with project id: {self.project_id}")
90
+
84
91
  data = {
85
92
  "x-goog-user-project": self.project_id,
86
93
  "Authorization": f"Bearer {self._credentials.access_token}",
@@ -143,11 +150,11 @@ class EESession:
143
150
  self.expiry_date = self._credentials.access_token_expiry_date
144
151
  self.project_id = (
145
152
  self._credentials.project_id
146
- if not self.enforce_project_id
153
+ if self.enforce_project_id
147
154
  else self.project_id
148
155
  )
149
156
  logger.debug(
150
- f"Successfully refreshed credentials !{self._credentials}."
157
+ f"Successfully refreshed credentials !{self._credentials}==================. {self.project_id}"
151
158
  )
152
159
  return
153
160
  else:
@@ -180,7 +187,9 @@ class EESession:
180
187
  try:
181
188
  async with self.get_client() as client:
182
189
  url_with_project = self.set_url_project(url)
183
- logger.debug(f"Making async {method} request to {url_with_project}")
190
+ logger.debug(
191
+ f"Making async {method} request to {url_with_project} with data: {data}"
192
+ )
184
193
  response = await client.request(
185
194
  method, url_with_project, json=data, params=params
186
195
  )
@@ -211,7 +211,7 @@ async def create_folder(client: "EESession", folder: Union[Path, str]) -> str:
211
211
  if not folder or not folder.strip("/"):
212
212
  raise ValueError("Folder path cannot be empty")
213
213
 
214
- full_path = str(client.get_assets_folder() / Path(folder))
214
+ full_path = str(await client.get_assets_folder() / Path(folder))
215
215
 
216
216
  if asset := await get_asset(client, full_path):
217
217
  logger.debug(f"Folder already exists: {full_path}")
@@ -71,9 +71,8 @@ class GoogleTokens(BaseModel):
71
71
  class SepalUser(BaseModel):
72
72
  id: int
73
73
  username: str
74
- google_tokens: Optional[GoogleTokens] = (
75
- None # Make it optional so we can intercept missing data.
76
- )
74
+ # Make it optional to catch missing tokens
75
+ google_tokens: Optional[GoogleTokens] = None
77
76
  status: str
78
77
  roles: List[str]
79
78
  system_user: bool
@@ -86,8 +85,9 @@ class SepalUser(BaseModel):
86
85
 
87
86
  @model_validator(mode="before")
88
87
  def check_google_tokens_present(cls, values: dict) -> dict:
89
- # Check if the 'google_tokens' key is missing or None
90
- if not values.get("google_tokens"):
88
+ # Look for the token in both the field name and its alias
89
+ token_value = values.get("google_tokens") or values.get("googleTokens")
90
+ if not token_value:
91
91
  raise EEClientError(
92
92
  "Authentication required: Please authenticate via sepal. See https://docs.sepal.io/en/latest/setup/gee.html."
93
93
  )
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "ee-client"
7
- version = "1.2.0"
7
+ version = "1.2.2"
8
8
  description = "extends the capabilities of the earthengine-api by providing custom session management and client interactions"
9
9
  readme = { file = "README.rst", content-type = "text/x-rst" }
10
10
  authors = [
@@ -66,7 +66,7 @@ branch = true
66
66
  [tool.commitizen]
67
67
  tag_format = "v$major.$minor.$patch$prerelease"
68
68
  update_changelog_on_bump = false
69
- version = "1.2.0"
69
+ version = "1.2.2"
70
70
  version_files = [
71
71
  "pyproject.toml:version",
72
72
  "eeclient/__init__.py:__version__",
@@ -56,7 +56,7 @@ async def test_delete_asset(sepal_headers):
56
56
  sepal_session = EESession(sepal_headers=sepal_headers)
57
57
  await create_folder(sepal_session, folder="1/2/3/4/5/65/")
58
58
 
59
- folder_to_delete = str(Path(sepal_session.get_assets_folder()) / "1/")
59
+ folder_to_delete = str(Path(await sepal_session.get_assets_folder()) / "1/")
60
60
 
61
61
  with pytest.raises(EERestException) as excinfo:
62
62
  await delete_asset(sepal_session, asset_id=folder_to_delete)
@@ -15,11 +15,18 @@ def test_headers(dummy_headers):
15
15
  assert sepal_headers.cookies == {"SEPAL-SESSIONID": "s:random"}
16
16
  assert sepal_headers.sepal_user.id == 10001
17
17
  assert sepal_headers.sepal_user.username == "admin"
18
+ assert sepal_headers.sepal_user.google_tokens
18
19
  assert sepal_headers.sepal_user.google_tokens.access_token
19
20
  assert sepal_headers.sepal_user.google_tokens.refresh_token
20
21
  assert sepal_headers.sepal_user.google_tokens.project_id == "ee-project"
21
22
 
22
23
 
24
+ def test_headers_no_google_tokes(dummy_headers_no_google_tokens):
25
+
26
+ with pytest.raises(EEClientError):
27
+ SepalHeaders.model_validate(dummy_headers_no_google_tokens)
28
+
29
+
23
30
  def test_without_sepal_user(dummy_headers_no_project_id):
24
31
 
25
32
  with pytest.raises(EEClientError):
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes