Skip to content

Commit 42195ef

Browse files
authored
Fix/fs3 1933 segments type value (#22)
### Fixed - Corrected Segment Hit logic and configuration manager. - Updated documentation links in the configuration. ### CI/CD - Updated GitHub Actions workflow for the Python package. - Updated supported Python versions in the CI workflow.
1 parent c2d0d67 commit 42195ef

File tree

9 files changed

+60
-53
lines changed

9 files changed

+60
-53
lines changed

.github/workflows/python-package.yml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,41 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ "ubuntu-latest" ]
14-
python-version: ['3.8', '3.9', '3.10', '3.11']
14+
python-version: ['3.9', '3.12', '3.14']
1515
runs-on: ${{ matrix.os }}
1616
steps:
17-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v5
1818
- name: Set up Python ${{ matrix.python-version }}
19-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v6
2020
with:
2121
python-version: ${{ matrix.python-version }}
2222
- name: Install Poetry
2323
uses: snok/install-poetry@v1
2424
with:
2525
virtualenvs-create: true
2626
virtualenvs-in-project: true
27+
virtualenvs-path: .venv
28+
installer-parallel: true
2729
- name: Load cached venv
2830
id: cached-poetry-dependencies
29-
uses: actions/cache@v3
31+
uses: actions/cache@v4
3032
with:
3133
path: .venv
3234
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
3335
- name: Install dependencies
3436
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
3537
run: poetry install --no-interaction --no-root
36-
- name: Install library
38+
- name: Install project
3739
run: poetry install --no-interaction
3840
- name: Test with pytest
3941
run: poetry run pytest --cov=flagship --cov-report=xml ./tests/
4042
- name: Upload coverage
41-
if: matrix.python-version == 3.8
43+
if: matrix.python-version == 3.9
4244
uses: codecov/codecov-action@v3
4345
with:
4446
file: ./coverage.xml
4547
fail_ci_if_error: false
4648
- name: Build and publish library
47-
if: matrix.python-version == 3.8
49+
if: matrix.python-version == 3.9
4850
run: |
49-
poetry build
51+
poetry build

.github/workflows/python-test.yml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ jobs:
1111
strategy:
1212
matrix:
1313
os: [ "ubuntu-latest" ]
14-
python-version: ['3.8', '3.9', '3.10', '3.11']
15-
# python-version: ['3.7', '3.8', '3.9', '3.10', '3.11']
14+
python-version: ['3.9', '3.12', '3.14']
1615
runs-on: ${{ matrix.os }}
1716
steps:
18-
- uses: actions/checkout@v3
17+
- uses: actions/checkout@v5
1918
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v4
19+
uses: actions/setup-python@v6
2120
with:
2221
python-version: ${{ matrix.python-version }}
2322
- name: Install Poetry
@@ -27,7 +26,7 @@ jobs:
2726
virtualenvs-in-project: true
2827
- name: Load cached venv
2928
id: cached-poetry-dependencies
30-
uses: actions/cache@v3
29+
uses: actions/cache@v4
3130
with:
3231
path: .venv
3332
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
@@ -39,7 +38,7 @@ jobs:
3938
- name: Test with pytest
4039
run: poetry run pytest --cov=flagship --cov-report=xml ./tests/
4140
- name: Upload coverage
42-
if: matrix.python-version == 3.8
41+
if: matrix.python-version == 3.9
4342
uses: codecov/codecov-action@v3
4443
with:
4544
file: ./coverage.xml

flagship/__init__.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,11 @@
1515
from flagship.visitor import Visitor
1616

1717
__name__ = 'flagship'
18-
__version__ = importlib_metadata.distribution(__name__).version
19-
18+
try:
19+
from importlib.metadata import distribution
20+
__version__ = distribution(__name__).version
21+
except Exception:
22+
__version__ = "0.0.0-dev"
2023

2124
class Flagship:
2225
__instance = None
@@ -115,12 +118,10 @@ def __init__(self):
115118

116119
@param_types_validator(True, str, str, [_FlagshipConfig, None])
117120
def start(self, env_id, api_key, flagship_config):
118-
# self.update_status(flagship_config, Status.STARTING)
119121
if not env_id or not api_key:
120122
raise InitializationParamError()
121123
self.update_status(flagship_config, Status.STARTING)
122124
self.configuration_manager.init(env_id, api_key, flagship_config, self.update_status)
123-
# self.update_status(flagship_config, Status.STARTING)
124125
if self.configuration_manager.is_set() is False:
125126
self.update_status(self.configuration_manager.flagship_config, Status.NOT_INITIALIZED)
126127
self.__log(TAG_INITIALIZATION, LogLevel.ERROR, ERROR_CONFIGURATION)

flagship/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ def __init__(self, mode, **kwargs):
2929
self.log_manager = self.get_arg(kwargs, 'log_manager', LogManager) or FlagshipLogManager(self.log_level)
3030
self.polling_interval = self.get_arg(kwargs, 'polling_interval', type(1)) or 60000
3131
self.timeout = self.get_arg(kwargs, 'timeout', type(1)) or 2000
32-
self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None
3332
self.tracking_manager_config = self.get_arg(kwargs, 'tracking_manager_config',
3433
TrackingManagerConfig) or TrackingManagerConfig()
3534
self.cache_manager = self.get_arg(kwargs, 'cache_manager', CacheManager) or None
35+
self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None
3636

3737
def get_arg(self, kwargs, name, c_type):
3838
return kwargs[name] if name in kwargs and isinstance(kwargs[name], c_type) else None

flagship/config_manager.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ def init(self, env_id, api_key, config=None, update_status=None):
2626
self.flagship_config.log_manager.log(TAG_INITIALIZATION, LogLevel.WARNING, WARNING_DEFAULT_CONFIG)
2727
self.flagship_config.env_id = env_id
2828
self.flagship_config.api_key = api_key
29-
self.init_decision_manager(update_status)
3029
self.init_cache_manager()
3130
self.init_tracking_manager()
31+
self.init_decision_manager(update_status)
3232
self.decision_manager.start_running()
3333

3434
def init_decision_manager(self, update_status=None):
@@ -39,21 +39,16 @@ def init_decision_manager(self, update_status=None):
3939

4040
def init_cache_manager(self):
4141
try:
42-
# if self.cache_manager is None:
43-
# self.cache_manager = CacheManager()
4442
if self.flagship_config.cache_manager is not None:
4543
self.cache_manager = self.flagship_config.cache_manager
4644
self.cache_manager.init(self.flagship_config)
47-
# if self.flagship_config.cache_manager is not None:
48-
# self.flagship_config.cache_manager.init(env_id)
4945
except Exception as e:
5046
print(e)
5147

5248
def init_tracking_manager(self):
5349
if self.tracking_manager is None:
5450
self.tracking_manager = TrackingManager(self.flagship_config, self.cache_manager)
5551
self.tracking_manager.init(self.flagship_config, self.cache_manager)
56-
# self.tracking_manager.start_running()
5752

5853
def is_set(self):
5954
return self.flagship_config.is_set() and self.decision_manager is not None

flagship/hits.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -572,10 +572,16 @@ def __init__(self, visitor_id, context):
572572
Hit.__init__(self, HitType.SEGMENT)
573573
data = {
574574
HitFields.visitor_id: visitor_id,
575-
HitFields.segment_list: context
575+
HitFields.segment_list: self.stringify_values(context)
576576
}
577577
self.hit_data.update(data)
578578

579+
def stringify_values(self, obj):
580+
new_obj = {}
581+
for key, value in obj.items():
582+
new_obj[key] = str(value)
583+
return new_obj
584+
579585
def check_data_validity(self):
580586
if ((Hit.check_data_validity(self) is False) or
581587
(not bool(self.hit_data[HitFields.visitor_id])) or

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "flagship"
3-
version = "3.0.0"
3+
version = "3.0.1"
44
description = "Flagship Python SDK"
55
authors = ["Raphael <raphael@abtasty.com>"]
66
license = "Apache License Version 2.0"
@@ -20,7 +20,7 @@ pytest-cov = "^4.1.0"
2020

2121
[tool.poetry.urls]
2222
Sources = "https://github.com/abtasty/flagship-python-sdk"
23-
Documentation = "https://docs.developers.flagship.io/docs/python"
23+
Documentation = "https://docs.abtasty.com/server-side/sdks/python"
2424

2525
[build-system]
2626
requires = ["poetry-core"]

script.py

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
import asyncio
2-
import sys
31
import time
42

3+
from flagship.config import DecisionApi
54
from flagship import *
6-
from flagship.cache_manager import SqliteCacheManager
7-
from flagship.config import DecisionApi, Bucketing
8-
from flagship.hits import Screen
5+
from flagship.config import Bucketing
6+
from flagship.status_listener import StatusListener
97
from flagship.tracking_manager import TrackingManagerConfig
10-
8+
from flagship.hits import Screen
119

1210
def init():
13-
print(sys.version)
14-
Flagship.start('__env_id__', '__api_key__', DecisionApi(timeout=3000,
15-
cache_manager=SqliteCacheManager(),
16-
log_level=LogLevel.ALL,
17-
tracking_manager_config=TrackingManagerConfig(
18-
time_interval=10000,
19-
max_pool_size=5))) ## Demo
20-
21-
visitor = Flagship.new_visitor('visitor-A', context={'testing_tracking_manager': True})
22-
visitor.fetch_flags()
23-
visitor.get_flag("my_flag", 'default').value()
24-
visitor.send_hit(Screen("screen 1"))
25-
time.sleep(2)
26-
27-
28-
2911

30-
init()
12+
class CustomStatusListener(StatusListener):
13+
14+
def on_status_changed(self, new_status):
15+
if new_status is Status.READY:
16+
print(new_status)
17+
visitor = Flagship.new_visitor(visitor_id='visitor-A', context={'isVIP': True, "int": 4973})
18+
visitor.fetch_flags()
19+
print(str(visitor.get_flag("my_flag", 'default').value()))
20+
visitor.send_hit(Screen("screen 1"))
21+
22+
Flagship.start(
23+
'_ENV_ID_',
24+
'_API_KEY_',
25+
DecisionApi(
26+
timeout=3000,
27+
status_listener=CustomStatusListener(),
28+
log_level=LogLevel.ALL,
29+
tracking_manager_config=TrackingManagerConfig(time_interval=5000, max_pool_size=5)
30+
)
31+
)
32+
time.sleep(6)
33+
34+
init()

setup.cfg

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ classifiers =
1717
Operating System :: OS Independent
1818
author = Flagship Team
1919
author_email = support@flagship.io
20-
url = https://docs.developers.flagship.io/docs/python-v2-1
20+
url = https://docs.abtasty.com/server-side/sdks/python
2121
project_urls =
2222
Sources = https://github.com/abtasty/flagship-python-sdk
23-
Documentation = https://docs.developers.flagship.io/docs/python-v2-1
23+
Documentation = https://docs.abtasty.com/server-side/sdks/python
2424
[options]
2525
python_requires = >=3.7
2626
packages = find:

0 commit comments

Comments
 (0)