mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-12 23:54:17 +00:00
Re-factor normalization in parse_args
This commit is contained in:
parent
cc3a9210fd
commit
684f19f5e3
1 changed files with 15 additions and 16 deletions
|
|
@ -111,6 +111,20 @@ class Option(object):
|
||||||
return self.long_option_name[2:].replace('-', '_')
|
return self.long_option_name[2:].replace('-', '_')
|
||||||
return self.short_option_name[1]
|
return self.short_option_name[1]
|
||||||
|
|
||||||
|
def normalize(self, options):
|
||||||
|
dest = self.dest
|
||||||
|
if self.normalize_paths:
|
||||||
|
old_value = getattr(options, dest)
|
||||||
|
# Decide whether to parse a list of paths or a single path
|
||||||
|
normalize = utils.normalize_path
|
||||||
|
if self.comma_separated_list:
|
||||||
|
normalize = utils.normalize_paths
|
||||||
|
setattr(options, dest, normalize(old_value))
|
||||||
|
elif self.comma_separated_list:
|
||||||
|
old_value = getattr(options, dest)
|
||||||
|
setattr(options, dest,
|
||||||
|
utils.parse_comma_separated_list(old_value))
|
||||||
|
|
||||||
def to_optparse(self):
|
def to_optparse(self):
|
||||||
"""Convert a Flake8 Option to an optparse Option."""
|
"""Convert a Flake8 Option to an optparse Option."""
|
||||||
if not hasattr(self, '_opt'):
|
if not hasattr(self, '_opt'):
|
||||||
|
|
@ -153,21 +167,6 @@ class OptionManager(object):
|
||||||
"""Simple proxy to calling the OptionParser's parse_args method."""
|
"""Simple proxy to calling the OptionParser's parse_args method."""
|
||||||
options, xargs = self.parser.parse_args(args, values)
|
options, xargs = self.parser.parse_args(args, values)
|
||||||
for option in self.options:
|
for option in self.options:
|
||||||
_normalize_option(options, option)
|
option.normalize(options)
|
||||||
|
|
||||||
return options, xargs
|
return options, xargs
|
||||||
|
|
||||||
|
|
||||||
def _normalize_option(options, option):
|
|
||||||
dest = option.dest
|
|
||||||
if option.normalize_paths:
|
|
||||||
old_value = getattr(options, dest)
|
|
||||||
# Decide whether to parse a list of paths or a single path
|
|
||||||
normalize = utils.normalize_path
|
|
||||||
if option.comma_separated_list:
|
|
||||||
normalize = utils.normalize_paths
|
|
||||||
setattr(options, dest, normalize(old_value))
|
|
||||||
elif option.comma_separated_list:
|
|
||||||
old_value = getattr(options, dest)
|
|
||||||
setattr(options, dest,
|
|
||||||
utils.parse_comma_separated_list(old_value))
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue