diff options
| author | Carl Meyer <carl@oddbird.net> | 2017-10-23 16:49:09 -0700 |
|---|---|---|
| committer | Carl Meyer <carl@oddbird.net> | 2017-10-24 19:58:18 -0700 |
| commit | 423980164b258b2ec77d8d9bfccb9bc00b220e31 (patch) | |
| tree | 95c9cd2ad1955478ddc317136fb63dc7636142fc /src | |
| parent | 8acf55e0f85233c51c291816d73d828cc62d30d1 (diff) | |
| download | flake8-423980164b258b2ec77d8d9bfccb9bc00b220e31.tar.gz | |
Add paths option in local-plugins config file.
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/main/application.py | 2 | ||||
| -rw-r--r-- | src/flake8/options/config.py | 37 |
2 files changed, 33 insertions, 6 deletions
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py index 6c68305..233b9af 100644 --- a/src/flake8/main/application.py +++ b/src/flake8/main/application.py @@ -177,6 +177,8 @@ class Application(object): self.prelim_opts.isolated, ) + sys.path.extend(self.local_plugins.paths) + if self.check_plugins is None: self.check_plugins = plugin_manager.Checkers( self.local_plugins.extension) diff --git a/src/flake8/options/config.py b/src/flake8/options/config.py index 71429af..b5b42fb 100644 --- a/src/flake8/options/config.py +++ b/src/flake8/options/config.py @@ -54,6 +54,7 @@ class ConfigFileFinder(object): # caches to avoid double-reading config files self._local_configs = None + self._local_found_files = [] self._user_config = None self._cli_configs = {} @@ -120,14 +121,22 @@ class ConfigFileFinder(object): for filename in self.generate_possible_local_files() ] + [f for f in self.extra_config_files if exists(f)] - def local_configs(self): - """Parse all local config files into one config object.""" + def local_configs_with_files(self): + """Parse all local config files into one config object. + + Return (config, found_config_files) tuple. + """ if self._local_configs is None: config, found_files = self._read_config(self.local_config_files()) if found_files: LOG.debug('Found local configuration files: %s', found_files) self._local_configs = config - return self._local_configs + self._local_found_files = found_files + return (self._local_configs, self._local_found_files) + + def local_configs(self): + """Parse all local config files into one config object.""" + return self.local_configs_with_files()[0] def user_config_file(self): """Find the user-level config file.""" @@ -314,7 +323,7 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False): :rtype: flake8.options.config.LocalPlugins """ - local_plugins = LocalPlugins(extension=[], report=[]) + local_plugins = LocalPlugins(extension=[], report=[], paths=[]) if isolated: LOG.debug('Refusing to look for local plugins in configuration' 'files due to user-requested isolation') @@ -324,8 +333,11 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False): LOG.debug('Reading local plugins only from "%s" specified via ' '--config by the user', cli_config) config = config_finder.cli_config(cli_config) + config_files = [cli_config] else: - config = config_finder.local_configs() + config, config_files = config_finder.local_configs_with_files() + + base_dirs = {os.path.dirname(cf) for cf in config_files} section = '%s:local-plugins' % config_finder.program_name for plugin_type in ['extension', 'report']: @@ -336,7 +348,20 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False): local_plugins_string, regexp=utils.LOCAL_PLUGIN_LIST_RE, )) + if config.has_option(section, 'paths'): + raw_paths = utils.parse_comma_separated_list( + config.get(section, 'paths').strip(), + regexp=utils.LOCAL_PLUGIN_LIST_RE, + ) + norm_paths = [] + for base_dir in base_dirs: + norm_paths.extend( + path for path in + utils.normalize_paths(raw_paths, parent=base_dir) + if os.path.exists(path) + ) + local_plugins.paths.extend(norm_paths) return local_plugins -LocalPlugins = collections.namedtuple('LocalPlugins', 'extension report') +LocalPlugins = collections.namedtuple('LocalPlugins', 'extension report paths') |
