Skip to content

Commit 23dae3d

Browse files
committed
chore: Reorganize import structure to align with compatibility expectations (#374)
1 parent 750d273 commit 23dae3d

25 files changed

+859
-873
lines changed

contract-tests/client_entity.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
Stage
1616
)
1717
from ldclient.config import BigSegmentsConfig
18-
from ldclient.impl.datasourcev2.polling import PollingDataSourceBuilder
19-
from ldclient.impl.datasystem.config import (
18+
from ldclient.datasystem import (
2019
custom,
20+
fdv1_fallback_ds_builder,
2121
polling_ds_builder,
2222
streaming_ds_builder
2323
)
24+
from ldclient.impl.datasourcev2.polling import PollingDataSourceBuilder
2425

2526

2627
class ClientEntity:
@@ -59,6 +60,7 @@ def __init__(self, tag, config):
5960

6061
primary_builder = None
6162
secondary_builder = None
63+
fallback_builder = None
6264

6365
if primary is not None:
6466
streaming = primary.get('streaming')
@@ -74,6 +76,7 @@ def __init__(self, tag, config):
7476
opts["base_uri"] = polling["baseUri"]
7577
_set_optional_time_prop(polling, "pollIntervalMs", opts, "poll_interval")
7678
primary_builder = polling_ds_builder()
79+
fallback_builder = fdv1_fallback_ds_builder()
7780

7881
if secondary is not None:
7982
streaming = secondary.get('streaming')
@@ -89,9 +92,12 @@ def __init__(self, tag, config):
8992
opts["base_uri"] = polling["baseUri"]
9093
_set_optional_time_prop(polling, "pollIntervalMs", opts, "poll_interval")
9194
secondary_builder = polling_ds_builder()
95+
fallback_builder = fdv1_fallback_ds_builder()
9296

9397
if primary_builder is not None:
9498
datasystem.synchronizers(primary_builder, secondary_builder)
99+
if fallback_builder is not None:
100+
datasystem.fdv1_compatible_synchronizer(fallback_builder)
95101

96102
if datasystem_config.get("payloadFilter") is not None:
97103
opts["payload_filter_key"] = datasystem_config["payloadFilter"]

ldclient/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from ldclient.feature_store import InMemoryFeatureStore
1212
from ldclient.hook import Hook
13-
from ldclient.impl.datasystem import Initializer, Synchronizer
1413
from ldclient.impl.util import (
1514
log,
1615
validate_application_info,
@@ -22,6 +21,8 @@
2221
DataStoreMode,
2322
EventProcessor,
2423
FeatureStore,
24+
Initializer,
25+
Synchronizer,
2526
UpdateProcessor
2627
)
2728
from ldclient.plugin import Plugin

ldclient/impl/datasystem/config.py renamed to ldclient/datasystem.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@
1616
StreamingDataSource,
1717
StreamingDataSourceBuilder
1818
)
19-
from ldclient.impl.datasystem import Initializer, Synchronizer
20-
from ldclient.interfaces import DataStoreMode, FeatureStore
19+
from ldclient.interfaces import (
20+
DataStoreMode,
21+
FeatureStore,
22+
Initializer,
23+
Synchronizer
24+
)
2125

2226
T = TypeVar("T")
2327

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""
2-
This module houses FDv2 types and implementations of synchronizers and
3-
initializers for the datasystem.
2+
This module houses FDv2 implementations of synchronizers and initializers for
3+
the datasystem.
44
55
All types and implementations in this module are considered internal
66
and are not part of the public API of the LaunchDarkly Python SDK.
@@ -9,7 +9,3 @@
99
1010
You have been warned.
1111
"""
12-
13-
from .polling import PollingResult, Requester
14-
15-
__all__: list[str] = ["PollingResult", "Requester"]

ldclient/impl/datasourcev2/polling.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,10 @@
1515

1616
from ldclient.config import Config
1717
from ldclient.impl.datasource.feature_requester import LATEST_ALL_URI
18-
from ldclient.impl.datasystem import BasisResult, SelectorStore, Update
1918
from ldclient.impl.datasystem.protocolv2 import (
20-
Basis,
21-
ChangeSet,
22-
ChangeSetBuilder,
2319
DeleteObject,
2420
EventName,
25-
IntentCode,
26-
ObjectKind,
27-
Payload,
28-
PutObject,
29-
Selector,
30-
ServerIntent
21+
PutObject
3122
)
3223
from ldclient.impl.http import _http_factory
3324
from ldclient.impl.repeating_task import RepeatingTask
@@ -44,11 +35,22 @@
4435
log
4536
)
4637
from ldclient.interfaces import (
38+
Basis,
39+
BasisResult,
40+
ChangeSet,
41+
ChangeSetBuilder,
4742
DataSourceErrorInfo,
4843
DataSourceErrorKind,
49-
DataSourceState
44+
DataSourceState,
45+
Initializer,
46+
IntentCode,
47+
ObjectKind,
48+
Selector,
49+
SelectorStore,
50+
ServerIntent,
51+
Synchronizer,
52+
Update
5053
)
51-
from ldclient.versioned_data_kind import FEATURES, SEGMENTS
5254

5355
POLLING_ENDPOINT = "/sdk/poll"
5456

@@ -78,7 +80,7 @@ def fetch(self, selector: Optional[Selector]) -> PollingResult:
7880
CacheEntry = namedtuple("CacheEntry", ["data", "etag"])
7981

8082

81-
class PollingDataSource:
83+
class PollingDataSource(Initializer, Synchronizer):
8284
"""
8385
PollingDataSource is a data source that can retrieve information from
8486
LaunchDarkly either as an Initializer or as a Synchronizer.
@@ -235,7 +237,7 @@ def _poll(self, ss: SelectorStore) -> BasisResult:
235237

236238

237239
# pylint: disable=too-few-public-methods
238-
class Urllib3PollingRequester:
240+
class Urllib3PollingRequester(Requester):
239241
"""
240242
Urllib3PollingRequester is a Requester that uses urllib3 to make HTTP
241243
requests.
@@ -401,7 +403,7 @@ def build(self) -> PollingDataSource:
401403

402404

403405
# pylint: disable=too-few-public-methods
404-
class Urllib3FDv1PollingRequester:
406+
class Urllib3FDv1PollingRequester(Requester):
405407
"""
406408
Urllib3PollingRequesterFDv1 is a Requester that uses urllib3 to make HTTP
407409
requests.

ldclient/impl/datasourcev2/status.py

Lines changed: 0 additions & 109 deletions
This file was deleted.

ldclient/impl/datasourcev2/streaming.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,13 @@
1818
from ld_eventsource.errors import HTTPStatusError
1919

2020
from ldclient.config import Config
21-
from ldclient.impl.datasystem import (
22-
DiagnosticAccumulator,
23-
DiagnosticSource,
24-
SelectorStore,
25-
Synchronizer,
26-
Update
27-
)
21+
from ldclient.impl.datasystem import DiagnosticAccumulator, DiagnosticSource
2822
from ldclient.impl.datasystem.protocolv2 import (
29-
ChangeSetBuilder,
3023
DeleteObject,
3124
Error,
3225
EventName,
3326
Goodbye,
34-
IntentCode,
35-
PutObject,
36-
Selector,
37-
ServerIntent
27+
PutObject
3828
)
3929
from ldclient.impl.http import HTTPFactory, _http_factory
4030
from ldclient.impl.util import (
@@ -45,9 +35,16 @@
4535
log
4636
)
4737
from ldclient.interfaces import (
38+
ChangeSetBuilder,
4839
DataSourceErrorInfo,
4940
DataSourceErrorKind,
50-
DataSourceState
41+
DataSourceState,
42+
IntentCode,
43+
Selector,
44+
SelectorStore,
45+
ServerIntent,
46+
Synchronizer,
47+
Update
5148
)
5249

5350
# allows for up to 5 minutes to elapse without any data sent across the stream.

0 commit comments

Comments
 (0)