def build_messages_modules(messages):
data = collections.defaultdict(list)<EOL>for line in messages:<EOL><INDENT>module_name = line.get('<STR_LIT>')<EOL>module_path = line.get('<STR_LIT:path>')<EOL>module_info = ModuleInfo(<EOL>module_name,<EOL>module_path,<EOL>)<EOL>data[module_info].append(line)<EOL><DEDENT>for module, module_messages in data.items():<EOL><INDENT>yield (<EOL>module,<EOL>sorted(module_messages, key=lambda x: x.get('<STR_LIT>')))<EOL><DEDENT>
Build and yield sorted list of messages per module.

    :param list messages: List of dict of messages
    :return: Tuple of 2 values: first is the module info, second is the list
             of messages sorted by line number