Skip to content

Commit 25d87d2

Browse files
committed
Merge branch 'flake8'
2 parents 4ccf8ab + 01b01fe commit 25d87d2

File tree

8 files changed

+81
-63
lines changed

8 files changed

+81
-63
lines changed

.travis.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ python:
1010
- 3.5
1111
- 3.6
1212
- pypy
13+
- flake8
1314
install: travis_retry pip install tox-travis
1415
services:
1516
#- mongodb
@@ -27,4 +28,4 @@ before_script:
2728
# timer is needed in order to get mongo to properly initialize on travis-ci
2829
# See https://github.com/travis-ci/travis-ci/issues/1967#issuecomment-42008605
2930
- "${PWD}/mongodb-linux-x86_64-3.4.7/bin/mongo eve_test --eval 'db.createUser({\"user\": \"test_user\", \"pwd\": \"test_pw\", \"roles\": [\"readWrite\", \"dbAdmin\"]},{\"w\": \"majority\" , \"wtimeout\": 5000 })'"
30-
#- mongo eve_test --eval 'db.addUser("test_user", "test_pw");'
31+
#- mongo eve_test --eval 'db.addUser("test_user", "test_pw");'

eve/flaskapp.py

+34-33
Original file line numberDiff line numberDiff line change
@@ -439,32 +439,34 @@ def validate_field_name(field):
439439
'(they will be handled automatically).'
440440
% (', '.join(offenders), resource))
441441

442-
if isinstance(schema, dict):
443-
for field, ruleset in schema.items():
444-
validate_field_name(field)
445-
if isinstance(ruleset, dict) and 'dict' in ruleset.get('type', ''):
446-
for field in ruleset.get('schema', {}).keys():
447-
validate_field_name(field)
448-
449-
# check data_relation rules
450-
if 'data_relation' in ruleset:
451-
if 'resource' not in ruleset['data_relation']:
452-
raise SchemaException("'resource' key is mandatory for "
453-
"the 'data_relation' rule in "
454-
"'%s: %s'" % (resource, field))
455-
if ruleset['data_relation'].get('embeddable', False):
456-
457-
# special care for data_relations with a version
458-
value_field = ruleset['data_relation']['field']
459-
if ruleset['data_relation'].get('version', False):
460-
if 'schema' not in ruleset or \
461-
value_field not in ruleset['schema'] or \
462-
'type' not in ruleset['schema'][value_field]:
463-
raise SchemaException(
464-
"Must defined type for '%s' in schema when "
465-
"declaring an embedded data_relation with"
466-
" version." % value_field
467-
)
442+
if not isinstance(schema, dict):
443+
return
444+
445+
for field, ruleset in schema.items():
446+
validate_field_name(field)
447+
if isinstance(ruleset, dict) and 'dict' in ruleset.get('type', ''):
448+
for field in ruleset.get('schema', {}).keys():
449+
validate_field_name(field)
450+
451+
# check data_relation rules
452+
if 'data_relation' in ruleset:
453+
if 'resource' not in ruleset['data_relation']:
454+
raise SchemaException("'resource' key is mandatory for "
455+
"the 'data_relation' rule in "
456+
"'%s: %s'" % (resource, field))
457+
if ruleset['data_relation'].get('embeddable', False):
458+
459+
# special care for data_relations with a version
460+
value_field = ruleset['data_relation']['field']
461+
if ruleset['data_relation'].get('version', False):
462+
if 'schema' not in ruleset or \
463+
value_field not in ruleset['schema'] or \
464+
'type' not in ruleset['schema'][value_field]:
465+
raise SchemaException(
466+
"Must defined type for '%s' in schema when "
467+
"declaring an embedded data_relation with"
468+
" version." % value_field
469+
)
468470

469471
# TODO are there other mandatory settings? Validate them here
470472

@@ -690,16 +692,15 @@ def _set_resource_projection(self, ds, schema, settings):
690692

691693
# list of all media fields for the resource
692694
if isinstance(schema, dict):
693-
settings['_media'] = [field for field, definition in schema.items() if
694-
isinstance(definition, dict) and
695-
(definition.get('type') == 'media' or
696-
(definition.get('type') == 'list' and
697-
definition.get('schema', {}).get('type') ==
698-
'media'))]
695+
settings['_media'] = [field for field, definition in schema.items()
696+
if isinstance(definition, dict) and
697+
(definition.get('type') == 'media' or
698+
(definition.get('type') == 'list' and
699+
definition.get('schema', {}).get('type') ==
700+
'media'))]
699701
else:
700702
settings['_media'] = []
701703

702-
703704
if settings['_media'] and not self.media:
704705
raise ConfigException('A media storage class of type '
705706
' eve.io.media.MediaStorage must be defined '

eve/io/mongo/mongo.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class Mongo(DataLayer):
105105
['$options', '$search', '$language'] +
106106
['$exists', '$type'] +
107107
['$geoWithin', '$geoIntersects', '$near', '$nearSphere'] +
108-
['$all', '$elemMatch', '$size'] +
108+
['$all', '$elemMatch', '$size'] +
109109
['$bitsAllClear', '$bitsAllSet', '$bitsAnyClear', '$bitsAnySet']
110110
)
111111

eve/methods/common.py

+30-20
Original file line numberDiff line numberDiff line change
@@ -434,13 +434,16 @@ def serialize(document, resource=None, schema=None, fields=None):
434434
for x_of in ['allof', 'anyof', 'oneof', 'noneof']:
435435
for optschema in field_schema.get(x_of, []):
436436
serialize(document,
437-
schema={field: {'type': field_type,
438-
'schema': optschema}})
437+
schema={
438+
field: {'type': field_type,
439+
'schema': optschema}})
439440
x_of_type = '{0}_type'.format(x_of)
440441
for opttype in field_schema.get(x_of_type, []):
441-
serialize(document,
442-
schema={field: {'type': field_type,
443-
'schema': {'type': opttype}}})
442+
serialize(
443+
document,
444+
schema={field: {'type': field_type,
445+
'schema': {'type':
446+
opttype}}})
444447
else:
445448
# a list of one type, arbitrary length
446449
field_type = field_schema.get('type')
@@ -701,7 +704,8 @@ def embedded_document(references, data_relation, field_name):
701704

702705
# Retrieve and serialize the requested document
703706
if 'version' in data_relation and data_relation['version'] is True:
704-
# For the version flow, I keep the as-is logic (flow is too complex to make it bulk)
707+
# For the version flow, I keep the as-is logic (flow is too complex to
708+
# make it bulk)
705709
for reference in references:
706710
# grab the specific version
707711
embedded_doc = get_data_version_relation_document(
@@ -724,25 +728,28 @@ def embedded_document(references, data_relation, field_name):
724728
[], latest_embedded_doc)
725729
embedded_docs.append(embedded_doc)
726730
else:
727-
id_value_to_sort, list_of_id_field_name, subresources_query = generate_query_and_sorting_criteria(data_relation,
728-
references)
731+
id_value_to_sort, list_of_id_field_name, subresources_query = \
732+
generate_query_and_sorting_criteria(data_relation, references)
729733
for subresource in subresources_query:
730-
list_embedded_doc = list(app.data.find(subresource,
731-
None,
732-
subresources_query[subresource]))
734+
list_embedded_doc = list(
735+
app.data.find(subresource, None,
736+
subresources_query[subresource]))
737+
733738
if not list_embedded_doc:
734-
embedded_docs.extend([None] *
735-
len(subresources_query[subresource]["$or"]))
739+
embedded_docs.extend(
740+
[None] * len(subresources_query[subresource]["$or"]))
736741
else:
737742
for embedded_doc in list_embedded_doc:
738743
resolve_media_files(embedded_doc, subresource)
739744
embedded_docs.extend(list_embedded_doc)
740745

741-
# After having retrieved my data, I have to be sure that the sorting of the
742-
# list is the same in input as in output (this is to support embedding of
743-
# sub-documents - only in case the storage is not done via DBref)
746+
# After having retrieved my data, I have to be sure that the sorting of
747+
# the list is the same in input as in output (this is to support
748+
# embedding of sub-documents - only in case the storage is not done via
749+
# DBref)
744750
if embedded_docs:
745-
embedded_docs = sort_db_response(embedded_docs, id_value_to_sort, list_of_id_field_name)
751+
embedded_docs = sort_db_response(embedded_docs, id_value_to_sort,
752+
list_of_id_field_name)
746753

747754
if output_is_list:
748755
return embedded_docs
@@ -766,7 +773,8 @@ def sort_db_response(embedded_docs, id_value_to_sort, list_of_id_field_name):
766773
old_occurrence = 0
767774

768775
for id_field_name in set(list_of_id_field_name):
769-
current_occurrence = old_occurrence + int(id_field_name_occurrences[id_field_name])
776+
current_occurrence = old_occurrence + int(id_field_name_occurrences[
777+
id_field_name])
770778
temp_embedded_docs.extend(
771779
sort_per_resource(embedded_docs[old_occurrence:current_occurrence],
772780
id_value_to_sort,
@@ -805,9 +813,11 @@ def generate_query_and_sorting_criteria(data_relation, references):
805813
:param data_relation: data relation for the resource.
806814
:param references: DBRef or id to use to embed the document.
807815
:returns id_value_to_sort: list of ids to use in the sort
808-
list_of_id_field_name: list of field name (important only for DBRef)
816+
list_of_id_field_name: list of field name (important only for
817+
DBRef)
809818
subresources_query: the list of query to perform per resource
810-
(in case is not DBRef, it will be only one query)
819+
(in case is not DBRef, it will be only one
820+
query)
811821
"""
812822
query = {"$or": []}
813823
subresources_query = {}

eve/tests/methods/common.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ def test_mongo_serializes(self):
7878
self.assertTrue(isinstance(ks['foo1'], ObjectId))
7979
self.assertTrue(isinstance(ks['foo2'], ObjectId))
8080
self.assertTrue(isinstance(res['refobj'], DBRef))
81-
self.assertTrue(isinstance(res['decobjstring'], decimal128.Decimal128))
82-
self.assertTrue(isinstance(res['decobjnumber'], decimal128.Decimal128))
81+
self.assertTrue(isinstance(res['decobjstring'],
82+
decimal128.Decimal128))
83+
self.assertTrue(isinstance(res['decobjnumber'],
84+
decimal128.Decimal128))
8385

8486
def test_non_blocking_on_simple_field_serialization_exception(self):
8587
schema = {
@@ -352,7 +354,8 @@ def test_serialize_alongside_x_of_rules(self):
352354
}),
353355
('oid-field', {'type': 'objectid'})
354356
])
355-
doc = OrderedDict([('x_of-field', '50656e4538345b39dd0414f0'), ('oid-field', '50656e4538345b39dd0414f0')])
357+
doc = OrderedDict([('x_of-field', '50656e4538345b39dd0414f0'),
358+
('oid-field', '50656e4538345b39dd0414f0')])
356359
with self.app.app_context():
357360
serialized = serialize(doc, schema=schema)
358361
self.assertTrue(isinstance(serialized['x_of-field'], ObjectId))
@@ -372,7 +375,8 @@ def test_serialize_list_alongside_x_of_rules(self):
372375
doc = {'x_of-field': ['50656e4538345b39dd0414f0']}
373376
with self.app.app_context():
374377
serialized = serialize(doc, schema=schema)
375-
self.assertTrue(isinstance(serialized['x_of-field'][0], ObjectId))
378+
self.assertTrue(isinstance(serialized['x_of-field'][0],
379+
ObjectId))
376380

377381
def test_serialize_inside_nested_x_of_rules(self):
378382
schema = {

eve/tests/methods/delete.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ def test_bulk_delete_id_field(self):
2626
self.app.config["IF_MATCH"] = False
2727
products, _ = self.get(self.products)
2828
list_products_skus = [product["parent_product"] for product in
29-
products["_items"] if "parent_product" in product]
29+
products["_items"] if "parent_product" in
30+
product]
3031
# Deletion of all the product in the first cart
3132
url = self.child_products_url.replace(
3233
'<regex("[A-Z]+"):parent_product>', list_products_skus[0])

eve/tests/methods/post.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from base64 import b64decode
2-
from bson import ObjectId, decimal128
2+
from bson import ObjectId
33

44
import simplejson as json
55

tox.ini

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ commands=python setup.py test {posargs}
77
[testenv:flake8]
88
deps=flake8
99
basepython=python2
10-
commands=flake8 --ignore=E731 eve {posargs}
10+
commands=flake8 --ignore=E731,E722 eve {posargs}
1111

1212
[tox:travis]
1313
2.6 = py26
1414
2.7 = py27
1515
3.3 = py33
1616
3.4 = py34
17-
3.5 = py35,flake
17+
3.5 = py35
1818
3.6 = py36
1919
pypy = pypy
20+
flake8 = flake8

0 commit comments

Comments
 (0)