Fixing flake8 warnings and errors

flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics --exclude benchmark

Excluding the benchmark directory (due to protobuf generated files)
Also removing some Python2 specific code
This commit is contained in:
Jacob Alexander
2019-09-26 22:18:28 -07:00
parent 1f0200af9c
commit b3021e4f6b
37 changed files with 536 additions and 452 deletions

View File

@@ -31,8 +31,26 @@ Example Usage::
for phone in person.phones:
print(phone.type, ':', phone.number)
"""
# flake8: noqa F401 F403 F405
from .version import version as __version__
from .lib.capnp import *
from .lib.capnp import _DynamicStructReader, _DynamicStructBuilder, _DynamicResizableListBuilder, _DynamicListReader, _DynamicListBuilder, _DynamicOrphan, _DynamicResizableListBuilder, _MallocMessageBuilder, _PackedFdMessageReader, _StreamFdMessageReader, _write_message_to_fd, _write_packed_message_to_fd, _StructModule, _InterfaceModule, _DynamicCapabilityClient, _CapabilityClient, _EventLoop
from .lib.capnp import (
_CapabilityClient,
_DynamicCapabilityClient,
_DynamicListBuilder,
_DynamicListReader,
_DynamicOrphan,
_DynamicResizableListBuilder,
_DynamicStructBuilder,
_DynamicStructReader,
_EventLoop,
_InterfaceModule,
_MallocMessageBuilder,
_PackedFdMessageReader,
_StreamFdMessageReader,
_StructModule,
_write_message_to_fd,
_write_packed_message_to_fd,
)
add_import_hook() # enable import hook by default

View File

@@ -7,58 +7,58 @@ from jinja2 import Environment, PackageLoader
import os
def find_type(code, id):
for node in code['nodes']:
if node['id'] == id:
return node
for node in code['nodes']:
if node['id'] == id:
return node
return None
return None
def main():
env = Environment(loader=PackageLoader('capnp', 'templates'))
env.filters['format_name'] = lambda name: name[name.find(':')+1:]
env = Environment(loader=PackageLoader('capnp', 'templates'))
env.filters['format_name'] = lambda name: name[name.find(':') + 1:]
code = schema_capnp.CodeGeneratorRequest.read(sys.stdin)
code=code.to_dict()
code['nodes'] = [node for node in code['nodes'] if 'struct' in node and node['scopeId'] != 0]
for node in code['nodes']:
displayName = node['displayName']
parent, path = displayName.split(':')
node['module_path'] = parent.replace('.', '_') + '.' + '.'.join([x[0].upper() + x[1:] for x in path.split('.')])
node['module_name'] = path.replace('.', '_')
node['c_module_path'] = '::'.join([x[0].upper() + x[1:] for x in path.split('.')])
node['schema'] = '_{}_Schema'.format(node['module_name'])
is_union = False
for field in node['struct']['fields']:
if field['discriminantValue'] != 65535:
is_union = True
field['c_name'] = field['name'][0].upper() + field['name'][1:]
if 'slot' in field:
field['type'] = field['slot']['type'].keys()[0]
if not isinstance(field['slot']['type'][field['type']], dict):
continue
sub_type = field['slot']['type'][field['type']].get('typeId', None)
if sub_type:
field['sub_type'] = find_type(code, sub_type)
sub_type = field['slot']['type'][field['type']].get('elementType', None)
if sub_type:
field['sub_type'] = sub_type
else:
field['type'] = find_type(code, field['group']['typeId'])
node['is_union'] = is_union
code = schema_capnp.CodeGeneratorRequest.read(sys.stdin)
code = code.to_dict()
code['nodes'] = [node for node in code['nodes'] if 'struct' in node and node['scopeId'] != 0]
for node in code['nodes']:
displayName = node['displayName']
parent, path = displayName.split(':')
node['module_path'] = parent.replace('.', '_') + '.' + '.'.join([x[0].upper() + x[1:] for x in path.split('.')])
node['module_name'] = path.replace('.', '_')
node['c_module_path'] = '::'.join([x[0].upper() + x[1:] for x in path.split('.')])
node['schema'] = '_{}_Schema'.format(node['module_name'])
is_union = False
for field in node['struct']['fields']:
if field['discriminantValue'] != 65535:
is_union = True
field['c_name'] = field['name'][0].upper() + field['name'][1:]
if 'slot' in field:
field['type'] = field['slot']['type'].keys()[0]
if not isinstance(field['slot']['type'][field['type']], dict):
continue
sub_type = field['slot']['type'][field['type']].get('typeId', None)
if sub_type:
field['sub_type'] = find_type(code, sub_type)
sub_type = field['slot']['type'][field['type']].get('elementType', None)
if sub_type:
field['sub_type'] = sub_type
else:
field['type'] = find_type(code, field['group']['typeId'])
node['is_union'] = is_union
include_dir = os.path.abspath(os.path.join(os.path.dirname(capnp.__file__), '..'))
module = env.get_template('module.pyx')
include_dir = os.path.abspath(os.path.join(os.path.dirname(capnp.__file__), '..'))
module = env.get_template('module.pyx')
for f in code['requestedFiles']:
filename = f['filename'].replace('.', '_') + '_cython.pyx'
for f in code['requestedFiles']:
filename = f['filename'].replace('.', '_') + '_cython.pyx'
file_code = dict(code)
file_code['nodes'] = [node for node in file_code['nodes'] if node['displayName'].startswith(f['filename'])]
with open(filename, 'w') as out:
out.write(module.render(code=file_code, file=f, include_dir=include_dir))
file_code = dict(code)
file_code['nodes'] = [node for node in file_code['nodes'] if node['displayName'].startswith(f['filename'])]
with open(filename, 'w') as out:
out.write(module.render(code=file_code, file=f, include_dir=include_dir))
setup = env.get_template('setup.py.tmpl')
with open('setup_capnp.py', 'w') as out:
out.write(setup.render(code=code))
print('You now need to build the cython module by running `python setup_capnp.py build_ext --inplace`.')
print()
setup = env.get_template('setup.py.tmpl')
with open('setup_capnp.py', 'w') as out:
out.write(setup.render(code=code))
print('You now need to build the cython module by running `python setup_capnp.py build_ext --inplace`.')
print()