Skip to content

Commit b637f4d

Browse files
Enforcing styling through Travis and pep8 (#59)
1 parent 8204f92 commit b637f4d

15 files changed

+61
-30
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ python:
33
- "2.7"
44
- "3.4"
55
install: "pip install -r requirements/core.txt;pip install -r requirements/test.txt"
6+
before_script: "pep8"
67
script: "nosetests --with-coverage --cover-package=optimizely"
78
after_success:
89
- coveralls

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ We welcome contributions and feedback! All contributors must sign our [Contribut
2121

2222
## Style
2323

24-
We enforce PEP-8 rules with a few minor deviations.
24+
We enforce PEP-8 rules with a few minor [deviations](https://github.com/optimizely/python-sdk/blob/master/tox.ini).
2525

2626
## License
2727

optimizely/decision_service.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ def get_variation(self, experiment, user_id, attributes, ignore_user_profile=Fal
151151
return None
152152

153153
def get_variation_for_layer(self, layer, user_id, attributes=None, ignore_user_profile=False):
154-
""" Determine which variation the user is in for a given layer. Returns the variation of the first experiment the user qualifies for.
154+
""" Determine which variation the user is in for a given layer.
155+
Returns the variation of the first experiment the user qualifies for.
155156
156157
Args:
157158
layer: Layer for which we are getting the variation.
@@ -169,7 +170,8 @@ def get_variation_for_layer(self, layer, user_id, attributes=None, ignore_user_p
169170
experiment = self.config.get_experiment_from_key(experiment_dict['key'])
170171
variation = self.get_variation(experiment, user_id, attributes, ignore_user_profile)
171172
if variation:
172-
self.logger.log(enums.LogLevels.DEBUG, 'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
173+
self.logger.log(enums.LogLevels.DEBUG,
174+
'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
173175
# Return as soon as we get a variation
174176
return variation
175177

@@ -197,7 +199,8 @@ def get_variation_for_feature(self, feature, user_id, attributes=None):
197199
variation = self.get_variation(experiment, user_id, attributes)
198200

199201
if variation:
200-
self.logger.log(enums.LogLevels.DEBUG, 'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
202+
self.logger.log(enums.LogLevels.DEBUG,
203+
'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
201204
else:
202205
self.logger.log(enums.LogLevels.ERROR, enums.Errors.INVALID_GROUP_ID_ERROR.format('_get_variation_for_feature'))
203206

@@ -209,7 +212,8 @@ def get_variation_for_feature(self, feature, user_id, attributes=None):
209212
variation = self.get_variation(experiment, user_id, attributes)
210213

211214
if variation:
212-
self.logger.log(enums.LogLevels.DEBUG, 'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
215+
self.logger.log(enums.LogLevels.DEBUG,
216+
'User "%s" is in variation %s of experiment %s.' % (user_id, variation.key, experiment.key))
213217

214218
# Next check if user is part of a rollout
215219
if not variation and feature.layerId:
@@ -243,4 +247,3 @@ def get_experiment_in_group(self, group, user_id):
243247
(user_id, group.id))
244248

245249
return None
246-

optimizely/entities.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
1415
class BaseEntity(object):
1516

1617
def __eq__(self, other):
@@ -68,6 +69,7 @@ def __init__(self, id, key, experimentIds, layerId, variables, groupId=None, **k
6869
self.variables = variables
6970
self.groupId = groupId
7071

72+
7173
class Group(BaseEntity):
7274

7375
def __init__(self, id, policy, experiments, trafficAllocation, **kwargs):

optimizely/error_handler.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
1415
class BaseErrorHandler(object):
1516
""" Class encapsulating exception handling functionality.
1617
Override with your own exception handler providing handle_error method. """

optimizely/exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
1415
class InvalidAttributeException(Exception):
1516
""" Raised when provided attribute is invalid. """
1617
pass

optimizely/helpers/validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ def is_user_profile_valid(user_profile):
136136
if not type(user_profile) is dict:
137137
return False
138138

139-
if not UserProfile.USER_ID_KEY in user_profile:
139+
if UserProfile.USER_ID_KEY not in user_profile:
140140
return False
141141

142-
if not UserProfile.EXPERIMENT_BUCKET_MAP_KEY in user_profile:
142+
if UserProfile.EXPERIMENT_BUCKET_MAP_KEY not in user_profile:
143143
return False
144144

145145
experiment_bucket_map = user_profile.get(UserProfile.EXPERIMENT_BUCKET_MAP_KEY)

optimizely/optimizely.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def activate(self, experiment_key, user_id, attributes=None):
191191

192192
return variation.key
193193

194-
def track(self, event_key, user_id, attributes=None, event_tags=None):
194+
def track(self, event_key, user_id, attributes=None, event_tags=None):
195195
""" Send conversion event to Optimizely.
196196
197197
Args:

optimizely/project_config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ def __init__(self, datafile, logger, error_handler):
9090
for variation in self.variation_key_map.get(experiment.key).values():
9191
self.variation_id_map[experiment.key][variation.id] = variation
9292
if variation.variables:
93-
self.variation_variable_usage_map[variation.id] = self._generate_key_map(variation.variables, 'id', entities.Variation.VariableUsage)
93+
self.variation_variable_usage_map[variation.id] = self._generate_key_map(
94+
variation.variables, 'id', entities.Variation.VariableUsage
95+
)
9496

9597
self.feature_key_map = self._generate_key_map(self.features, 'key', entities.Feature)
9698
for feature in self.feature_key_map.values():

optimizely/user_profile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Licensed under the Apache License, Version 2.0 (the "License");
33
# you may not use this file except in compliance with the License.
44
# You may obtain a copy of the License at
5-
#
5+
#
66
# http://www.apache.org/licenses/LICENSE-2.0
77

88
# Unless required by applicable law or agreed to in writing, software

0 commit comments

Comments
 (0)