diff options
| author | Anthony Sottile <asottile@umich.edu> | 2020-01-08 17:50:57 +0000 |
|---|---|---|
| committer | Anthony Sottile <asottile@umich.edu> | 2020-01-08 17:50:57 +0000 |
| commit | a5aa81e87588ff36560654a5ada13eb87e7e8133 (patch) | |
| tree | 258f2692d8a214e48e792cdd72162d464916edc7 /src | |
| parent | 4395b0560523c57e732c66e3f9ad9bb916aa3c1b (diff) | |
| parent | c918e7249699ab91ccbd6d69a898d19aa009c971 (diff) | |
| download | flake8-a5aa81e87588ff36560654a5ada13eb87e7e8133.tar.gz | |
Merge branch 'config-finder-isolated' into 'master'
Determine config isolation from the ConfigFileFinder object
See merge request pycqa/flake8!398
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/api/legacy.py | 13 | ||||
| -rw-r--r-- | src/flake8/main/application.py | 31 | ||||
| -rw-r--r-- | src/flake8/options/aggregator.py | 6 | ||||
| -rw-r--r-- | src/flake8/options/config.py | 25 |
4 files changed, 28 insertions, 47 deletions
diff --git a/src/flake8/api/legacy.py b/src/flake8/api/legacy.py index fe3b405..40da7db 100644 --- a/src/flake8/api/legacy.py +++ b/src/flake8/api/legacy.py @@ -32,18 +32,15 @@ def get_style_guide(**kwargs): 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.program, + prelim_opts.append_config, + ignore_config_files=prelim_opts.isolated, ) - application.find_plugins( - config_finder, prelim_opts.config, prelim_opts.isolated - ) + application.find_plugins(config_finder, prelim_opts.config) application.register_plugin_options() application.parse_configuration_and_cli( - config_finder, - prelim_opts.config, - prelim_opts.isolated, - remaining_args, + config_finder, prelim_opts.config, remaining_args, ) # We basically want application.initialize to be called but with these # options set instead before we make our formatter, notifier, internal diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 791d5af..a30f195 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -131,8 +131,8 @@ class Application(object): (self.result_count > 0) or self.catastrophic_failure ) - def find_plugins(self, config_finder, config_file, ignore_config_files): - # type: (config.ConfigFileFinder, Optional[str], bool) -> None + def find_plugins(self, config_finder, config_file): + # type: (config.ConfigFileFinder, Optional[str]) -> None """Find and load the plugins for this application. Set the :attr:`check_plugins` and :attr:`formatting_plugins` attributes @@ -147,9 +147,7 @@ class Application(object): Determine whether to parse configuration files or not. (i.e., the --isolated option). """ - local_plugins = config.get_local_plugins( - config_finder, config_file, ignore_config_files - ) + local_plugins = config.get_local_plugins(config_finder, config_file) sys.path.extend(local_plugins.paths) @@ -173,7 +171,6 @@ class Application(object): self, config_finder, # type: config.ConfigFileFinder config_file, # type: Optional[str] - ignore_config_files, # type: bool argv, # type: List[str] ): # type: (...) -> None @@ -184,18 +181,11 @@ class Application(object): :param str config_file: The optional configuraiton file to override all other configuration files (i.e., the --config option). - :param bool ignore_config_files: - Determine whether to parse configuration files or not. (i.e., the - --isolated option). :param list argv: Command-line arguments passed in directly. """ self.options, self.args = aggregator.aggregate_options( - self.option_manager, - config_finder, - config_file, - ignore_config_files, - argv, + self.option_manager, config_finder, config_file, argv, ) self.running_against_diff = self.options.diff @@ -335,17 +325,14 @@ class Application(object): 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.program, + prelim_opts.append_config, + ignore_config_files=prelim_opts.isolated, ) + self.find_plugins(config_finder, prelim_opts.config) self.register_plugin_options() self.parse_configuration_and_cli( - config_finder, - prelim_opts.config, - prelim_opts.isolated, - remaining_args, + config_finder, prelim_opts.config, remaining_args, ) self.make_formatter() self.make_guide() diff --git a/src/flake8/options/aggregator.py b/src/flake8/options/aggregator.py index 58d1022..939dfb3 100644 --- a/src/flake8/options/aggregator.py +++ b/src/flake8/options/aggregator.py @@ -17,7 +17,6 @@ def aggregate_options( manager, # type: OptionManager config_finder, # type: config.ConfigFileFinder cli_config, # type: Optional[str] - isolated, # type: bool argv, # type: List[str] ): # type: (...) -> Tuple[argparse.Namespace, List[str]] """Aggregate and merge CLI and config file options. @@ -29,9 +28,6 @@ def aggregate_options( :param str cli_config: Value of --config when specified at the command-line. Overrides all other config files. - :param bool isolated: - Determines if we should parse configuration files at all or not. - If running in isolated mode, we ignore all configuration files :param list argv: The list of remaining command-line argumentsthat were unknown during preliminary option parsing to pass to ``manager.parse_args``. @@ -50,7 +46,7 @@ def aggregate_options( ) # Get the parsed config - parsed_config = config_parser.parse(cli_config, isolated) + parsed_config = config_parser.parse(cli_config) # Extend the default ignore value with the extended default ignore list, # registered by plugins. diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py index e1952be..7261bcd 100644 --- a/src/flake8/options/config.py +++ b/src/flake8/options/config.py @@ -16,19 +16,26 @@ __all__ = ("ConfigFileFinder", "MergedConfigParser") class ConfigFileFinder(object): """Encapsulate the logic for finding and reading config files.""" - def __init__(self, program_name, extra_config_files): - # type: (str, List[str]) -> None + def __init__( + self, program_name, extra_config_files, ignore_config_files=False + ): + # type: (str, List[str], bool) -> None """Initialize object to find config files. :param str program_name: Name of the current program (e.g., flake8). :param list extra_config_files: Extra configuration files specified by the user to read. + :param bool ignore_config_files: + Determine whether to ignore configuration files or not. """ # The values of --append-config from the CLI extra_config_files = extra_config_files or [] self.extra_config_files = utils.normalize_paths(extra_config_files) + # The value of --isolated from the CLI. + self.ignore_config_files = ignore_config_files + # Platform specific settings self.is_windows = sys.platform == "win32" self.xdg_home = os.environ.get( @@ -282,7 +289,7 @@ class MergedConfigParser(object): return config - def parse(self, cli_config=None, isolated=False): + def parse(self, cli_config=None): """Parse and return the local and user config files. First this copies over the parsed local configuration and then @@ -292,15 +299,12 @@ class MergedConfigParser(object): :param str cli_config: Value of --config when specified at the command-line. Overrides all other config files. - :param bool isolated: - Determines if we should parse configuration files at all or not. - If running in isolated mode, we ignore all configuration files :returns: Dictionary of parsed configuration options :rtype: dict """ - if isolated: + if self.config_finder.ignore_config_files: LOG.debug( "Refusing to parse configuration files due to user-" "requested isolation" @@ -319,7 +323,7 @@ class MergedConfigParser(object): return self.merge_user_and_local_config() -def get_local_plugins(config_finder, cli_config=None, isolated=False): +def get_local_plugins(config_finder, cli_config=None): """Get local plugins lists from config files. :param flake8.options.config.ConfigFileFinder config_finder: @@ -327,9 +331,6 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False): :param str cli_config: Value of --config when specified at the command-line. Overrides all other config files. - :param bool isolated: - Determines if we should parse configuration files at all or not. - If running in isolated mode, we ignore all configuration files :returns: LocalPlugins namedtuple containing two lists of plugin strings, one for extension (checker) plugins and one for report plugins. @@ -337,7 +338,7 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False): flake8.options.config.LocalPlugins """ local_plugins = LocalPlugins(extension=[], report=[], paths=[]) - if isolated: + if config_finder.ignore_config_files: LOG.debug( "Refusing to look for local plugins in configuration" "files due to user-requested isolation" |
