summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-12-07 17:05:22 -0500
committerGitHub <noreply@github.com>2021-12-07 17:05:22 -0500
commit1587936e2a1448710f3e44877cb5d44dcad7c6ac (patch)
treee7113207ff8d418a8c49acc04b718c3a4f876a05
parent03b33b95738b6667778b70006ef61548269589d2 (diff)
parent52fb51810467b6c4818b47fdd5a2ab14b53d84bb (diff)
downloadflake8-1587936e2a1448710f3e44877cb5d44dcad7c6ac.tar.gz
Merge pull request #1487 from PyCQA/debug-store-true
eliminate --bug-report double-parse quirk with store_true
-rw-r--r--.pre-commit-config.yaml4
-rw-r--r--src/flake8/main/application.py7
-rw-r--r--src/flake8/main/debug.py37
-rw-r--r--src/flake8/main/options.py7
-rw-r--r--tests/unit/test_debug.py45
5 files changed, 12 insertions, 88 deletions
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 16052ba..b6fa672 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -17,6 +17,10 @@ repos:
hooks:
- id: black
args: [--line-length=79]
+- repo: https://github.com/PyCQA/flake8
+ rev: 4.0.1
+ hooks:
+ - id: flake8
- repo: https://github.com/asottile/pyupgrade
rev: v2.29.1
hooks:
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index aa2dd14..77f25d4 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -1,6 +1,7 @@
"""Module containing the application logic for Flake8."""
import argparse
import configparser
+import json
import logging
import sys
import time
@@ -19,6 +20,7 @@ from flake8 import defaults
from flake8 import exceptions
from flake8 import style_guide
from flake8 import utils
+from flake8.main import debug
from flake8.main import options
from flake8.options import aggregator
from flake8.options import config
@@ -184,6 +186,11 @@ class Application:
argv,
)
+ if self.options.bug_report:
+ info = debug.information(self.option_manager)
+ print(json.dumps(info, indent=2, sort_keys=True))
+ raise SystemExit(0)
+
if self.options.diff:
LOG.warning(
"the --diff option is deprecated and will be removed in a "
diff --git a/src/flake8/main/debug.py b/src/flake8/main/debug.py
index 9b3e42b..cca6857 100644
--- a/src/flake8/main/debug.py
+++ b/src/flake8/main/debug.py
@@ -1,36 +1,5 @@
"""Module containing the logic for our debugging logic."""
-import argparse
-import json
import platform
-from typing import Dict
-from typing import List
-
-
-class DebugAction(argparse.Action):
- """argparse action to print debug information."""
-
- def __init__(self, *args, option_manager, **kwargs):
- """Initialize the action.
-
- This takes an extra `option_manager` keyword argument which will be
- used to delay response.
- """
- self._option_manager = option_manager
- super().__init__(*args, **kwargs)
-
- def __call__(self, parser, namespace, values, option_string=None):
- """Perform the argparse action for printing debug information."""
- # NOTE(sigmavirus24): Flake8 parses options twice. The first time, we
- # will not have any registered plugins. We can skip this one and only
- # take action on the second time we're called.
- if not self._option_manager.registered_plugins:
- return
- print(
- json.dumps(
- information(self._option_manager), indent=2, sort_keys=True
- )
- )
- raise SystemExit(0)
def information(option_manager):
@@ -38,7 +7,6 @@ def information(option_manager):
return {
"version": option_manager.version,
"plugins": plugins_from(option_manager),
- "dependencies": dependencies(),
"platform": {
"python_implementation": platform.python_implementation(),
"python_version": platform.python_version(),
@@ -57,8 +25,3 @@ def plugins_from(option_manager):
}
for plugin in sorted(option_manager.registered_plugins)
]
-
-
-def dependencies() -> List[Dict[str, str]]:
- """Generate the list of dependencies we care about."""
- return []
diff --git a/src/flake8/main/options.py b/src/flake8/main/options.py
index 3abc043..a73a9ee 100644
--- a/src/flake8/main/options.py
+++ b/src/flake8/main/options.py
@@ -1,9 +1,7 @@
"""Contains the logic for all of the default options for Flake8."""
import argparse
-import functools
from flake8 import defaults
-from flake8.main import debug
from flake8.options.manager import OptionManager
@@ -379,9 +377,6 @@ def register_default_options(option_manager: OptionManager) -> None:
add_option(
"--bug-report",
- action=functools.partial(
- debug.DebugAction, option_manager=option_manager
- ),
- nargs=0,
+ action="store_true",
help="Print information necessary when preparing a bug report",
)
diff --git a/tests/unit/test_debug.py b/tests/unit/test_debug.py
index 2da4bf8..e686c5c 100644
--- a/tests/unit/test_debug.py
+++ b/tests/unit/test_debug.py
@@ -7,11 +7,6 @@ from flake8.main import debug
from flake8.options import manager
-def test_dependencies():
- """Verify that we format our dependencies appropriately."""
- assert [] == debug.dependencies()
-
-
@pytest.mark.parametrize(
"plugins, expected",
[
@@ -75,7 +70,6 @@ def test_information(system, pyversion, pyimpl):
{"plugin": "mccabe", "version": "0.5.9", "is_local": False},
{"plugin": "pycodestyle", "version": "2.0.0", "is_local": False},
],
- "dependencies": [],
"platform": {
"python_implementation": "CPython",
"python_version": "3.5.3",
@@ -93,42 +87,3 @@ def test_information(system, pyversion, pyimpl):
pyimpl.assert_called_once_with()
pyversion.assert_called_once_with()
system.assert_called_once_with()
-
-
-@mock.patch("flake8.main.debug.print")
-@mock.patch("flake8.main.debug.information", return_value={})
-@mock.patch("json.dumps", return_value="{}")
-def test_print_information_no_plugins(dumps, information, print_mock):
- """Verify we print and exit only when we have plugins."""
- option_manager = mock.Mock(registered_plugins=set())
- action = debug.DebugAction(
- "--bug-report",
- dest="bug_report",
- option_manager=option_manager,
- )
- assert action(None, None, None, None) is None
- assert dumps.called is False
- assert information.called is False
- assert print_mock.called is False
-
-
-@mock.patch("flake8.main.debug.print")
-@mock.patch("flake8.main.debug.information", return_value={})
-@mock.patch("json.dumps", return_value="{}")
-def test_print_information(dumps, information, print_mock):
- """Verify we print and exit only when we have plugins."""
- plugins = [
- manager.PluginVersion("pycodestyle", "2.0.0", False),
- manager.PluginVersion("mccabe", "0.5.9", False),
- ]
- option_manager = mock.Mock(registered_plugins=set(plugins))
- action = debug.DebugAction(
- "--bug-report",
- dest="bug_report",
- option_manager=option_manager,
- )
- with pytest.raises(SystemExit):
- action(None, None, None, None)
- print_mock.assert_called_once_with("{}")
- dumps.assert_called_once_with({}, indent=2, sort_keys=True)
- information.assert_called_once_with(option_manager)