flagsmith-flag-engine 10.0.4__tar.gz → 10.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. {flagsmith_flag_engine-10.0.4/flagsmith_flag_engine.egg-info → flagsmith_flag_engine-10.2.0}/PKG-INFO +9 -1
  2. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/README.md +8 -0
  3. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/context/types.py +1 -0
  4. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/result/types.py +2 -1
  5. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/segments/evaluator.py +34 -30
  6. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0/flagsmith_flag_engine.egg-info}/PKG-INFO +9 -1
  7. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/setup.py +1 -1
  8. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/LICENSE.txt +0 -0
  9. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/__init__.py +0 -0
  10. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/context/__init__.py +0 -0
  11. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/context/mappers.py +0 -0
  12. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/engine.py +0 -0
  13. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/py.typed +0 -0
  14. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/result/__init__.py +0 -0
  15. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/segments/__init__.py +0 -0
  16. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/segments/constants.py +0 -0
  17. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/segments/types.py +0 -0
  18. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/segments/utils.py +0 -0
  19. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/__init__.py +0 -0
  20. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/hashing.py +0 -0
  21. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/json/__init__.py +0 -0
  22. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/json/encoders.py +0 -0
  23. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/semver.py +0 -0
  24. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flag_engine/utils/types.py +0 -0
  25. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flagsmith_flag_engine.egg-info/SOURCES.txt +0 -0
  26. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flagsmith_flag_engine.egg-info/dependency_links.txt +0 -0
  27. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flagsmith_flag_engine.egg-info/requires.txt +0 -0
  28. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/flagsmith_flag_engine.egg-info/top_level.txt +0 -0
  29. {flagsmith_flag_engine-10.0.4 → flagsmith_flag_engine-10.2.0}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagsmith-flag-engine
3
- Version: 10.0.4
3
+ Version: 10.2.0
4
4
  Summary: Flag engine for the Flagsmith API.
5
5
  Home-page: https://github.com/Flagsmith/flagsmith-engine
6
6
  Author: Flagsmith
@@ -46,6 +46,14 @@ source .venv/bin/activate
46
46
  python -m pip install -r requirements-dev.txt
47
47
  ```
48
48
 
49
+ ## Syncing engine-test-data
50
+
51
+ The engine-test-data submodule is pinned to a specific tag. To sync it locally:
52
+
53
+ ```bash
54
+ make sync-engine-test-data
55
+ ```
56
+
49
57
  ## Design
50
58
 
51
59
  - Marshmallow Schemas
@@ -15,6 +15,14 @@ source .venv/bin/activate
15
15
  python -m pip install -r requirements-dev.txt
16
16
  ```
17
17
 
18
+ ## Syncing engine-test-data
19
+
20
+ The engine-test-data submodule is pinned to a specific tag. To sync it locally:
21
+
22
+ ```bash
23
+ make sync-engine-test-data
24
+ ```
25
+
18
26
  ## Design
19
27
 
20
28
  - Marshmallow Schemas
@@ -23,6 +23,7 @@ class EnvironmentContext(TypedDict):
23
23
 
24
24
 
25
25
  class FeatureValue(TypedDict):
26
+ key: NotRequired[str]
26
27
  value: Any
27
28
  weight: float
28
29
  priority: int
@@ -4,7 +4,7 @@
4
4
 
5
5
  from __future__ import annotations
6
6
 
7
- from typing import Any, Dict, Generic, List
7
+ from typing import Any, Dict, Generic, List, Optional
8
8
 
9
9
  from typing_extensions import NotRequired, TypedDict
10
10
 
@@ -16,6 +16,7 @@ class FlagResult(TypedDict, Generic[FeatureMetadataT]):
16
16
  enabled: bool
17
17
  value: Any
18
18
  reason: str
19
+ variant: Optional[str]
19
20
  metadata: NotRequired[FeatureMetadataT]
20
21
 
21
22
 
@@ -178,38 +178,39 @@ def get_flag_result_from_context(
178
178
  """
179
179
  key = _get_identity_key(context)
180
180
 
181
- flag_result: typing.Optional[FlagResult[FeatureMetadataT]] = None
181
+ value = feature_context["value"]
182
+ variant: typing.Optional[str] = None
182
183
 
183
184
  if key is not None and (variants := feature_context.get("variants")):
185
+ # Default to the control bucket; a matched named variant overrides this.
186
+ variant = "control"
187
+
184
188
  percentage_value = get_hashed_percentage_for_object_ids(
185
189
  [feature_context["key"], key]
186
190
  )
187
191
 
188
192
  start_percentage = 0.0
189
193
 
190
- for variant in sorted(
194
+ for feature_value in sorted(
191
195
  variants,
192
196
  key=operator.itemgetter("priority"),
193
197
  ):
194
- limit = (weight := variant["weight"]) + start_percentage
198
+ limit = (weight := feature_value["weight"]) + start_percentage
195
199
  if start_percentage <= percentage_value < limit:
196
- flag_result = {
197
- "enabled": feature_context["enabled"],
198
- "name": feature_context["name"],
199
- "reason": f"SPLIT; weight={weight}",
200
- "value": variant["value"],
201
- }
200
+ reason = f"SPLIT; weight={weight}"
201
+ value = feature_value["value"]
202
+ variant = feature_value.get("key")
202
203
  break
203
204
 
204
205
  start_percentage = limit
205
206
 
206
- if flag_result is None:
207
- flag_result = {
208
- "enabled": feature_context["enabled"],
209
- "name": feature_context["name"],
210
- "reason": reason,
211
- "value": feature_context["value"],
212
- }
207
+ flag_result: FlagResult[FeatureMetadataT] = {
208
+ "enabled": feature_context["enabled"],
209
+ "name": feature_context["name"],
210
+ "reason": reason,
211
+ "value": value,
212
+ "variant": variant,
213
+ }
213
214
 
214
215
  if metadata := feature_context.get("metadata"):
215
216
  flag_result["metadata"] = metadata
@@ -236,27 +237,30 @@ def context_matches_rule(
236
237
  ) -> bool:
237
238
  matches_conditions = (
238
239
  get_matching_function(rule["type"])(
239
- [
240
- context_matches_condition(
241
- context=context,
242
- condition=condition,
243
- segment_key=segment_key,
244
- )
245
- for condition in conditions
246
- ]
240
+ context_matches_condition(
241
+ context=context,
242
+ condition=condition,
243
+ segment_key=segment_key,
244
+ )
245
+ for condition in conditions
247
246
  )
248
247
  if (conditions := rule.get("conditions"))
249
248
  else True
250
249
  )
251
250
 
252
- return matches_conditions and all(
253
- context_matches_rule(
254
- context=context,
255
- rule=rule,
256
- segment_key=segment_key,
251
+ matches_rules = (
252
+ get_matching_function(rule["type"])(
253
+ context_matches_rule(
254
+ context=context,
255
+ rule=sub_rule,
256
+ segment_key=segment_key,
257
+ )
258
+ for sub_rule in rules
257
259
  )
258
- for rule in rule.get("rules") or []
260
+ if (rules := rule.get("rules"))
261
+ else True
259
262
  )
263
+ return matches_conditions and matches_rules
260
264
 
261
265
 
262
266
  def context_matches_condition(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flagsmith-flag-engine
3
- Version: 10.0.4
3
+ Version: 10.2.0
4
4
  Summary: Flag engine for the Flagsmith API.
5
5
  Home-page: https://github.com/Flagsmith/flagsmith-engine
6
6
  Author: Flagsmith
@@ -46,6 +46,14 @@ source .venv/bin/activate
46
46
  python -m pip install -r requirements-dev.txt
47
47
  ```
48
48
 
49
+ ## Syncing engine-test-data
50
+
51
+ The engine-test-data submodule is pinned to a specific tag. To sync it locally:
52
+
53
+ ```bash
54
+ make sync-engine-test-data
55
+ ```
56
+
49
57
  ## Design
50
58
 
51
59
  - Marshmallow Schemas
@@ -2,7 +2,7 @@ from setuptools import find_packages, setup
2
2
 
3
3
  setup(
4
4
  name="flagsmith-flag-engine",
5
- version="10.0.4",
5
+ version="10.2.0",
6
6
  author="Flagsmith",
7
7
  author_email="support@flagsmith.com",
8
8
  packages=find_packages(include=["flag_engine", "flag_engine.*"]),