Exemple #1
0
def main():
    global pep8style
    pep8style = pep8.StyleGuide(parse_argv=True, config_file=True)
    options = pep8style.options
    complexity = options.max_complexity
    builtins = set(options.builtins)
    warnings = 0

    if builtins:
        orig_builtins = set(pyflakes._MAGIC_GLOBALS)
        pyflakes._MAGIC_GLOBALS = orig_builtins | builtins

    if pep8style.paths and options.filename is not None:
        for path in _get_python_files(pep8style.paths):
            warnings += check_file(path, options.ignore, complexity)
    else:
        # wait for 1 second on the stdin fd
        reads, __, __ = select.select([sys.stdin], [], [], 1.)
        if reads == []:
            print('input not specified')
            raise SystemExit(1)

        stdin = sys.stdin.read()
        warnings += check_code(stdin, complexity)

    if options.exit_zero:
        raise SystemExit(0)
    raise SystemExit(warnings > 0)
Exemple #2
0
def _initpep8():
    # default pep8 setup
    global pep8style
    if pep8style is None:
        pep8style = pep8.StyleGuide(config_file=True)
    pep8.options = _PEP8Options()
    pep8.options.physical_checks = pep8.find_checks('physical_line')
    pep8.options.logical_checks = pep8.find_checks('logical_line')
    pep8.options.counters = dict.fromkeys(pep8.BENCHMARK_KEYS, 0)
    pep8.options.messages = {}
    pep8.options.max_line_length = 79
    pep8.args = []
    def teardown_test_environment(self, **kwargs):
        # Local import to avoid intallation errors.
        import flake8.run

        locations = get_apps_locations(
            self.test_labels,
            self.test_all
        )

        paths = flake8.run._get_python_files(locations)
        flake8.run.pep8style = pep8.StyleGuide(
            parse_argv=False,
            config_file=False
        )
        old_stdout, flake8_output = sys.stdout, BytesIO()
        sys.stdout = flake8_output
        warnings = 0
        for path in paths:
            # We could pass ignore paths
            # but I need to figure out first how to do it
            warnings += flake8.run.check_file(
                path,
                complexity=self.max_complexity
            )

        sys.stdout = old_stdout

        flake8_output.seek(0)

        while True:
            line = flake8_output.readline()
            if not line:
                break

            # Make sure the path is relative in the report
            bits = line.split(':')
            bits[0] = relpath(bits[0])
            self.output.write(':'.join(bits))

        self.output.close()