Skip to content

Commit c604b1b

Browse files
authored
Feat/v1.1.5 (#8)
1 parent 62b5654 commit c604b1b

File tree

11 files changed

+167
-8
lines changed

11 files changed

+167
-8
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: Python Linting and Testing
2+
3+
on:
4+
pull_request:
5+
types:
6+
- opened
7+
- reopened
8+
- synchronize
9+
10+
jobs:
11+
build:
12+
# compatible for py 3.6
13+
runs-on: ubuntu-20.04
14+
strategy:
15+
# You can use PyPy versions in python-version.
16+
matrix:
17+
python-version: ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
18+
19+
steps:
20+
- uses: actions/checkout@v3
21+
- name: Set up Python ${{ matrix.python-version }}
22+
uses: actions/setup-python@v4
23+
with:
24+
python-version: ${{ matrix.python-version }}
25+
# You can test your matrix by printing the current Python version
26+
- name: Display Python version
27+
run: python -c "import sys; print(sys.version)"
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
pip install flake8 pytest pytest-mock
32+
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
33+
- name: Lint with flake8
34+
run: |
35+
# stop the build if there are Python syntax errors
36+
flake8 .
37+
- name: Test with pytest
38+
run: |
39+
pytest

.github/workflows/release.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# This workflow uses actions that are not certified by GitHub.
2+
# They are provided by a third-party and are governed by
3+
# separate terms of service, privacy policy, and support
4+
# documentation.
5+
6+
# GitHub recommends pinning actions to a commit SHA.
7+
# To get a newer version, you will need to update the SHA.
8+
# You can also reference a tag or branch, but the action may change without warning.
9+
10+
name: Upload Python Package
11+
12+
on:
13+
push:
14+
branches:
15+
- master
16+
- main
17+
18+
jobs:
19+
deploy:
20+
runs-on: ubuntu-latest
21+
environment: py-production
22+
steps:
23+
- uses: actions/checkout@v3
24+
- name: Read current version
25+
id: version
26+
uses: juliangruber/read-file-action@v1.1
27+
with:
28+
path: ./release/package.json
29+
property: version
30+
- name: Read realease description
31+
id: description
32+
uses: juliangruber/read-file-action@v1.1.6
33+
with:
34+
path: ./release/description.md
35+
- name: Create GitHub Release
36+
uses: actions/create-release@latest
37+
env:
38+
GITHUB_TOKEN: ${{ secrets.PROJECT_RELEASE_TOKEN }}
39+
with:
40+
tag_name: v${{steps.version.outputs.value}}
41+
release_name: v${{steps.version.outputs.value}}
42+
body: ${{steps.description.outputs.content}}
43+
draft: false
44+
prerelease: false
45+
- name: Set up Python
46+
uses: actions/setup-python@v4
47+
with:
48+
python-version: '3.x'
49+
- name: Install dependencies
50+
run: |
51+
python -m pip install --upgrade pip
52+
pip install build
53+
- name: Build package
54+
run: python -m build
55+
- name: Publish package distributions to PyPI
56+
uses: pypa/gh-action-pypi-publish@v1.8.6
57+
with:
58+
user: featbit
59+
password: ${{ secrets.PYPI_PASSWORD }}

MANIFEST.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
include requirements.txt
22
include README.md
3-
include dev-requirements.txt
3+
include dev-requirements.txt
4+
include release/package.json

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,13 @@ If you would like to get variations of all feature flags in a special environmen
144144
if client.initialize:
145145
user = {'key': user_key, 'name': user_name}
146146
all_flag_values = client.get_all_latest_flag_variations(user)
147-
detail = all_flag_values.get(flag_key, default=None)
147+
# get all feature flag keys
148+
keys = all_flag_values.keys()
149+
for flag_key in keys:
150+
# get viariation detail
151+
detail = all_flag_values.get(flag_key, default=None)
152+
# get viariation
153+
value = all_flag_values.get_variation(flag_key, default=None)
148154
```
149155

150156
> **Note**

fbclient/common_types.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,24 @@ def __init__(self, success: bool, reason: str,
215215
self._data = dict((ed.key_name, (ed, fb_event)) for ed, fb_event in data.items()) if data else {}
216216
self._event_handler = event_handler
217217

218+
def keys(self):
219+
"""
220+
return all feature flag keys
221+
"""
222+
return self._data.keys()
223+
224+
def get_variation(self, key_name: str, default: Any = None) -> Any:
225+
"""Return the variation of a given feature flag key
226+
227+
This method will send event to back to feature flag center immediately
228+
229+
The default value should be a string, boolean, numeric, or json type.
230+
231+
:param key_name: key name of the flag
232+
:return: the variation of the flag in any type of string, boolean, numeric, or json type
233+
"""
234+
return self.get(key_name, default).variation
235+
218236
def get(self, key_name: str, default: Any = None) -> EvalDetail:
219237
"""Return the flag evaluation details of a given feature flag key
220238

fbclient/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
VERSION = "1.1.4"
1+
VERSION = "1.1.5"

release/description.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
version: 1.1.5
3+
4+
## Break changes
5+
6+
No Break changes
7+
8+
## New features
9+
10+
No new features
11+
12+
## Updates
13+
14+
- optimize `AllFlagStates` in adding two functions: `keys` and `get_variation`

release/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"version":"1.1.5"
3+
}

setup.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1+
import json
12
from setuptools import setup, find_packages
23

3-
version = {}
4-
54

65
def last_version():
7-
with open("./fbclient/version.py") as fp:
8-
exec(fp.read(), version)
9-
return version['VERSION']
6+
with open("./release/package.json") as fp:
7+
version = json.load(fp)
8+
return version['version']
109

1110

1211
fb_version = last_version()

tests/test_fbclient.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,15 +206,30 @@ def test_get_all_latest_flag_variations():
206206
assert client.initialize
207207
all_states = client.get_all_latest_flag_variations(USER_1)
208208
ed = all_states.get("ff-test-bool", False)
209+
value = all_states.get_variation("ff-test-bool", False)
209210
assert ed is not None and ed.variation is True
211+
assert value is True
212+
assert "ff-test-bool" in all_states.keys()
210213
ed = all_states.get("ff-test-number", -1)
214+
value = all_states.get_variation("ff-test-number", -1)
211215
assert ed is not None and ed.variation == 1
216+
assert value == 1
217+
assert "ff-test-number" in all_states.keys()
212218
ed = all_states.get("ff-test-string", 'error')
219+
value = all_states.get_variation("ff-test-string", 'error')
213220
assert ed is not None and ed.variation == "others"
221+
assert value == "others"
222+
assert "ff-test-string" in all_states.keys()
214223
ed = all_states.get("ff-test-seg", 'error')
224+
value = all_states.get_variation("ff-test-seg", 'error')
215225
assert ed is not None and ed.variation == "teamA"
226+
assert value == "teamA"
227+
assert "ff-test-seg" in all_states.keys()
216228
ed = all_states.get("ff-test-json", {})
229+
value = all_states.get_variation("ff-test-json", {})
217230
assert ed is not None and ed.variation["code"] == 200
231+
assert value["code"] == 200
232+
assert "ff-test-json" in all_states.keys()
218233

219234

220235
def test_variation_argument_error():

0 commit comments

Comments
 (0)