How to use the flake8.api.legacy.get_style_guide function in flake8

To help you get started, we’ve selected a few flake8 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NicolasHug / Surprise / tests / test_pep8.py View on Github external
def test_cython_files():

    style_guide = flake8.get_style_guide(
        filename=['*.pyx', '*.px'],
        exclude=['doc', '.eggs', '*.egg', 'build', 'setup.py'],
        select=['E', 'W', 'F'],
        ignore=['E225'],
        max_line_length=88
    )

    report = style_guide.check_files()
github quattor / aquilon / tests / codestyle.py View on Github external
args.from_ref = '{}^'.format(args.to_ref)

    # If provided, set the path to the git binary for GitPython
    if args.git_bin is not None:
        os.environ['GIT_PYTHON_GIT_EXECUTABLE'] = os.path.abspath(args.git_bin)
    # The following is done to insure that we import git only after setting
    # the environment variable to specify the path to the git bin received on
    # the command line
    global git
    import git

    # Move to the git directory
    os.chdir(args.git_dir)

    # Prepare the Flake8 checker
    flake8style = flake8.get_style_guide(
        quiet=True,
        # No need to select or ignore anything, it should pick-up the project
        # configuration when run from the project directory
    )
    flake8style.init_report(reporter=Flake8DictReport)

    if args.all:
        checkerhandler_cls = CheckerHandler
    elif args.staged:
        checkerhandler_cls = CheckerHandlerStaged
    else:
        checkerhandler_cls = CheckerHandlerCommits

    checkerhandler_args = vars(args)
    checkerhandler_args.update(git_dir='.')
    checkerhandler = checkerhandler_cls(**checkerhandler_args)
github colcon / colcon-bundle / test / test_flake8.py View on Github external
def test_flake8():
    style_guide = get_style_guide(extend_ignore=['D100', 'D104'],
                                  show_source=True)
    style_guide_tests = get_style_guide(
        extend_ignore=[
            'D100', 'D101', 'D102', 'D103', 'D104', 'D105', 'D107'],
        show_source=True, )

    stdout = sys.stdout
    sys.stdout = sys.stderr
    # implicitly calls report_errors()
    report = style_guide.check_files(
        [str(Path(__file__).parents[1] / 'colcon_bundle')])
    report_tests = style_guide_tests.check_files(
        [str(Path(__file__).parents[1] / 'tests')])
    sys.stdout = stdout

    total_errors = report.total_errors + report_tests.total_errors
    if total_errors:  # pragma: no cover
        # output summary with per-category counts
github PyCQA / flake8 / tests / unit / test_legacy_api.py View on Github external
append_config=[],
        config=None,
        isolated=False,
        output_file=None,
        verbose=0,
    )
    mockedapp = mock.Mock()
    mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
    mockedapp.program = 'flake8'
    with mock.patch('flake8.api.legacy.config.ConfigFileFinder') as mock_config_finder:  # noqa: E501
        config_finder = ConfigFileFinder(mockedapp.program, [])
        mock_config_finder.return_value = config_finder

        with mock.patch('flake8.main.application.Application') as application:
            application.return_value = mockedapp
            style_guide = api.get_style_guide()

    application.assert_called_once_with()
    mockedapp.parse_preliminary_options.assert_called_once_with([])
    mockedapp.find_plugins.assert_called_once_with(config_finder, None, False)
    mockedapp.register_plugin_options.assert_called_once_with()
    mockedapp.parse_configuration_and_cli.assert_called_once_with(
        config_finder, [])
    mockedapp.make_formatter.assert_called_once_with()
    mockedapp.make_guide.assert_called_once_with()
    mockedapp.make_file_checker_manager.assert_called_once_with()
    assert isinstance(style_guide, api.StyleGuide)
github GatorIncubator / gatorgrouper / tests / test_gatorgrouper.py View on Github external
def test_flake8():

    # list of all file names to be checked for PEP8
    filenames = list()

    # fill list with all python files found in all subdirectories
    for root, dirs, files in os.walk("gatorgrouper", topdown=False):
        pyFiles = glob.glob(root + "/*.py")
        filenames.extend(pyFiles)

    style_guide = flake8.get_style_guide(ignore=["E265", "E501"])
    report = style_guide.check_files(filenames)
    assert report.get_statistics('E') == [], 'Flake8 found violations'
github Edurate / edurate / linting.py View on Github external
def test_flake8():

    # list of all file names to be checked for PEP8
    filenames = list()

    # fill list with all python files found in all subdirectories
    for root, dirs, files in os.walk("edurate", topdown=False):
        pyFiles = glob.glob(root + "/*.py")
        filenames.extend(pyFiles)

    style_guide = flake8.get_style_guide(ignore=["E265", "E501"])
    report = style_guide.check_files(filenames)
    assert report.get_statistics('E') == [], 'Flake8 found violations'
github kmmbvnr / django-jenkins / django_jenkins / tasks / run_flake8.py View on Github external
default=pep8.DEFAULT_EXCLUDE + ",south_migrations", split=',')

        set_option(pep8_options, 'select', options['pep8-select'], config_file, split=',')

        set_option(pep8_options, 'ignore', options['pep8-ignore'], config_file, split=',')

        set_option(pep8_options, 'max_line_length', options['pep8-max-line-length'], config_file,
                   default=pep8.MAX_LINE_LENGTH)

        set_option(pep8_options, 'max_complexity', options['flake8-max-complexity'], config_file,
                   default=-1)

        old_stdout, flake8_output = sys.stdout, StringIO()
        sys.stdout = flake8_output

        pep8style = get_style_guide(
            parse_argv=False,
            jobs='1',
            **pep8_options)

        try:
            for location in apps_locations:
                pep8style.input_file(os.path.relpath(location))
        finally:
            sys.stdout = old_stdout

        flake8_output.seek(0)
        output.write(flake8_output.read())
        output.close()