How to use the flake8.options.config 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 PyCQA / flake8 / tests / unit / test_merged_config_parser.py View on Github external
def config_finder():
    """Generate a simple ConfigFileFinder."""
    return config.ConfigFileFinder('flake8', [], [])
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()
        application.find_plugins()
        application.register_plugin_options()
        application.parse_configuration_and_cli(argv)
github PyCQA / flake8 / tests / unit / test_config_file_finder.py View on Github external
def test_cli_config_double_read():
    """Second request for CLI config is cached."""
    finder = config.ConfigFileFinder('flake8', None, [])

    parsed_config = finder.cli_config(CLI_SPECIFIED_FILEPATH)
    boom = Exception("second request for CLI config not cached")
    with mock.patch.object(finder, '_read_config', side_effect=boom):
        parsed_config_2 = finder.cli_config(CLI_SPECIFIED_FILEPATH)

    assert parsed_config is parsed_config_2
github PyCQA / flake8 / tests / integration / test_aggregator.py View on Github external
def test_aggregate_options_with_config(optmanager):
    """Verify we aggregate options and config values appropriately."""
    arguments = ['flake8', '--config', CLI_SPECIFIED_CONFIG, '--select',
                 'E11,E34,E402,W,F', '--exclude', 'tests/*']
    config_finder = config.ConfigFileFinder('flake8', [])
    options, args = aggregator.aggregate_options(
        optmanager, config_finder, arguments)

    assert options.config == CLI_SPECIFIED_CONFIG
    assert options.select == ['E11', 'E34', 'E402', 'W', 'F']
    assert options.ignore == ['E123', 'W234', 'E111']
    assert options.exclude == [os.path.abspath('tests/*')]
github PyCQA / flake8 / tests / unit / test_get_local_plugins.py View on Github external
def test_get_local_plugins_respects_isolated():
    """Verify behaviour of get_local_plugins with isolated=True."""
    config_finder = mock.MagicMock()

    local_plugins = config.get_local_plugins(config_finder, isolated=True)

    assert local_plugins.extension == []
    assert local_plugins.report == []
    assert config_finder.local_configs.called is False
    assert config_finder.user_config.called is False
github PyCQA / flake8 / tests / unit / test_merged_config_parser.py View on Github external
def test_is_configured_by(
        filename, is_configured_by, optmanager, config_finder):
    """Verify the behaviour of the is_configured_by method."""
    parsed_config, _ = config.ConfigFileFinder._read_config(filename)
    parser = config.MergedConfigParser(optmanager, config_finder)

    assert parser.is_configured_by(parsed_config) is is_configured_by
github zrzka / blackmamba / blackmamba / lib / flake8 / main / application.py View on Github external
def make_config_finder(self):
        """Make our ConfigFileFinder based on preliminary opts and args."""
        if self.config_finder is None:
            extra_config_files = utils.normalize_paths(
                self.prelim_opts.append_config)
            self.config_finder = config.ConfigFileFinder(
                self.option_manager.program_name,
                self.prelim_args,
                extra_config_files,
            )
github PyCQA / flake8 / src / flake8 / main / application.py View on Github external
def initialize(self, argv):
        # type: (List[str]) -> None
        """Initialize the application to be run.

        This finds the plugins, registers their options, and parses the
        command-line arguments.
        """
        # NOTE(sigmavirus24): When updating this, make sure you also update
        # our legacy API calls to these same methods.
        prelim_opts, remaining_args = self.parse_preliminary_options(argv)
        flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
        config_finder = config.ConfigFileFinder(
            self.program, prelim_opts.append_config
        )
        self.find_plugins(
            config_finder, prelim_opts.config, prelim_opts.isolated
        )
        self.register_plugin_options()
        self.parse_configuration_and_cli(config_finder, remaining_args)
        self.make_formatter()
        self.make_guide()
        self.make_file_checker_manager()