mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-11 07:14:18 +00:00
application: Rename prelim parsing method to 'parse_preliminary_options'
Positional arguments are not used nor parsed for pre-configuration loading. Thus, renaming the method and updating the docstrings appropriately.
This commit is contained in:
parent
b5157e194d
commit
1abe1d42c2
4 changed files with 11 additions and 22 deletions
|
|
@ -28,10 +28,7 @@ def get_style_guide(**kwargs):
|
||||||
:class:`StyleGuide`
|
:class:`StyleGuide`
|
||||||
"""
|
"""
|
||||||
application = app.Application()
|
application = app.Application()
|
||||||
(
|
prelim_opts, remaining_args = application.parse_preliminary_options([])
|
||||||
prelim_opts,
|
|
||||||
remaining_args,
|
|
||||||
) = application.parse_preliminary_options_and_args([])
|
|
||||||
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
||||||
application.make_config_finder(prelim_opts.append_config)
|
application.make_config_finder(prelim_opts.append_config)
|
||||||
application.find_plugins(prelim_opts.config, prelim_opts.isolated)
|
application.find_plugins(prelim_opts.config, prelim_opts.isolated)
|
||||||
|
|
|
||||||
|
|
@ -98,12 +98,12 @@ class Application(object):
|
||||||
#: The parsed diff information
|
#: The parsed diff information
|
||||||
self.parsed_diff = {} # type: Dict[str, Set[int]]
|
self.parsed_diff = {} # type: Dict[str, Set[int]]
|
||||||
|
|
||||||
def parse_preliminary_options_and_args(self, argv):
|
def parse_preliminary_options(self, argv):
|
||||||
# type: (List[str]) -> Tuple[argparse.Namespace, List[str]]
|
# type: (List[str]) -> Tuple[argparse.Namespace, List[str]]
|
||||||
"""Get preliminary options and args from CLI, pre-plugin-loading.
|
"""Get preliminary options from the CLI, pre-plugin-loading.
|
||||||
|
|
||||||
We need to know the values of a few standard options and args now, so
|
We need to know the values of a few standard options so that we can
|
||||||
that we can find config files and configure logging.
|
locate configuration files and configure logging.
|
||||||
|
|
||||||
Since plugins aren't loaded yet, there may be some as-yet-unknown
|
Since plugins aren't loaded yet, there may be some as-yet-unknown
|
||||||
options; we ignore those for now, they'll be parsed later when we do
|
options; we ignore those for now, they'll be parsed later when we do
|
||||||
|
|
@ -338,9 +338,7 @@ class Application(object):
|
||||||
"""
|
"""
|
||||||
# NOTE(sigmavirus24): When updating this, make sure you also update
|
# NOTE(sigmavirus24): When updating this, make sure you also update
|
||||||
# our legacy API calls to these same methods.
|
# our legacy API calls to these same methods.
|
||||||
prelim_opts, remaining_args = self.parse_preliminary_options_and_args(
|
prelim_opts, remaining_args = self.parse_preliminary_options(argv)
|
||||||
argv
|
|
||||||
)
|
|
||||||
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
flake8.configure_logging(prelim_opts.verbose, prelim_opts.output_file)
|
||||||
self.make_config_finder(prelim_opts.append_config)
|
self.make_config_finder(prelim_opts.append_config)
|
||||||
self.find_plugins(prelim_opts.config, prelim_opts.isolated)
|
self.find_plugins(prelim_opts.config, prelim_opts.isolated)
|
||||||
|
|
|
||||||
|
|
@ -92,7 +92,7 @@ def test_returns_specified_plugin(application):
|
||||||
|
|
||||||
def test_prelim_opts_args(application):
|
def test_prelim_opts_args(application):
|
||||||
"""Verify we get sensible prelim opts and args."""
|
"""Verify we get sensible prelim opts and args."""
|
||||||
opts, args = application.parse_preliminary_options_and_args(
|
opts, args = application.parse_preliminary_options(
|
||||||
['--foo', '--verbose', 'src', 'setup.py', '--statistics', '--version'])
|
['--foo', '--verbose', 'src', 'setup.py', '--statistics', '--version'])
|
||||||
|
|
||||||
assert opts.verbose
|
assert opts.verbose
|
||||||
|
|
@ -104,10 +104,7 @@ def test_prelim_opts_ignore_help(application):
|
||||||
# GIVEN
|
# GIVEN
|
||||||
|
|
||||||
# WHEN
|
# WHEN
|
||||||
_, args = application.parse_preliminary_options_and_args([
|
_, args = application.parse_preliminary_options(['--help', '-h'])
|
||||||
'--help',
|
|
||||||
'-h',
|
|
||||||
])
|
|
||||||
|
|
||||||
# THEN
|
# THEN
|
||||||
assert args == ['--help', '-h']
|
assert args == ['--help', '-h']
|
||||||
|
|
@ -117,6 +114,6 @@ def test_prelim_opts_handles_empty(application):
|
||||||
"""Verify empty argv lists are handled correctly."""
|
"""Verify empty argv lists are handled correctly."""
|
||||||
irrelevant_args = ['myexe', '/path/to/foo']
|
irrelevant_args = ['myexe', '/path/to/foo']
|
||||||
with mock.patch.object(sys, 'argv', irrelevant_args):
|
with mock.patch.object(sys, 'argv', irrelevant_args):
|
||||||
opts, args = application.parse_preliminary_options_and_args([])
|
opts, args = application.parse_preliminary_options([])
|
||||||
|
|
||||||
assert args == []
|
assert args == []
|
||||||
|
|
|
||||||
|
|
@ -18,16 +18,13 @@ def test_get_style_guide():
|
||||||
verbose=0,
|
verbose=0,
|
||||||
)
|
)
|
||||||
mockedapp = mock.Mock()
|
mockedapp = mock.Mock()
|
||||||
mockedapp.parse_preliminary_options_and_args.return_value = (
|
mockedapp.parse_preliminary_options.return_value = (prelim_opts, [])
|
||||||
prelim_opts,
|
|
||||||
[],
|
|
||||||
)
|
|
||||||
with mock.patch('flake8.main.application.Application') as application:
|
with mock.patch('flake8.main.application.Application') as application:
|
||||||
application.return_value = mockedapp
|
application.return_value = mockedapp
|
||||||
style_guide = api.get_style_guide()
|
style_guide = api.get_style_guide()
|
||||||
|
|
||||||
application.assert_called_once_with()
|
application.assert_called_once_with()
|
||||||
mockedapp.parse_preliminary_options_and_args.assert_called_once_with([])
|
mockedapp.parse_preliminary_options.assert_called_once_with([])
|
||||||
mockedapp.make_config_finder.assert_called_once_with([])
|
mockedapp.make_config_finder.assert_called_once_with([])
|
||||||
mockedapp.find_plugins.assert_called_once_with(None, False)
|
mockedapp.find_plugins.assert_called_once_with(None, False)
|
||||||
mockedapp.register_plugin_options.assert_called_once_with()
|
mockedapp.register_plugin_options.assert_called_once_with()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue