Skip to content

Commit 33b599a

Browse files
Merge pull request #10 from drone/ci_workflow
CI workflow
2 parents d3ca0d1 + c61c2be commit 33b599a

File tree

4 files changed

+38
-29
lines changed

4 files changed

+38
-29
lines changed

.github/ci.yml renamed to .github/workflows/ci.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,13 @@ jobs:
2424
run: |
2525
python -m pip install --upgrade pip
2626
pip install flake8 pytest
27-
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
27+
if [ -f requirements_dev.txt ]; then pip install -r requirements_dev.txt; fi
28+
- name: Format
29+
run: |
30+
make fmt
2831
- name: Lint with flake8
2932
run: |
30-
# stop the build if there are Python syntax errors or undefined names
31-
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
32-
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
33-
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
33+
make lint
3434
- name: Test with pytest
3535
run: |
36-
pytest
36+
make test

featureflags/client.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -109,27 +109,33 @@ def map_segments_from_cache(self, fc: FeatureConfig) -> None:
109109
if self._config.cache:
110110
segments = fc.get_segment_identifiers()
111111
for identifier in segments:
112-
segment = self._config.cache.get(f'segments/{identifier}')
113-
if fc.segments is None:
114-
fc.segments = Segments({})
115-
fc.segments[identifier] = segment
112+
try:
113+
segment = self._config.cache.get(f'segments/{identifier}')
114+
if fc.segments is None:
115+
fc.segments = Segments({})
116+
fc.segments[identifier] = segment
117+
except KeyError:
118+
log.warn("segment %s not found in cache", identifier)
116119

117120
def _variation(self, fn: str, identifier: str, target: Target,
118121
default: Any) -> Any:
119122
if self._config.cache:
120-
fc = self._config.cache.get(f'flags/{identifier}')
121-
if fc:
122-
self.map_segments_from_cache(fc)
123-
method = getattr(fc, fn, None)
124-
if method:
125-
variation = method(target)
126-
if variation is None:
127-
log.debug('No variation found')
128-
return default
129-
self._analytics.enqueue(target, fc, variation)
130-
return variation.bool()
131-
else:
132-
log.error("Wrong method name %s", fn)
123+
try:
124+
fc = self._config.cache.get(f'flags/{identifier}')
125+
if fc:
126+
self.map_segments_from_cache(fc)
127+
method = getattr(fc, fn, None)
128+
if method:
129+
variation = method(target)
130+
if variation is None:
131+
log.debug('No variation found')
132+
return default
133+
self._analytics.enqueue(target, fc, variation)
134+
return variation.bool()
135+
else:
136+
log.error("Wrong method name %s", fn)
137+
except KeyError:
138+
log.warn("flag %s not found in cache", identifier)
133139
return default
134140

135141
def bool_variation(self, identifier: str, target: Target,

featureflags/lru_cache.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def set(self, key: str, value: Any) -> None:
3434

3535
def get(self, key: str) -> Any:
3636
val = self.cache.get(key)
37-
if val:
38-
self.cache.move_to_end(key)
37+
self.cache.move_to_end(key)
3938
return val
4039

4140
def remove(self, keys: List[str]) -> None:

requirements_dev.txt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ pip==19.2.3
22
bump2version==0.5.11
33
wheel==0.33.6
44
watchdog==0.9.0
5-
flake8==3.7.8
5+
flake8==3.9.2
6+
autopep8==1.5.7
7+
isort==5.8.0
68
mypy==0.812
79
tox==3.14.0
810
coverage==4.5.4
9-
Sphinx==1.8.5
11+
Sphinx==4.1.2
1012
twine==3.4.1
1113

1214
pytest==5.1
@@ -18,5 +20,7 @@ attrs~=21.2.0
1820

1921
pyjwt==2.0.1
2022

21-
openapi-python-client~=0.9.2
22-
requests==2.25.1
23+
openapi-python-client~=0.10.3
24+
requests==2.25.1
25+
26+
mmh3

0 commit comments

Comments
 (0)