diff --git a/CHANGES.md b/CHANGES.md index 0eaf10d..b329dc8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,3 +1,8 @@ +## Changes in 0.8.0 (in development) + +* Provided xcube data store framework interface compatibility with + breaking changes in xcube 0.8.0 (see https://github.com/dcs4cop/xcube/issues/420). + ## Changes in 0.7.0 - Replace Travis CI with AppVeyor for CI (closes #25) diff --git a/environment.yml b/environment.yml index 2e62a41..c7d7a78 100644 --- a/environment.yml +++ b/environment.yml @@ -8,4 +8,4 @@ dependencies: - numpy >=1.17 - python-dateutil >=2.8.1 - xarray >=0.14.1 - - xcube >=0.7.0 + - xcube >=0.8.0 diff --git a/test/test_store.py b/test/test_store.py index d8fdeb5..7d312a9 100644 --- a/test/test_store.py +++ b/test/test_store.py @@ -80,13 +80,13 @@ def test_invalid_data_id(self): def test_list_and_describe_data_ids(self): store = CDSDataStore(endpoint_url=_CDS_API_URL, cds_api_key=_CDS_API_KEY) - data_ids = store.get_data_ids() + data_ids = store.get_data_ids(include_attrs=['title']) self.assertIsInstance(data_ids, Iterator) for data_id in data_ids: self.assertIsInstance(data_id, tuple) self.assertTrue(1 <= len(data_id) <= 2) - for element in data_id: - self.assertIsInstance(element, str) + self.assertIsInstance(data_id[0], str) + self.assertIsInstance(data_id[1], dict) descriptor = store.describe_data(data_id[0]) self.assertIsInstance(descriptor, DataDescriptor) diff --git a/xcube_cds/store.py b/xcube_cds/store.py index 7697fda..9ad800c 100644 --- a/xcube_cds/store.py +++ b/xcube_cds/store.py @@ -29,7 +29,7 @@ import tempfile from abc import ABC from abc import abstractmethod -from typing import Any +from typing import Any, Container from typing import Dict from typing import Iterator from typing import List @@ -316,8 +316,7 @@ def __init__(self, normalize_names: Optional[bool] = False, client_class=cdsapi.Client, endpoint_url=None, - cds_api_key=None - ): + cds_api_key=None): """Instantiate a CDS data opener. :param normalize_names: if True, all variable names in the returned @@ -330,7 +329,7 @@ def __init__(self, :param endpoint_url: CDS API URL. Will be passed to the CDS API client. If omitted, the client will read the value from an environment variable or configuration file. - :param cds_api_url: CDS API key. Will be passed to the CDS API client. + :param cds_api_key: CDS API key. Will be passed to the CDS API client. If omitted, the client will read the value from an environment variable or configuration file. """ @@ -759,17 +758,23 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]: return TYPE_SPECIFIER_CUBE, def get_data_ids(self, type_specifier: Optional[str] = None, - include_titles: bool = True) \ - -> Iterator[Tuple[str, Optional[str]]]: - if not self._is_type_specifier_satisfied(type_specifier): - # If the type specifier isn't compatible, return an empty iterator. - return iter(()) - return iter( - (data_id, - self._handler_registry[data_id]. - get_human_readable_data_id(data_id) if include_titles else None) - for data_id in self._handler_registry - ) + include_attrs: Container[str] = None) -> \ + Union[Iterator[str], Iterator[Tuple[str, Dict[str, Any]]]]: + + if self._is_type_specifier_satisfied(type_specifier): + # Only if the type specifier isn't compatible + return_tuples = include_attrs is not None + # TODO: respect names other than "title" in include_attrs + include_titles = return_tuples and 'title' in include_attrs + + for data_id, handler in self._handler_registry.items(): + if return_tuples: + if include_titles: + yield data_id, {'title': handler.get_human_readable_data_id(data_id)} + else: + yield data_id, {} + else: + yield data_id def has_data(self, data_id: str, type_specifier: Optional[str] = None) \ -> bool: diff --git a/xcube_cds/version.py b/xcube_cds/version.py index cfc9b73..129ca61 100644 --- a/xcube_cds/version.py +++ b/xcube_cds/version.py @@ -20,4 +20,4 @@ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. -version = '0.7.0' +version = '0.8.0.dev0'