Merge branch 'revert-6a70aaae' into 'master'

Revert "Merge branch 'hoist-argv' into 'master'"

See merge request pycqa/flake8!344
This commit is contained in:
Anthony Sottile 2019-08-28 23:21:04 +00:00
commit 8b34b334fa
3 changed files with 7 additions and 21 deletions

View file

@ -97,8 +97,8 @@ 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_and_args(self, argv=None):
# type: (List[str]) -> None # type: (Optional[List[str]]) -> None
"""Get preliminary options and args from CLI, pre-plugin-loading. """Get preliminary options and args from 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 and args now, so
@ -121,7 +121,7 @@ class Application(object):
# do not need to worry and we can continue. If it is, we successfully # do not need to worry and we can continue. If it is, we successfully
# defer printing the version until just a little bit later. # defer printing the version until just a little bit later.
# Similarly we have to defer printing the help text until later. # Similarly we have to defer printing the help text until later.
args = argv[:] args = (argv if argv is not None else sys.argv)[:]
try: try:
args.remove("--version") args.remove("--version")
except ValueError: except ValueError:
@ -344,7 +344,7 @@ class Application(object):
self.formatter.show_statistics(self.guide.stats) self.formatter.show_statistics(self.guide.stats)
def initialize(self, argv): def initialize(self, argv):
# type: (List[str]) -> None # type: (Optional[List[str]]) -> None
"""Initialize the application to be run. """Initialize the application to be run.
This finds the plugins, registers their options, and parses the This finds the plugins, registers their options, and parses the
@ -373,13 +373,13 @@ class Application(object):
self.formatter.stop() self.formatter.stop()
def _run(self, argv): def _run(self, argv):
# type: (List[str]) -> None # type: (Optional[List[str]]) -> None
self.initialize(argv) self.initialize(argv)
self.run_checks() self.run_checks()
self.report() self.report()
def run(self, argv): def run(self, argv=None):
# type: (List[str]) -> None # type: (Optional[List[str]]) -> None
"""Run our application. """Run our application.
This method will also handle KeyboardInterrupt exceptions for the This method will also handle KeyboardInterrupt exceptions for the

View file

@ -1,5 +1,4 @@
"""Command-line implementation of flake8.""" """Command-line implementation of flake8."""
import sys
from typing import List, Optional from typing import List, Optional
from flake8.main import application from flake8.main import application
@ -15,9 +14,6 @@ def main(argv=None):
:param list argv: :param list argv:
The arguments to be passed to the application for parsing. The arguments to be passed to the application for parsing.
""" """
if argv is None:
argv = sys.argv
app = application.Application() app = application.Application()
app.run(argv) app.run(argv)
app.exit() app.exit()

View file

@ -126,13 +126,3 @@ def test_bug_report_successful(capsys):
out, err = capsys.readouterr() out, err = capsys.readouterr()
assert json.loads(out) assert json.loads(out)
assert err == '' assert err == ''
def test_obtaining_args_from_sys_argv_when_not_explicity_provided(capsys):
"""Test that arguments are obtained from 'sys.argv'."""
with mock.patch('sys.argv', ['--help']):
_call_main(None)
out, err = capsys.readouterr()
assert out.startswith('usage: flake8 [options] file file ...\n')
assert err == ''