cmake: Make flake8 happy

pull/4969/head
Daniel Mensinger 6 years ago
parent 703054903b
commit af6448ced5
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 18
      mesonbuild/cmake/client.py
  2. 26
      mesonbuild/cmake/interpreter.py

@ -48,8 +48,8 @@ CMAKE_REPLY_TYPES = {
# Base CMake server message classes # Base CMake server message classes
class MessageBase: class MessageBase:
def __init__(self, type: str, cookie: str): def __init__(self, msg_type: str, cookie: str):
self.type = type self.type = msg_type
self.cookie = cookie self.cookie = cookie
def to_dict(self) -> dict: def to_dict(self) -> dict:
@ -61,8 +61,8 @@ class MessageBase:
class RequestBase(MessageBase): class RequestBase(MessageBase):
cookie_counter = 0 cookie_counter = 0
def __init__(self, type: str): def __init__(self, msg_type: str):
super().__init__(type, self.gen_cookie()) super().__init__(msg_type, self.gen_cookie())
@staticmethod @staticmethod
def gen_cookie(): def gen_cookie():
@ -404,13 +404,13 @@ class CMakeClient:
raw_data = self.readMessageRaw() raw_data = self.readMessageRaw()
if 'type' not in raw_data: if 'type' not in raw_data:
raise CMakeException('The "type" attribute is missing from the message') raise CMakeException('The "type" attribute is missing from the message')
type = raw_data['type'] msg_type = raw_data['type']
func = self.type_map.get(type, None) func = self.type_map.get(msg_type, None)
if not func: if not func:
raise CMakeException('Recieved unknown message type "{}"'.format(type)) raise CMakeException('Recieved unknown message type "{}"'.format(msg_type))
for i in CMAKE_MESSAGE_TYPES[type]: for i in CMAKE_MESSAGE_TYPES[msg_type]:
if i not in raw_data: if i not in raw_data:
raise CMakeException('Key "{}" is missing from CMake server message type {}'.format(i, type)) raise CMakeException('Key "{}" is missing from CMake server message type {}'.format(i, msg_type))
return func(raw_data) return func(raw_data)
def writeMessage(self, msg: MessageBase) -> None: def writeMessage(self, msg: MessageBase) -> None:

@ -414,7 +414,7 @@ class CMakeInterpreter:
def string(value: str) -> StringNode: def string(value: str) -> StringNode:
return StringNode(token(val=value)) return StringNode(token(val=value))
def id(value: str) -> IdNode: def id_node(value: str) -> IdNode:
return IdNode(token(val=value)) return IdNode(token(val=value))
def nodeify(value): def nodeify(value):
@ -433,7 +433,11 @@ class CMakeInterpreter:
args.arguments += [nodeify(x) for x in elements] args.arguments += [nodeify(x) for x in elements]
return ArrayNode(args, 0, 0, 0, 0) return ArrayNode(args, 0, 0, 0, 0)
def function(name: str, args=[], kwargs={}) -> FunctionNode: def function(name: str, args=None, kwargs=None) -> FunctionNode:
if args is None:
args = []
if kwargs is None:
kwargs = {}
args_n = ArgumentNode(token()) args_n = ArgumentNode(token())
if not isinstance(args, list): if not isinstance(args, list):
args = [args] args = [args]
@ -442,7 +446,11 @@ class CMakeInterpreter:
func_n = FunctionNode(self.subdir, 0, 0, 0, 0, name, args_n) func_n = FunctionNode(self.subdir, 0, 0, 0, 0, name, args_n)
return func_n return func_n
def method(obj: BaseNode, name: str, args=[], kwargs={}) -> MethodNode: def method(obj: BaseNode, name: str, args=None, kwargs=None) -> MethodNode:
if args is None:
args = []
if kwargs is None:
kwargs = {}
args_n = ArgumentNode(token()) args_n = ArgumentNode(token())
if not isinstance(args, list): if not isinstance(args, list):
args = [args] args = [args]
@ -466,7 +474,7 @@ class CMakeInterpreter:
assert(isinstance(i, ConverterTarget)) assert(isinstance(i, ConverterTarget))
if i.name not in processed: if i.name not in processed:
process_target(i) process_target(i)
link_with += [id(processed[i.name]['tgt'])] link_with += [id_node(processed[i.name]['tgt'])]
for i in tgt.object_libs: for i in tgt.object_libs:
assert(isinstance(i, ConverterTarget)) assert(isinstance(i, ConverterTarget))
if i.name not in processed: if i.name not in processed:
@ -490,11 +498,11 @@ class CMakeInterpreter:
tgt_kwargs = { tgt_kwargs = {
'link_args': tgt.link_flags + tgt.link_libraries, 'link_args': tgt.link_flags + tgt.link_libraries,
'link_with': link_with, 'link_with': link_with,
'include_directories': id(inc_var), 'include_directories': id_node(inc_var),
'install': tgt.install, 'install': tgt.install,
'install_dir': tgt.install_dir, 'install_dir': tgt.install_dir,
'override_options': tgt.override_options, 'override_options': tgt.override_options,
'objects': [method(id(x), 'extract_all_objects') for x in objec_libs], 'objects': [method(id_node(x), 'extract_all_objects') for x in objec_libs],
} }
# Handle compiler args # Handle compiler args
@ -510,14 +518,14 @@ class CMakeInterpreter:
# declare_dependency kwargs # declare_dependency kwargs
dep_kwargs = { dep_kwargs = {
'link_args': tgt.link_flags + tgt.link_libraries, 'link_args': tgt.link_flags + tgt.link_libraries,
'link_with': id(tgt_var), 'link_with': id_node(tgt_var),
'include_directories': id(inc_var), 'include_directories': id_node(inc_var),
} }
# Generate the function nodes # Generate the function nodes
inc_node = assign(inc_var, function('include_directories', tgt.includes)) inc_node = assign(inc_var, function('include_directories', tgt.includes))
src_node = assign(src_var, function('files', tgt.sources + tgt.generated)) src_node = assign(src_var, function('files', tgt.sources + tgt.generated))
tgt_node = assign(tgt_var, function(tgt_func, [base_name, id(src_var)], tgt_kwargs)) tgt_node = assign(tgt_var, function(tgt_func, [base_name, id_node(src_var)], tgt_kwargs))
dep_node = assign(dep_var, function('declare_dependency', kwargs=dep_kwargs)) dep_node = assign(dep_var, function('declare_dependency', kwargs=dep_kwargs))
# Add the nodes to the ast # Add the nodes to the ast

Loading…
Cancel
Save