freva-client 2509.1.0__tar.gz → 2509.2.0__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.

Potentially problematic release.


This version of freva-client might be problematic. Click here for more details.

Files changed (20) hide show
  1. {freva_client-2509.1.0 → freva_client-2509.2.0}/PKG-INFO +1 -1
  2. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/__init__.py +1 -1
  3. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/utils/databrowser_utils.py +44 -33
  4. {freva_client-2509.1.0 → freva_client-2509.2.0}/MANIFEST.in +0 -0
  5. {freva_client-2509.1.0 → freva_client-2509.2.0}/README.md +0 -0
  6. {freva_client-2509.1.0 → freva_client-2509.2.0}/assets/share/freva/freva.toml +0 -0
  7. {freva_client-2509.1.0 → freva_client-2509.2.0}/pyproject.toml +0 -0
  8. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/__main__.py +0 -0
  9. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/auth.py +0 -0
  10. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/__init__.py +0 -0
  11. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/auth_cli.py +0 -0
  12. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/cli_app.py +0 -0
  13. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/cli_parser.py +0 -0
  14. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/cli_utils.py +0 -0
  15. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/cli/databrowser_cli.py +0 -0
  16. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/py.typed +0 -0
  17. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/query.py +0 -0
  18. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/utils/__init__.py +0 -0
  19. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/utils/auth_utils.py +0 -0
  20. {freva_client-2509.1.0 → freva_client-2509.2.0}/src/freva_client/utils/logger.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: freva-client
3
- Version: 2509.1.0
3
+ Version: 2509.2.0
4
4
  Summary: Search for climate data based on key-value pairs
5
5
  Author-email: "DKRZ, Clint" <freva@dkrz.de>
6
6
  Requires-Python: >=3.8
@@ -18,5 +18,5 @@ official documentation: https://freva-org.github.io/freva-legacy
18
18
  from .auth import authenticate
19
19
  from .query import databrowser
20
20
 
21
- __version__ = "2509.1.0"
21
+ __version__ = "2509.2.0"
22
22
  __all__ = ["authenticate", "databrowser", "__version__"]
@@ -42,11 +42,18 @@ class Config:
42
42
  uniq_key: Literal["file", "uri"] = "file",
43
43
  flavour: Optional[str] = None,
44
44
  ) -> None:
45
- self.databrowser_url = f"{self.get_api_url(host)}/databrowser"
46
- self.auth_url = f"{self.get_api_url(host)}/auth/v2"
47
- self.get_api_main_url = self.get_api_url(host)
45
+ config_host = host or cast(str, self._get_databrowser_param_from_config("host"))
46
+
47
+ self.databrowser_url = f"{self.get_api_url(config_host)}/databrowser"
48
+ self.auth_url = f"{self.get_api_url(config_host)}/auth/v2"
49
+ self.get_api_main_url = self.get_api_url(config_host)
48
50
  self.uniq_key = uniq_key
49
- self.flavour = self.get_flavour(flavour)
51
+ self._flavour = (
52
+ flavour or self._get_databrowser_param_from_config(
53
+ "flavour",
54
+ optional=True
55
+ )
56
+ )
50
57
 
51
58
  @cached_property
52
59
  def validate_server(self) -> bool:
@@ -59,18 +66,17 @@ class Config:
59
66
  f"Could not connect to {self.databrowser_url}: {e}"
60
67
  ) from None
61
68
 
62
- def get_flavour(self, flavour: Optional[str]) -> str:
63
- """Get the current flavour."""
64
- if flavour:
65
- return flavour
66
- else:
67
- try:
68
- config_flavour = self._get_databrowser_params_from_config().get(
69
- "flavour", ""
70
- )
71
- return config_flavour or "freva"
72
- except ValueError:
73
- return "freva"
69
+ @property
70
+ def flavour(self) -> str:
71
+ """Get the flavour, using server default if not configured."""
72
+ if self._flavour:
73
+ return self._flavour
74
+ try:
75
+ flavours = self.overview.get("flavours", [])
76
+ self._flavour = flavours[0] if flavours else "freva"
77
+ except (ValueError, IndexError, KeyError):
78
+ self._flavour = "freva"
79
+ return self._flavour
74
80
 
75
81
  def _read_ini(self, path: Path) -> Dict[str, str]:
76
82
  """Read an ini file.
@@ -115,8 +121,11 @@ class Config:
115
121
  """
116
122
  try:
117
123
  config = tomli.loads(path.read_text()).get("freva", {})
118
- scheme, host = self._split_url(cast(str, config.get("host", "")))
124
+ raw_host = cast(str, config.get("host", ""))
119
125
  flavour = config.get("default_flavour", "")
126
+ if not raw_host:
127
+ return {"host": "", "flavour": flavour}
128
+ scheme, host = self._split_url(raw_host)
120
129
  except (tomli.TOMLDecodeError, KeyError):
121
130
  return {}
122
131
  host, _, port = host.partition(":")
@@ -186,9 +195,10 @@ class Config:
186
195
  f"Could not connect to {self.databrowser_url}"
187
196
  ) from None
188
197
 
189
- def _get_databrowser_params_from_config(self) -> Dict[str, str]:
190
- """Get the config file order."""
191
-
198
+ def _get_databrowser_param_from_config(
199
+ self, key: str, optional: bool = False
200
+ ) -> Optional[str]:
201
+ """Get a single config parameter following proper precedence."""
192
202
  eval_conf = self.get_dirs(user=False) / "evaluation_system.conf"
193
203
  freva_config = Path(
194
204
  os.environ.get("FREVA_CONFIG")
@@ -202,20 +212,22 @@ class Config:
202
212
  os.environ.get("EVALUATION_SYSTEM_CONFIG_FILE") or eval_conf
203
213
  ): "ini",
204
214
  }
215
+
205
216
  for config_path, config_type in paths.items():
206
217
  if config_path.is_file():
207
218
  config_data = self._read_config(config_path, config_type)
208
- host = config_data.get("host", "")
209
- flavour = config_data.get("flavour", "")
210
- if host:
211
- return {
212
- "host": host,
213
- "flavour": flavour
214
- }
219
+ value = config_data.get(key, "")
220
+ # we cannot igonore the empty string here, because
221
+ # it needs to check the next config file
222
+ if value:
223
+ return value if value else None
224
+ if optional:
225
+ return None
226
+
215
227
  raise ValueError(
216
- "No databrowser host configured, please use a"
217
- " configuration defining a databrowser host or"
218
- " set a host name using the `host` key"
228
+ f"No databrowser {key} configured, please use a"
229
+ f" configuration defining a databrowser {key} or"
230
+ f" set a host name using the `{key}` key"
219
231
  )
220
232
 
221
233
  @property
@@ -257,9 +269,8 @@ class Config:
257
269
  scheme = scheme or "http"
258
270
  return scheme, hostname
259
271
 
260
- def get_api_url(self, url: Optional[str]) -> str:
272
+ def get_api_url(self, url: str) -> str:
261
273
  """Construct the databrowser url from a given hostname."""
262
- url = url or self._get_databrowser_params_from_config().get("host", "")
263
274
  scheme, hostname = self._split_url(url)
264
275
  hostname, _, port = hostname.partition(":")
265
276
  if port:
@@ -385,7 +396,7 @@ class UserDataHandler:
385
396
  ) -> None:
386
397
  for data in validated_userdata:
387
398
  metadata = self._get_metadata(data)
388
- if isinstance(metadata, Exception) or metadata == {}:
399
+ if metadata == {}:
389
400
  logger.warning("Error getting metadata: %s", metadata)
390
401
  else:
391
402
  self.user_metadata.append(metadata)