mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-29 10:36:53 +00:00
Allow our local plugin parsing to accept commas
By slightly modifying our utility function to parse comma separated lists we can parse local plugins similar to other configuration options.
This commit is contained in:
parent
a2c7051c9e
commit
222f0a8115
3 changed files with 19 additions and 7 deletions
|
|
@ -5,6 +5,8 @@ import logging
|
|||
import os.path
|
||||
import sys
|
||||
|
||||
from flake8 import utils
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
__all__ = ('ConfigFileFinder', 'MergedConfigParser')
|
||||
|
|
@ -320,11 +322,12 @@ def get_local_plugins(config_finder, cli_config=None, isolated=False):
|
|||
section = '%s:local-plugins' % config_finder.program_name
|
||||
for plugin_type in ['extension', 'report']:
|
||||
if config.has_option(section, plugin_type):
|
||||
getattr(local_plugins, plugin_type).extend(
|
||||
c.strip() for c in config.get(
|
||||
section, plugin_type
|
||||
).strip().splitlines()
|
||||
)
|
||||
local_plugins_string = config.get(section, plugin_type).strip()
|
||||
plugin_type_list = getattr(local_plugins, plugin_type)
|
||||
plugin_type_list.extend(utils.parse_comma_separated_list(
|
||||
local_plugins_string,
|
||||
regexp=utils.LOCAL_PLUGIN_LIST_RE,
|
||||
))
|
||||
return local_plugins
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,14 +11,20 @@ import tokenize
|
|||
|
||||
DIFF_HUNK_REGEXP = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$')
|
||||
COMMA_SEPARATED_LIST_RE = re.compile(r'[,\s]')
|
||||
LOCAL_PLUGIN_LIST_RE = re.compile(r'[,\t\n\r\f\v]')
|
||||
|
||||
|
||||
def parse_comma_separated_list(value):
|
||||
def parse_comma_separated_list(value, regexp=COMMA_SEPARATED_LIST_RE):
|
||||
# type: (Union[Sequence[str], str]) -> List[str]
|
||||
"""Parse a comma-separated list.
|
||||
|
||||
:param value:
|
||||
String or list of strings to be parsed and normalized.
|
||||
:param regexp:
|
||||
Compiled regular expression used to split the value when it is a
|
||||
string.
|
||||
:type regexp:
|
||||
_sre.SRE_Pattern
|
||||
:returns:
|
||||
List of values with whitespace stripped.
|
||||
:rtype:
|
||||
|
|
@ -28,7 +34,7 @@ def parse_comma_separated_list(value):
|
|||
return []
|
||||
|
||||
if not isinstance(value, (list, tuple)):
|
||||
value = COMMA_SEPARATED_LIST_RE.split(value)
|
||||
value = regexp.split(value)
|
||||
|
||||
item_gen = (item.strip() for item in value)
|
||||
return [item for item in item_gen if item]
|
||||
|
|
|
|||
|
|
@ -18,7 +18,10 @@ def test_get_local_plugins_respects_isolated():
|
|||
|
||||
def test_get_local_plugins_uses_cli_config():
|
||||
"""Verify behaviour of get_local_plugins with a specified config."""
|
||||
config_obj = mock.Mock()
|
||||
config_finder = mock.MagicMock()
|
||||
config_finder.cli_config.return_value = config_obj
|
||||
config_obj.get.return_value = ''
|
||||
|
||||
config.get_local_plugins(config_finder, cli_config='foo.ini')
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue