Skip to content

Commit d96967e

Browse files
committed
Merge remote-tracking branch 'origin/main'
# Conflicts: # CHANGES.md
2 parents 0b187a3 + 56f1c06 commit d96967e

File tree

7 files changed

+43
-19
lines changed

7 files changed

+43
-19
lines changed

CHANGES.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@
1212

1313
### Other changes
1414

15+
* Added a new abstract class `PreloadedDataStore` that defines the return type of the
16+
`preload_data` method in `xcube.core.store.DataStore`. The `PreloadedDataStore` is a
17+
data store containing a `preload_handle` field, which holds the handle
18+
associated with a preload job.
19+
1520
* Renamed [xrlint]() config file from `xrlint_config.yaml` to `xrlint-config.yaml`.
1621

1722
## Changes in 1.8.3

test/core/store/test_store.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
import pytest
88
from fsspec.registry import register_implementation
99

10-
from xcube.core.store import DataStoreError, list_data_store_ids, new_data_store
10+
from xcube.core.store import (
11+
DataStoreError,
12+
PreloadedDataStore,
13+
list_data_store_ids,
14+
new_data_store,
15+
)
16+
from xcube.core.store.preload import NullPreloadHandle
1117

1218

1319
class ListDataStoreTest(unittest.TestCase):
@@ -84,6 +90,12 @@ def test_has_data(self, mock_filesystem):
8490
self.assertEqual(mock_http_fs.exists.call_count, 3)
8591
self.assertFalse(res)
8692

93+
def test_preload_data(self):
94+
store = new_data_store("file")
95+
store_test = store.preload_data()
96+
self.assertTrue(hasattr(store_test, "preload_handle"))
97+
self.assertIsInstance(store_test.preload_handle, NullPreloadHandle)
98+
8799

88100
def test_fsspec_instantiation_error():
89101
error_string = "deliberate instantiation error for testing"

xcube/core/store/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from .store import (
3939
DataStore,
4040
MutableDataStore,
41+
PreloadedDataStore,
4142
find_data_store_extensions,
4243
get_data_store_class,
4344
get_data_store_params_schema,

xcube/core/store/preload.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,7 @@ def __repr__(self):
7575

7676

7777
class PreloadHandle(ABC):
78-
"""A handle for a preload job.
79-
80-
Instances of this class are returned by the
81-
``DataStore.preload_data()`` method.
82-
"""
78+
"""A handle for a preload job."""
8379

8480
@abstractmethod
8581
def get_state(self, data_id: str) -> PreloadState:

xcube/core/store/store.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def new_data_store(
2828
data_store_id: str,
2929
extension_registry: Optional[ExtensionRegistry] = None,
3030
**data_store_params,
31-
) -> Union["DataStore", "MutableDataStore"]:
31+
) -> Union["DataStore", "MutableDataStore", "PreloadDataStore"]:
3232
"""Create a new data store instance for given
3333
*data_store_id* and *data_store_params*.
3434
@@ -487,7 +487,7 @@ def preload_data(
487487
self,
488488
*data_ids: str,
489489
**preload_params: Any,
490-
) -> PreloadHandle:
490+
) -> "PreloadedDataStore":
491491
"""Preload the given data items for faster access.
492492
493493
Warning: This is an experimental and potentially unstable API
@@ -509,12 +509,11 @@ def preload_data(
509509
on the possible options.
510510
511511
Returns:
512-
A handle for the preload process. The default implementation
513-
returns an empty preload handle.
512+
A mutable data store containing the preload handle.
513+
The default implementation contains an empty preload handle.
514514
"""
515-
return NullPreloadHandle()
516-
517-
# noinspection PyMethodMayBeStatic
515+
self.preload_handle = NullPreloadHandle()
516+
return self
518517

519518

520519
class MutableDataStore(DataStore, DataWriter, ABC):
@@ -690,3 +689,18 @@ def deregister_data(self, data_id: str):
690689
Raises:
691690
DataStoreError: If an error occurs.
692691
"""
692+
693+
694+
class PreloadedDataStore(DataStore):
695+
"""A preload data store is a multable data store which contains the preload handle.
696+
697+
Instances of this class are returned by the ``DataStore.preload_data()`` method.
698+
"""
699+
700+
@property
701+
@abstractmethod
702+
def preload_handle(self) -> PreloadHandle:
703+
"""The preload handle that can be used to observe the preload progress.
704+
Implementors of this interface may use a `ExecutorPreloadHandle` or consider
705+
returning a `NullPreloadHandle` if the progress is not observable.
706+
"""

xcube/util/cache.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,7 @@ def _compute_object_size(obj):
439439
else (
440440
3
441441
if m in ("RGB", "YCbCr", "LAB", "HSV")
442-
else 1.0 / 8.0
443-
if m == "1"
444-
else 1
442+
else 1.0 / 8.0 if m == "1" else 1
445443
)
446444
)
447445
)

xcube/util/dask.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,7 @@ def new_cluster(
218218
cluster_account = (
219219
account
220220
if account is not None
221-
else account_from_env_var
222-
if account_from_env_var is not None
223-
else "bc"
221+
else account_from_env_var if account_from_env_var is not None else "bc"
224222
)
225223

226224
if provider == "coiled":

0 commit comments

Comments
 (0)