Run flake8.

def _run_flake8_internal(filename):
    """Run flake8."""
    from flake8.engine import get_style_guide
    from pep8 import BaseReport
    from prospector.message import Message, Location

    return_dict = dict()

    cwd = os.getcwd()

    class Flake8MergeReporter(BaseReport):
        """An implementation of pep8.BaseReport merging results.

        This implementation merges results from the flake8 report
        into the prospector report created earlier.
        """

        def __init__(self, options):
            """Initialize this Flake8MergeReporter."""
            super(Flake8MergeReporter, self).__init__(options)
            self._current_file = ""

        def init_file(self, filename, lines, expected, line_offset):
            """Start processing filename."""
            relative_path = os.path.join(cwd, filename)
            self._current_file = os.path.realpath(relative_path)

            super(Flake8MergeReporter, self).init_file(filename,
                                                       lines,
                                                       expected,
                                                       line_offset)

        def error(self, line_number, offset, text, check):
            """Record error and store in return_dict."""
            code = super(Flake8MergeReporter, self).error(line_number,
                                                          offset,
                                                          text,
                                                          check) or "no-code"

            key = _Key(self._current_file, line_number, code)
            return_dict[key] = Message(code,
                                       code,
                                       Location(self._current_file,
                                                None,
                                                None,
                                                line_number,
                                                offset),
                                       text[5:])

    flake8_check_paths = [filename]
    get_style_guide(reporter=Flake8MergeReporter,
                    jobs="1").check_files(paths=flake8_check_paths)

    return return_dict