diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml index b31e502..59c9fd7 100644 --- a/.github/workflows/python-package.yml +++ b/.github/workflows/python-package.yml @@ -11,12 +11,12 @@ jobs: strategy: matrix: os: [ "ubuntu-latest" ] - python-version: ['3.8', '3.9', '3.10', '3.11'] + python-version: ['3.9', '3.12', '3.14'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Install Poetry @@ -24,26 +24,28 @@ jobs: with: virtualenvs-create: true virtualenvs-in-project: true + virtualenvs-path: .venv + installer-parallel: true - name: Load cached venv id: cached-poetry-dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: .venv key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} - name: Install dependencies if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' run: poetry install --no-interaction --no-root - - name: Install library + - name: Install project run: poetry install --no-interaction - name: Test with pytest run: poetry run pytest --cov=flagship --cov-report=xml ./tests/ - name: Upload coverage - if: matrix.python-version == 3.8 + if: matrix.python-version == 3.9 uses: codecov/codecov-action@v3 with: file: ./coverage.xml fail_ci_if_error: false - name: Build and publish library - if: matrix.python-version == 3.8 + if: matrix.python-version == 3.9 run: | - poetry build \ No newline at end of file + poetry build diff --git a/.github/workflows/python-test.yml b/.github/workflows/python-test.yml index 22d3332..27aac4d 100644 --- a/.github/workflows/python-test.yml +++ b/.github/workflows/python-test.yml @@ -11,13 +11,12 @@ jobs: strategy: matrix: os: [ "ubuntu-latest" ] - python-version: ['3.8', '3.9', '3.10', '3.11'] -# python-version: ['3.7', '3.8', '3.9', '3.10', '3.11'] + python-version: ['3.9', '3.12', '3.14'] runs-on: ${{ matrix.os }} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v4 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Install Poetry @@ -27,7 +26,7 @@ jobs: virtualenvs-in-project: true - name: Load cached venv id: cached-poetry-dependencies - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: .venv key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }} @@ -39,7 +38,7 @@ jobs: - name: Test with pytest run: poetry run pytest --cov=flagship --cov-report=xml ./tests/ - name: Upload coverage - if: matrix.python-version == 3.8 + if: matrix.python-version == 3.9 uses: codecov/codecov-action@v3 with: file: ./coverage.xml diff --git a/flagship/__init__.py b/flagship/__init__.py index f470320..104160a 100644 --- a/flagship/__init__.py +++ b/flagship/__init__.py @@ -15,8 +15,11 @@ from flagship.visitor import Visitor __name__ = 'flagship' -__version__ = importlib_metadata.distribution(__name__).version - +try: + from importlib.metadata import distribution + __version__ = distribution(__name__).version +except Exception: + __version__ = "0.0.0-dev" class Flagship: __instance = None @@ -115,12 +118,10 @@ def __init__(self): @param_types_validator(True, str, str, [_FlagshipConfig, None]) def start(self, env_id, api_key, flagship_config): - # self.update_status(flagship_config, Status.STARTING) if not env_id or not api_key: raise InitializationParamError() self.update_status(flagship_config, Status.STARTING) self.configuration_manager.init(env_id, api_key, flagship_config, self.update_status) - # self.update_status(flagship_config, Status.STARTING) if self.configuration_manager.is_set() is False: self.update_status(self.configuration_manager.flagship_config, Status.NOT_INITIALIZED) self.__log(TAG_INITIALIZATION, LogLevel.ERROR, ERROR_CONFIGURATION) diff --git a/flagship/config.py b/flagship/config.py index d1a57d6..3d121e8 100644 --- a/flagship/config.py +++ b/flagship/config.py @@ -29,10 +29,10 @@ def __init__(self, mode, **kwargs): self.log_manager = self.get_arg(kwargs, 'log_manager', LogManager) or FlagshipLogManager(self.log_level) self.polling_interval = self.get_arg(kwargs, 'polling_interval', type(1)) or 60000 self.timeout = self.get_arg(kwargs, 'timeout', type(1)) or 2000 - self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None self.tracking_manager_config = self.get_arg(kwargs, 'tracking_manager_config', TrackingManagerConfig) or TrackingManagerConfig() self.cache_manager = self.get_arg(kwargs, 'cache_manager', CacheManager) or None + self.status_listener = self.get_arg(kwargs, 'status_listener', StatusListener) or None def get_arg(self, kwargs, name, c_type): return kwargs[name] if name in kwargs and isinstance(kwargs[name], c_type) else None diff --git a/flagship/config_manager.py b/flagship/config_manager.py index 7636b02..703b3f3 100644 --- a/flagship/config_manager.py +++ b/flagship/config_manager.py @@ -26,9 +26,9 @@ def init(self, env_id, api_key, config=None, update_status=None): self.flagship_config.log_manager.log(TAG_INITIALIZATION, LogLevel.WARNING, WARNING_DEFAULT_CONFIG) self.flagship_config.env_id = env_id self.flagship_config.api_key = api_key - self.init_decision_manager(update_status) self.init_cache_manager() self.init_tracking_manager() + self.init_decision_manager(update_status) self.decision_manager.start_running() def init_decision_manager(self, update_status=None): @@ -39,13 +39,9 @@ def init_decision_manager(self, update_status=None): def init_cache_manager(self): try: - # if self.cache_manager is None: - # self.cache_manager = CacheManager() if self.flagship_config.cache_manager is not None: self.cache_manager = self.flagship_config.cache_manager self.cache_manager.init(self.flagship_config) - # if self.flagship_config.cache_manager is not None: - # self.flagship_config.cache_manager.init(env_id) except Exception as e: print(e) @@ -53,7 +49,6 @@ def init_tracking_manager(self): if self.tracking_manager is None: self.tracking_manager = TrackingManager(self.flagship_config, self.cache_manager) self.tracking_manager.init(self.flagship_config, self.cache_manager) - # self.tracking_manager.start_running() def is_set(self): return self.flagship_config.is_set() and self.decision_manager is not None diff --git a/flagship/hits.py b/flagship/hits.py index 4e95951..c2b92f3 100644 --- a/flagship/hits.py +++ b/flagship/hits.py @@ -572,10 +572,16 @@ def __init__(self, visitor_id, context): Hit.__init__(self, HitType.SEGMENT) data = { HitFields.visitor_id: visitor_id, - HitFields.segment_list: context + HitFields.segment_list: self.stringify_values(context) } self.hit_data.update(data) + def stringify_values(self, obj): + new_obj = {} + for key, value in obj.items(): + new_obj[key] = str(value) + return new_obj + def check_data_validity(self): if ((Hit.check_data_validity(self) is False) or (not bool(self.hit_data[HitFields.visitor_id])) or diff --git a/pyproject.toml b/pyproject.toml index 3952645..20d0ccd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "flagship" -version = "3.0.0" +version = "3.0.1" description = "Flagship Python SDK" authors = ["Raphael "] license = "Apache License Version 2.0" @@ -20,7 +20,7 @@ pytest-cov = "^4.1.0" [tool.poetry.urls] Sources = "https://github.com/abtasty/flagship-python-sdk" -Documentation = "https://docs.developers.flagship.io/docs/python" +Documentation = "https://docs.abtasty.com/server-side/sdks/python" [build-system] requires = ["poetry-core"] diff --git a/script.py b/script.py index e64af46..1a417c6 100644 --- a/script.py +++ b/script.py @@ -1,30 +1,34 @@ -import asyncio -import sys import time +from flagship.config import DecisionApi from flagship import * -from flagship.cache_manager import SqliteCacheManager -from flagship.config import DecisionApi, Bucketing -from flagship.hits import Screen +from flagship.config import Bucketing +from flagship.status_listener import StatusListener from flagship.tracking_manager import TrackingManagerConfig - +from flagship.hits import Screen def init(): - print(sys.version) - Flagship.start('__env_id__', '__api_key__', DecisionApi(timeout=3000, - cache_manager=SqliteCacheManager(), - log_level=LogLevel.ALL, - tracking_manager_config=TrackingManagerConfig( - time_interval=10000, - max_pool_size=5))) ## Demo - - visitor = Flagship.new_visitor('visitor-A', context={'testing_tracking_manager': True}) - visitor.fetch_flags() - visitor.get_flag("my_flag", 'default').value() - visitor.send_hit(Screen("screen 1")) - time.sleep(2) - - - -init() \ No newline at end of file + class CustomStatusListener(StatusListener): + + def on_status_changed(self, new_status): + if new_status is Status.READY: + print(new_status) + visitor = Flagship.new_visitor(visitor_id='visitor-A', context={'isVIP': True, "int": 4973}) + visitor.fetch_flags() + print(str(visitor.get_flag("my_flag", 'default').value())) + visitor.send_hit(Screen("screen 1")) + + Flagship.start( + '_ENV_ID_', + '_API_KEY_', + DecisionApi( + timeout=3000, + status_listener=CustomStatusListener(), + log_level=LogLevel.ALL, + tracking_manager_config=TrackingManagerConfig(time_interval=5000, max_pool_size=5) + ) + ) + time.sleep(6) + +init() diff --git a/setup.cfg b/setup.cfg index 20d2f16..ec597ef 100644 --- a/setup.cfg +++ b/setup.cfg @@ -17,10 +17,10 @@ classifiers = Operating System :: OS Independent author = Flagship Team author_email = support@flagship.io -url = https://docs.developers.flagship.io/docs/python-v2-1 +url = https://docs.abtasty.com/server-side/sdks/python project_urls = Sources = https://github.com/abtasty/flagship-python-sdk - Documentation = https://docs.developers.flagship.io/docs/python-v2-1 + Documentation = https://docs.abtasty.com/server-side/sdks/python [options] python_requires = >=3.7 packages = find: