How to use the flake8.main.application.Application 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 Azure / azure-cli-extensions / scripts / ci / test_static.py View on Github external
def _run_flake8(module_paths, config_file=None):
    flake8_opts = ["--statistics"]

    if config_file:
        flake8_opts.append("--append-config={}".format(config_file))

    flake8_opts.extend(module_paths)

    app = application.Application()
    app.run(flake8_opts)
    try:
        app.exit()
    except SystemExit:
        pass

    if app.result_count > 0 or app.catastrophic_failure:
        sys.exit(app.result_count or 1)
github PyCQA / flake8 / tests / integration / test_plugins.py View on Github external
def test_enable_local_plugin_at_non_installed_path():
    """Can add a paths option in local-plugins config section for finding."""
    app = application.Application()
    app.initialize(['flake8', '--config', LOCAL_PLUGIN_PATH_CONFIG])

    assert app.check_plugins['XE'].plugin.name == 'ExtensionTestPlugin2'
github ros-infrastructure / ros_buildfarm / test / test_flake8.py View on Github external
def get_style_guide(argv=None):
    # this is a fork of flake8.api.legacy.get_style_guide
    # to allow passing command line argument
    application = Application()
    if not hasattr(application, 'parse_preliminary_options_and_args'):  # flake8 >= 3.8
        prelim_opts, remaining_args = application.parse_preliminary_options(argv)
        config_finder = config.ConfigFileFinder(
            application.program,
            prelim_opts.append_config,
            config_file=prelim_opts.config,
            ignore_config_files=prelim_opts.isolated,
        )
        application.find_plugins(config_finder)
        application.register_plugin_options()
        application.parse_configuration_and_cli(config_finder, remaining_args)
    else:
        application.parse_preliminary_options_and_args(argv)
        configure_logging(
            application.prelim_opts.verbose, application.prelim_opts.output_file)
        application.make_config_finder()
github dirk-thomas / vcstool / test / test_flake8.py View on Github external
def get_style_guide(argv=None):
    # this is a fork of flake8.api.legacy.get_style_guide
    # to allow passing command line argument
    application = Application()
    application.parse_preliminary_options_and_args([])
    application.make_config_finder()
    application.find_plugins()
    application.register_plugin_options()
    application.parse_configuration_and_cli(argv)
    application.make_formatter()
    application.make_guide()
    application.make_file_checker_manager()
    return StyleGuide(application)
github Azure / azure-cli-extensions / scripts / ci / source_code_static_analysis.py View on Github external
def _run_flake8(module_paths, config_file=None):
    flake8_opts = ["--statistics"]

    if config_file:
        flake8_opts.append("--append-config={}".format(config_file))

    flake8_opts.extend(module_paths)

    app = application.Application()
    app.run(flake8_opts)
    try:
        app.exit()
    except SystemExit:
        pass

    if app.result_count > 0 or app.catastrophic_failure:
        sys.exit(app.result_count or 1)
github PyCQA / flake8 / src / flake8 / api / legacy.py View on Github external
def get_style_guide(**kwargs):
    r"""Provision a StyleGuide for use.

    :param \*\*kwargs:
        Keyword arguments that provide some options for the StyleGuide.
    :returns:
        An initialized StyleGuide
    :rtype:
        :class:`StyleGuide`
    """
    application = app.Application()
    prelim_opts, remaining_args = application.parse_preliminary_options([])
    flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
    config_finder = config.ConfigFileFinder(
        application.program, prelim_opts.append_config
    )

    application.find_plugins(
        config_finder, prelim_opts.config, prelim_opts.isolated
    )
    application.register_plugin_options()
    application.parse_configuration_and_cli(config_finder, remaining_args)
    # We basically want application.initialize to be called but with these
    # options set instead before we make our formatter, notifier, internal
    # style guide and file checker manager.
    options = application.options
    for key, value in kwargs.items():
github PyCQA / flake8 / src / flake8 / main / git.py View on Github external
:param bool lazy:
        Find files not added to the index prior to committing. This is useful
        if you frequently use ``git commit -a`` for example. This defaults to
        False since it will otherwise include files not in the index.
    :param bool strict:
        If True, return the total number of errors/violations found by Flake8.
        This will cause the hook to fail.
    :returns:
        Total number of errors found during the run.
    :rtype:
        int
    """
    # NOTE(sigmavirus24): Delay import of application until we need it.
    from flake8.main import application

    app = application.Application()
    with make_temporary_directory() as tempdir:
        filepaths = list(copy_indexed_files_to(tempdir, lazy))
        app.initialize(["."])
        app.options.exclude = update_excludes(app.options.exclude, tempdir)
        app.options._running_from_vcs = True
        # Apparently there are times when there are no files to check (e.g.,
        # when amending a commit). In those cases, let's not try to run checks
        # against nothing.
        if filepaths:
            app.run_checks(filepaths)

    # If there were files to check, update their paths and report the errors
    if filepaths:
        update_paths(app.file_checker_manager, tempdir)
        app.report_errors()
github kataev / flake8-rst / flake8_rst / application.py View on Github external
from flake8.main import options
from flake8.main.application import Application as Flake8Application
from flake8.options import manager

from . import __version__
from . import checker


class Application(Flake8Application):
    def __init__(self, program='flake8-rst', version=__version__):
        super(Application, self).__init__(program, version)

        self.option_manager = manager.OptionManager(
            prog=program, version=version
        )
        self.option_manager.add_option(
            '--bootstrap', default=None, parse_from_config=True,
            help='Bootstrap code snippets. Useful for add imports.',
        )
        self.option_manager.add_option(
            '--default-groupnames', default="*.rst->*: default", parse_from_config=True,
            help='Set default group names.', type='string',
        )
        options.register_default_options(self.option_manager)