Skip to content

Commit

Permalink
Merge pull request #44 from dcs4cop/forman-420-include_attrs
Browse files Browse the repository at this point in the history
Addressing #420 (for CCI Toolbox).
  • Loading branch information
pont-us authored Apr 9, 2021
2 parents 24ec11b + fd03e05 commit 853eebc
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 20 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 3 additions & 3 deletions test/test_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
35 changes: 20 additions & 15 deletions xcube_cds/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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.
"""
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion xcube_cds/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'

0 comments on commit 853eebc

Please sign in to comment.