Skip to content

Commit bac6721

Browse files
feat: Update OpenFeature Provider (#83)
* feat: trying to update openfeature and other dependancies * chore: add python 3.9 to unit tests * feat: update wasm bucketing to 1.31.2, update min python version to 3.9 * chore: update gitignore * fix: revert requirements changes * feat: setting sdkPlatform working * chore: update to use datetime.now(timezone.utc) * feat: update OpenFeature Provider with initialize and shutdown methods * chore: cleanup * fix: linting issues * fix: more linting * chore: fix mypy issues with close()
1 parent d4e009a commit bac6721

File tree

17 files changed

+88
-31
lines changed

17 files changed

+88
-31
lines changed

.github/workflows/unit_test.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
name: Unit Tests
22

3-
on: [ push ]
3+
on: [push]
44

55
jobs:
66
unit_tests:
77
name: Unit Tests
88
runs-on: ${{matrix.os}}
99
strategy:
1010
matrix:
11-
python-version: [ "3.12" ]
11+
python-version: ["3.12", "3.9"]
1212
os: [ubuntu-latest, windows-latest]
1313

1414
steps:
@@ -17,11 +17,11 @@ jobs:
1717
uses: actions/setup-python@v5
1818
with:
1919
python-version: ${{ matrix.python-version }}
20-
cache: 'pip'
20+
cache: "pip"
2121
- name: Install dependencies
2222
run: |
2323
pip install --upgrade pip
2424
pip install -r requirements.test.txt
2525
- name: Run unit tests
2626
run: |
27-
pytest
27+
pytest

.gitignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,9 @@ target/
7171
benchmark.json
7272

7373
pip-wheel-metadata/
74-
.venv/
74+
.venv/
75+
76+
# Virtual environments
77+
venv*/
78+
.venv*/
79+
*venv/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This SDK allows your application to interface with the [DevCycle Bucketing API](
66

77
## Requirements
88

9-
* Python 3.8+
9+
* Python 3.9+
1010

1111
## Installation
1212

-529 KB
Binary file not shown.
178 Bytes
Binary file not shown.

devcycle_python_sdk/cloud_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,13 @@ def track(self, user: DevCycleUser, user_event: DevCycleEvent) -> None:
182182
except Exception as e:
183183
logger.error(f"DevCycle: Error tracking event: {e}")
184184

185+
def close(self) -> None:
186+
"""
187+
Closes the client and releases any resources held by it.
188+
"""
189+
# Cloud client doesn't need to release any resources
190+
logger.debug("DevCycle: Cloud client closed")
191+
185192

186193
def _validate_sdk_key(sdk_key: str) -> None:
187194
if sdk_key is None or len(sdk_key) == 0:

devcycle_python_sdk/devcycle_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,10 @@ def get_openfeature_provider(self) -> AbstractProvider:
3838
@abstractmethod
3939
def get_sdk_platform(self) -> str:
4040
pass
41+
42+
@abstractmethod
43+
def close(self) -> None:
44+
"""
45+
Closes the client and releases any resources held by it.
46+
"""
47+
pass

devcycle_python_sdk/local_client.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
import uuid
44
from numbers import Real
5-
from typing import Any, Dict, Union
5+
from typing import Any, Dict, Union, Optional
66

77
from devcycle_python_sdk import DevCycleLocalOptions, AbstractDevCycleClient
88
from devcycle_python_sdk.api.local_bucketing import LocalBucketing
@@ -50,12 +50,21 @@ def __init__(self, sdk_key: str, options: DevCycleLocalOptions):
5050
sdk_key, self.client_uuid, self.options, self.local_bucketing
5151
)
5252

53-
self._openfeature_provider = DevCycleProvider(self)
53+
self._openfeature_provider: Optional[DevCycleProvider] = None
5454

5555
def get_sdk_platform(self) -> str:
5656
return "Local"
5757

5858
def get_openfeature_provider(self) -> AbstractProvider:
59+
if self._openfeature_provider is None:
60+
self._openfeature_provider = DevCycleProvider(self)
61+
62+
# Update platform data for OpenFeature
63+
self._platform_data.sdkPlatform = "python-of"
64+
self.local_bucketing.set_platform_data(
65+
json.dumps(self._platform_data.to_json())
66+
)
67+
5968
return self._openfeature_provider
6069

6170
def is_initialized(self) -> bool:

devcycle_python_sdk/models/event.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class EventType:
1818
class DevCycleEvent:
1919
type: Optional[str] = None
2020
target: Optional[str] = None
21-
date: datetime = field(default_factory=lambda: datetime.utcnow())
21+
date: datetime = field(default_factory=lambda: datetime.now(timezone.utc))
2222
value: Optional[int] = None
2323
metaData: Optional[Dict[str, str]] = None
2424

devcycle_python_sdk/models/platform_data.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# ruff: noqa: N815
22
import platform
33
import socket
4+
from typing import Optional
45
from dataclasses import dataclass
56
from devcycle_python_sdk.util.version import sdk_version
67

@@ -13,6 +14,7 @@ class PlatformData:
1314
deviceModel: str
1415
platform: str
1516
hostname: str
17+
sdkPlatform: Optional[str] = None
1618

1719
def to_json(self):
1820
return {

0 commit comments

Comments
 (0)