Skip to content

Commit 44196fb

Browse files
committed
Addressing #420 (for CCI Toolbox)
1 parent e224598 commit 44196fb

File tree

5 files changed

+53
-14
lines changed

5 files changed

+53
-14
lines changed

CHANGES.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
## Changes in 0.7.1.dev1 (in development)
22

3+
* Slightly changed signature of `xcube.core.store.DataStore.get_dataset_ids()`
4+
by adding a new keyword argument `include_attrs: Sequence[str] = None` that
5+
can be used to obtain a minimum set of dataset attributes for each returned
6+
dataset identifier. However, `include_attrs` is ignored to far in the "s3",
7+
"memory", and "directory" data stores. (#420)
38
* Added `s3fs` requirement that has been removed by accident.
49
* Added missing requirements `requests` and `urllib3`.
510

xcube/core/store/store.py

+26-7
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# SOFTWARE.
2121

2222
from abc import abstractmethod, ABC
23-
from typing import Iterator, Tuple, Any, Optional, List, Type
23+
from typing import Iterator, Tuple, Any, Optional, List, Type, Sequence
2424

2525
from xcube.constants import EXTENSION_POINT_DATA_STORES
2626
from xcube.util.extension import Extension
@@ -153,7 +153,10 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
153153
"""
154154

155155
@abstractmethod
156-
def get_data_ids(self, type_specifier: str = None, include_titles: bool = True) -> \
156+
def get_data_ids(self,
157+
type_specifier: str = None,
158+
include_titles: bool = True,
159+
include_attrs: Sequence[str] = None) -> \
157160
Iterator[Tuple[str, Optional[str]]]:
158161
"""
159162
Get an iterator over the data resource identifiers for the given type *type_specifier*.
@@ -162,13 +165,29 @@ def get_data_ids(self, type_specifier: str = None, include_titles: bool = True)
162165
If a store implementation supports only a single data type, it should verify that *type_specifier*
163166
is either None or compatible with the supported data type.
164167
165-
The returned iterator items are 2-tuples of the form (*data_id*, *title*), where *data_id*
166-
is the actual data identifier and *title* is an optional, human-readable title for the data.
167-
If *include_titles* is false, the second item of the result tuple will be None.
168+
The returned iterator items are either 2-tuples of the form (*data_id*, *title*)
169+
or (*data_id*, *attrs*), where *data_id* is the actual data identifier:
168170
169-
:param type_specifier: If given, only data identifiers that are available as this type are returned. If this is
170-
omitted, all available data identifiers are returned.
171+
* The first form is returned if *include_titles* is given.
172+
Then *title* is an optional, human-readable title (of type ``str```) for the data.
173+
* The second form is returned if *include_attrs* is provided and not empty. and *attrs*.
174+
Then *attrs* is a possibly empty mapping (of type ``dict```) of attribute names to values
175+
with names given by *include_attrs*.
176+
177+
For data store backward compatibility, *include_titles* takes preference over *include_attrs*, so if
178+
*include_titles* is given (the default), a store should ignore *include_attrs*.
179+
Clients should however prefer ```include_attrs=["title", ...]``` over ```include_titles=True```.
180+
181+
If neither *include_titles* nor *include_attrs* is provided, the second item of the result tuple
182+
will be None.
183+
184+
:param type_specifier: If given, only data identifiers that are available as this type are returned.
185+
If this is omitted, all available data identifiers are returned.
171186
:param include_titles: If true, the store will attempt to also provide a title.
187+
In this case, the second tuple item is a ```str``` or None.
188+
:param include_attrs: A sequence of names of attributes to be returned for each dataset identifier.
189+
If given, the store will attempt to also provide the given set of dataset attributes.
190+
In this case, the second tuple item is a ```dict``` or None. (added in 0.7.1)
172191
:return: An iterator over the identifiers and titles of data resources provided by this data store.
173192
:raise DataStoreError: If an error occurs.
174193
"""

xcube/core/store/stores/directory.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
import os.path
2323
import uuid
24-
from typing import Optional, Iterator, Any, Tuple, List
24+
from typing import Optional, Iterator, Any, Tuple, List, Sequence
2525

2626
import geopandas as gpd
2727
import xarray as xr
@@ -116,8 +116,13 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
116116
actual_type_specifier, _, _ = self._get_accessor_id_parts(data_id)
117117
return actual_type_specifier,
118118

119-
def get_data_ids(self, type_specifier: str = None, include_titles: bool = True) -> \
119+
def get_data_ids(self,
120+
type_specifier: str = None,
121+
include_titles: bool = True,
122+
include_attrs: Sequence[str] = None) -> \
120123
Iterator[Tuple[str, Optional[str]]]:
124+
# TODO: do not ignore include_titles
125+
# TODO: do not ignore include_attrs
121126
if type_specifier is not None:
122127
type_specifier = TypeSpecifier.normalize(type_specifier)
123128
# TODO: Use os.walk(), which provides a generator rather than a list

xcube/core/store/stores/memory.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# SOFTWARE.
2121

2222
import uuid
23-
from typing import Iterator, Dict, Any, Optional, Tuple, Mapping
23+
from typing import Iterator, Dict, Any, Optional, Tuple, Mapping, Sequence
2424

2525
from xcube.core.store import DataDescriptor
2626
from xcube.core.store import DataStoreError
@@ -66,8 +66,13 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
6666
type_specifier = get_type_specifier(self._data_dict[data_id])
6767
return str(type_specifier),
6868

69-
def get_data_ids(self, type_specifier: str = None, include_titles: bool = True) -> Iterator[
70-
Tuple[str, Optional[str]]]:
69+
def get_data_ids(self,
70+
type_specifier: str = None,
71+
include_titles: bool = True,
72+
include_attrs: Sequence[str] = None) \
73+
-> Iterator[Tuple[str, Optional[str]]]:
74+
# TODO: do not ignore include_titles
75+
# TODO: do not ignore include_attrs
7176
if type_specifier is None:
7277
for data_id, data in self._data_dict.items():
7378
yield data_id, None

xcube/core/store/stores/s3.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,13 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
124124
data_type_specifier, _, _ = self._get_accessor_id_parts(data_id)
125125
return data_type_specifier,
126126

127-
def get_data_ids(self, type_specifier: str = None, include_titles=True) -> Iterator[Tuple[str, Optional[str]]]:
128-
# todo do not ignore type_specifier
127+
def get_data_ids(self,
128+
type_specifier: str = None,
129+
include_titles=True,
130+
include_attrs=None) -> Iterator[Tuple[str, Optional[str]]]:
131+
# TODO: do not ignore type_specifier
132+
# TODO: do not ignore include_titles
133+
# TODO: do not ignore include_attrs
129134
prefix = self._bucket_name + '/'
130135
first_index = len(prefix)
131136
for item in self._s3.listdir(self._bucket_name, detail=False):

0 commit comments

Comments
 (0)