Skip to content

Commit 853eebc

Browse files
authored
Merge pull request #44 from dcs4cop/forman-420-include_attrs
Addressing #420 (for CCI Toolbox).
2 parents 24ec11b + fd03e05 commit 853eebc

File tree

5 files changed

+30
-20
lines changed

5 files changed

+30
-20
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## Changes in 0.8.0 (in development)
2+
3+
* Provided xcube data store framework interface compatibility with
4+
breaking changes in xcube 0.8.0 (see https://github.com/dcs4cop/xcube/issues/420).
5+
16
## Changes in 0.7.0
27

38
- Replace Travis CI with AppVeyor for CI (closes #25)

environment.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ dependencies:
88
- numpy >=1.17
99
- python-dateutil >=2.8.1
1010
- xarray >=0.14.1
11-
- xcube >=0.7.0
11+
- xcube >=0.8.0

test/test_store.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ def test_invalid_data_id(self):
8080
def test_list_and_describe_data_ids(self):
8181
store = CDSDataStore(endpoint_url=_CDS_API_URL,
8282
cds_api_key=_CDS_API_KEY)
83-
data_ids = store.get_data_ids()
83+
data_ids = store.get_data_ids(include_attrs=['title'])
8484
self.assertIsInstance(data_ids, Iterator)
8585
for data_id in data_ids:
8686
self.assertIsInstance(data_id, tuple)
8787
self.assertTrue(1 <= len(data_id) <= 2)
88-
for element in data_id:
89-
self.assertIsInstance(element, str)
88+
self.assertIsInstance(data_id[0], str)
89+
self.assertIsInstance(data_id[1], dict)
9090
descriptor = store.describe_data(data_id[0])
9191
self.assertIsInstance(descriptor, DataDescriptor)
9292

xcube_cds/store.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import tempfile
3030
from abc import ABC
3131
from abc import abstractmethod
32-
from typing import Any
32+
from typing import Any, Container
3333
from typing import Dict
3434
from typing import Iterator
3535
from typing import List
@@ -316,8 +316,7 @@ def __init__(self,
316316
normalize_names: Optional[bool] = False,
317317
client_class=cdsapi.Client,
318318
endpoint_url=None,
319-
cds_api_key=None
320-
):
319+
cds_api_key=None):
321320
"""Instantiate a CDS data opener.
322321
323322
:param normalize_names: if True, all variable names in the returned
@@ -330,7 +329,7 @@ def __init__(self,
330329
:param endpoint_url: CDS API URL. Will be passed to the CDS API client.
331330
If omitted, the client will read the value from an environment
332331
variable or configuration file.
333-
:param cds_api_url: CDS API key. Will be passed to the CDS API client.
332+
:param cds_api_key: CDS API key. Will be passed to the CDS API client.
334333
If omitted, the client will read the value from an environment
335334
variable or configuration file.
336335
"""
@@ -759,17 +758,23 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
759758
return TYPE_SPECIFIER_CUBE,
760759

761760
def get_data_ids(self, type_specifier: Optional[str] = None,
762-
include_titles: bool = True) \
763-
-> Iterator[Tuple[str, Optional[str]]]:
764-
if not self._is_type_specifier_satisfied(type_specifier):
765-
# If the type specifier isn't compatible, return an empty iterator.
766-
return iter(())
767-
return iter(
768-
(data_id,
769-
self._handler_registry[data_id].
770-
get_human_readable_data_id(data_id) if include_titles else None)
771-
for data_id in self._handler_registry
772-
)
761+
include_attrs: Container[str] = None) -> \
762+
Union[Iterator[str], Iterator[Tuple[str, Dict[str, Any]]]]:
763+
764+
if self._is_type_specifier_satisfied(type_specifier):
765+
# Only if the type specifier isn't compatible
766+
return_tuples = include_attrs is not None
767+
# TODO: respect names other than "title" in include_attrs
768+
include_titles = return_tuples and 'title' in include_attrs
769+
770+
for data_id, handler in self._handler_registry.items():
771+
if return_tuples:
772+
if include_titles:
773+
yield data_id, {'title': handler.get_human_readable_data_id(data_id)}
774+
else:
775+
yield data_id, {}
776+
else:
777+
yield data_id
773778

774779
def has_data(self, data_id: str, type_specifier: Optional[str] = None) \
775780
-> bool:

xcube_cds/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
version = '0.7.0'
23+
version = '0.8.0.dev0'

0 commit comments

Comments
 (0)