From 1dc387d861db5afaf449b4ed6d3b7816179af531 Mon Sep 17 00:00:00 2001 From: Thomas Denewiler Date: Mon, 17 May 2021 06:23:50 -0700 Subject: [PATCH] Remove deprecated plugins for catkin discovery, print json reporting, and show tool output argument. (#359) --- .github/workflows/test.yml | 4 +- README.md | 2 +- .../source/statick_tool.plugins.discovery.rst | 8 -- .../source/statick_tool.plugins.reporting.rst | 8 -- requirements.txt | 1 - setup.py | 2 - .../discovery/catkin_discovery_plugin.py | 35 -------- .../catkin_discovery_plugin.yapsy-plugin | 3 - .../reporting/print_json_reporting_plugin.py | 53 ------------ .../print_json_reporting_plugin.yapsy-plugin | 3 - statick_tool/statick.py | 14 ---- .../invalid_package_nocmakelists/package.xml | 0 .../CMakeLists.txt | 0 .../test_catkin_discovery_plugin.py | 77 ----------------- .../valid_package/CMakeLists.txt | 0 .../valid_package/package.xml | 0 .../test_print_json_reporting_plugin.py | 82 ------------------- tests/statick/test_statick.py | 23 ------ tox.ini | 1 - 19 files changed, 2 insertions(+), 314 deletions(-) delete mode 100644 statick_tool/plugins/discovery/catkin_discovery_plugin.py delete mode 100644 statick_tool/plugins/discovery/catkin_discovery_plugin.yapsy-plugin delete mode 100644 statick_tool/plugins/reporting/print_json_reporting_plugin.py delete mode 100644 statick_tool/plugins/reporting/print_json_reporting_plugin.yapsy-plugin delete mode 100644 tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nocmakelists/package.xml delete mode 100644 tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nopackagexml/CMakeLists.txt delete mode 100644 tests/plugins/discovery/catkin_discovery_plugin/test_catkin_discovery_plugin.py delete mode 100644 tests/plugins/discovery/catkin_discovery_plugin/valid_package/CMakeLists.txt delete mode 100644 tests/plugins/discovery/catkin_discovery_plugin/valid_package/package.xml delete mode 100644 tests/plugins/reporting/print_json_reporting_plugin/test_print_json_reporting_plugin.py diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 23370d7f..8ae3598c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -98,11 +98,9 @@ jobs: sudo npm install -g markdownlint-cli@0.21.0 rm nodesource_setup.sh - # The --allow-untyped-decorators flag is only used while we are using the `deprecated` module. - # When the deprecations are removed we can remove that mypy flag as well. - name: Test with mypy run: | - mypy --ignore-missing-imports --allow-untyped-decorators --strict statick statick_tool/ + mypy --ignore-missing-imports --strict statick statick_tool/ - name: Test with black if: matrix.python-version >= 3.6 diff --git a/README.md b/README.md index fb6f1aeb..12ada4a7 100644 --- a/README.md +++ b/README.md @@ -698,7 +698,7 @@ types of reports that can be viewed with a text editor or web browser. ```shell python3 -m pip install mypy mkdir report -mypy --ignore-missing-imports --strict --allow-untyped-decorators --html-report report/ --txt-report report statick statick_tool/ +mypy --ignore-missing-imports --strict --html-report report/ --txt-report report statick statick_tool/ ``` It is hoped that in the future we will generate coverage reports from mypy and use those to check for regressions. diff --git a/docs/source/statick_tool.plugins.discovery.rst b/docs/source/statick_tool.plugins.discovery.rst index 9b05a4c4..265d859a 100644 --- a/docs/source/statick_tool.plugins.discovery.rst +++ b/docs/source/statick_tool.plugins.discovery.rst @@ -12,14 +12,6 @@ Module contents Submodules ---------- -statick_tool.plugins.discovery.catkin_discovery_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. automodule:: statick_tool.plugins.discovery.catkin_discovery_plugin - :members: - :undoc-members: - :show-inheritance: - statick_tool.plugins.discovery.c_discovery_plugin module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/docs/source/statick_tool.plugins.reporting.rst b/docs/source/statick_tool.plugins.reporting.rst index 2f2550bc..d90512c6 100644 --- a/docs/source/statick_tool.plugins.reporting.rst +++ b/docs/source/statick_tool.plugins.reporting.rst @@ -28,14 +28,6 @@ statick_tool.plugins.reporting.json_reporting_plugin module :undoc-members: :show-inheritance: -statick_tool.plugins.reporting.print_json_reporting_plugin module -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -.. automodule:: statick_tool.plugins.reporting.print_json_reporting_plugin - :members: - :undoc-members: - :show-inheritance: - statick_tool.plugins.reporting.print_to_console_reporting_plugin module ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/requirements.txt b/requirements.txt index 77c258b0..84704753 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,7 +3,6 @@ bandit black cmakelint cpplint -deprecated docformatter flawfinder lizard diff --git a/setup.py b/setup.py index 0767f7cb..929d18aa 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,6 @@ TEST_DEPS = [ "backports.tempfile", - "deprecated", "pylint-django", "pytest", "mock", @@ -48,7 +47,6 @@ "bandit", "cmakelint", "cpplint", - "deprecated", "flawfinder", "lizard", "pycodestyle", diff --git a/statick_tool/plugins/discovery/catkin_discovery_plugin.py b/statick_tool/plugins/discovery/catkin_discovery_plugin.py deleted file mode 100644 index c5820a72..00000000 --- a/statick_tool/plugins/discovery/catkin_discovery_plugin.py +++ /dev/null @@ -1,35 +0,0 @@ -"""Discovery plugin to find catkin packages.""" -import logging -import os -from typing import Optional - -from deprecated import deprecated - -from statick_tool.discovery_plugin import DiscoveryPlugin -from statick_tool.exceptions import Exceptions -from statick_tool.package import Package - - -class CatkinDiscoveryPlugin(DiscoveryPlugin): - """Discovery plugin to find catkin packages.""" - - def get_name(self) -> str: - """Get name of discovery type.""" - return "catkin" - - @deprecated( - "This plugin has been deprecated since v0.4.6. A more generic version of this plugin is the ros_discovery_plugin. This plugin will be removed in v0.6." # NOLINT - ) - def scan( - self, package: Package, level: str, exceptions: Optional[Exceptions] = None - ) -> None: - """Scan package looking for catkin files.""" - cmake_file = os.path.join(package.path, "CMakeLists.txt") - package_file = os.path.join(package.path, "package.xml") - - if os.path.isfile(cmake_file) and os.path.isfile(package_file): - logging.info(" Package is catkin.") - package["catkin"] = True - else: - logging.info(" Package is not catkin.") - package["catkin"] = False diff --git a/statick_tool/plugins/discovery/catkin_discovery_plugin.yapsy-plugin b/statick_tool/plugins/discovery/catkin_discovery_plugin.yapsy-plugin deleted file mode 100644 index a2b8daaf..00000000 --- a/statick_tool/plugins/discovery/catkin_discovery_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Catkin Discovery Plugin -Module = catkin_discovery_plugin diff --git a/statick_tool/plugins/reporting/print_json_reporting_plugin.py b/statick_tool/plugins/reporting/print_json_reporting_plugin.py deleted file mode 100644 index 01a0f9af..00000000 --- a/statick_tool/plugins/reporting/print_json_reporting_plugin.py +++ /dev/null @@ -1,53 +0,0 @@ -"""Prints the Statick reports out to the terminal in JSON format.""" -import json -from collections import OrderedDict -from typing import Dict, List, Optional, Tuple - -from deprecated import deprecated - -from statick_tool.issue import Issue -from statick_tool.package import Package -from statick_tool.reporting_plugin import ReportingPlugin - - -class PrintJsonReportingPlugin(ReportingPlugin): - """Prints the Statick reports out to the terminal in JSON format.""" - - def get_name(self) -> str: - """Return the plugin name.""" - return "print_json" - - @deprecated( - "The print_json reporting plugin has been deprecated since v0.5.4. A more generic version of this plugin is the json_reporting_plugin. This plugin will be removed in v0.6." # NOLINT - ) - def report( - self, package: Package, issues: Dict[str, List[Issue]], level: str - ) -> Tuple[Optional[None], bool]: - """Go through the issues list and print them to the console in JSON format. - - Args: - package (:obj:`Package`): The Package object that was analyzed. - issues (:obj:`dict` of :obj:`str` to :obj:`Issue`): The issues - found by the Statick analysis, keyed by the tool that found - them. - level: (:obj:`str`): Name of the level used in the scan. - """ - all_issues = [] - for _, value in issues.items(): - for issue in value: - issue_dict = OrderedDict() - issue_dict["fileName"] = issue.filename - issue_dict["lineNumber"] = issue.line_number - issue_dict["tool"] = issue.tool - issue_dict["type"] = issue.issue_type - issue_dict["severity"] = issue.severity - issue_dict["message"] = issue.message - issue_dict["certReference"] = "" - if issue.cert_reference: - issue_dict["certReference"] = issue.cert_reference - all_issues.append(issue_dict) - report_json = {"issues": all_issues} - line = json.dumps(report_json) - print(line) - - return None, True diff --git a/statick_tool/plugins/reporting/print_json_reporting_plugin.yapsy-plugin b/statick_tool/plugins/reporting/print_json_reporting_plugin.yapsy-plugin deleted file mode 100644 index 771bdcad..00000000 --- a/statick_tool/plugins/reporting/print_json_reporting_plugin.yapsy-plugin +++ /dev/null @@ -1,3 +0,0 @@ -[Core] -Name = Print JSON Reporting Plugin -Module = print_json_reporting_plugin diff --git a/statick_tool/statick.py b/statick_tool/statick.py index c089056d..8865c2a7 100644 --- a/statick_tool/statick.py +++ b/statick_tool/statick.py @@ -74,19 +74,11 @@ def set_logging_level(args: argparse.Namespace) -> None: log_level = args.log_level.upper() if log_level not in valid_levels: log_level = "WARNING" - if args.show_tool_output: - log_level = "DEBUG" args.log_level = log_level logging.basicConfig(level=log_level) logging.root.setLevel(log_level) logging.info("Log level set to %s", args.log_level.upper()) - if args.show_tool_output: - logging.warning( - "The --show-tool-output argument has been deprecated since v0.5.0." - " Use log level of DEBUG instead. The argument will be removed in v0.6." - ) - def get_config(self, args: argparse.Namespace) -> None: """Get Statick configuration.""" base_config_filename = "config.yaml" @@ -149,12 +141,6 @@ def gather_args(self, args: argparse.ArgumentParser) -> None: help="Verbosity level of output to show (DEBUG, INFO, WARNING, ERROR" ", CRITICAL)", ) - args.add_argument( - "--show-tool-output", - dest="show_tool_output", - action="store_true", - help="Show tool output", - ) args.add_argument( "--check", dest="check", diff --git a/tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nocmakelists/package.xml b/tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nocmakelists/package.xml deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nopackagexml/CMakeLists.txt b/tests/plugins/discovery/catkin_discovery_plugin/invalid_package_nopackagexml/CMakeLists.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/plugins/discovery/catkin_discovery_plugin/test_catkin_discovery_plugin.py b/tests/plugins/discovery/catkin_discovery_plugin/test_catkin_discovery_plugin.py deleted file mode 100644 index ed618790..00000000 --- a/tests/plugins/discovery/catkin_discovery_plugin/test_catkin_discovery_plugin.py +++ /dev/null @@ -1,77 +0,0 @@ -"""Unit tests for the catkin discovery plugin.""" -import os - -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.discovery_plugin import DiscoveryPlugin -from statick_tool.package import Package -from statick_tool.plugins.discovery.catkin_discovery_plugin import CatkinDiscoveryPlugin - - -def test_catkin_discovery_plugin_found(): - """Test that the plugin manager can find the Catkin plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Discovery": DiscoveryPlugin, - } - ) - manager.collectPlugins() - # Verify that a plugin's get_name() function returns "catkin" - assert any( - plugin_info.plugin_object.get_name() == "catkin" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - # While we're at it, verify that a plugin is named Catkin Discovery Plugin - assert any( - plugin_info.name == "Catkin Discovery Plugin" - for plugin_info in manager.getPluginsOfCategory("Discovery") - ) - - -def test_catkin_discovery_plugin_scan_valid(): - """Test the behavior when the Catkin plugin scans a valid package.""" - cdp = CatkinDiscoveryPlugin() - package = Package( - "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") - ) - cdp.scan(package, "level") - assert package["catkin"] - - -def test_catkin_discovery_plugin_scan_invalid_badpath(): - """Test the behavior when the Catkin plugin scans a nonexistent directory.""" - cdp = CatkinDiscoveryPlugin() - package = Package( - "invalid_package", os.path.join(os.path.dirname(__file__), "invalid_package") - ) - cdp.scan(package, "level") - assert not package["catkin"] - - -def test_catkin_discovery_plugin_scan_invalid_nocmake(): - """Test the behavior when the Catkin plugin scans a directory with no CMakeLists.txt.""" - cdp = CatkinDiscoveryPlugin() - package = Package( - "invalid_package_nocmakelists", - os.path.join(os.path.dirname(__file__), "invalid_package_nocmakelists"), - ) - cdp.scan(package, "level") - assert not package["catkin"] - - -def test_catkin_discovery_plugin_scan_invalid_packagexml(): - """Test the behavior when the Catkin plugin scans a directory with no package.xml.""" - cdp = CatkinDiscoveryPlugin() - package = Package( - "invalid_package_nopackagexml", - os.path.join(os.path.dirname(__file__), "invalid_package_nopackagexml"), - ) - cdp.scan(package, "level") - assert not package["catkin"] diff --git a/tests/plugins/discovery/catkin_discovery_plugin/valid_package/CMakeLists.txt b/tests/plugins/discovery/catkin_discovery_plugin/valid_package/CMakeLists.txt deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/plugins/discovery/catkin_discovery_plugin/valid_package/package.xml b/tests/plugins/discovery/catkin_discovery_plugin/valid_package/package.xml deleted file mode 100644 index e69de29b..00000000 diff --git a/tests/plugins/reporting/print_json_reporting_plugin/test_print_json_reporting_plugin.py b/tests/plugins/reporting/print_json_reporting_plugin/test_print_json_reporting_plugin.py deleted file mode 100644 index 83d680b7..00000000 --- a/tests/plugins/reporting/print_json_reporting_plugin/test_print_json_reporting_plugin.py +++ /dev/null @@ -1,82 +0,0 @@ -"""Unit tests for the print JSON reporting plugin.""" -import json -import os - -from yapsy.PluginManager import PluginManager - -import statick_tool -from statick_tool.issue import Issue -from statick_tool.package import Package -from statick_tool.plugins.reporting.print_json_reporting_plugin import ( - PrintJsonReportingPlugin, -) -from statick_tool.reporting_plugin import ReportingPlugin - - -def test_print_json_reporting_plugin_found(): - """Test that the plugin manager finds the print json reporting plugin.""" - manager = PluginManager() - # Get the path to statick_tool/__init__.py, get the directory part, and - # add 'plugins' to that to get the standard plugins dir - manager.setPluginPlaces( - [os.path.join(os.path.dirname(statick_tool.__file__), "plugins")] - ) - manager.setCategoriesFilter( - { - "Reporting": ReportingPlugin, - } - ) - manager.collectPlugins() - assert any( - plugin_info.plugin_object.get_name() == "print_json" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - assert any( - plugin_info.name == "Print JSON Reporting Plugin" - for plugin_info in manager.getPluginsOfCategory("Reporting") - ) - - -def test_print_json_reporting_plugin_report_cert(capsys): - """Test the output of the reporting plugin.""" - pjrp = PrintJsonReportingPlugin() - package = Package( - "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") - ) - issues = { - "tool_a": [ - Issue("test.txt", 1, "tool_a", "type", 1, "This is a test", "MEM50-CPP") - ] - } - - pjrp.report(package, issues, "level") - captured = capsys.readouterr() - output = captured.out.splitlines()[0] - assert ( - output - == '{"issues": [{"fileName": "test.txt", "lineNumber": 1, "tool": "tool_a", "type": "type", "severity": 1, "message": "This is a test", "certReference": "MEM50-CPP"}]}' - ) - assert json.loads(output) - - -def test_print_json_reporting_plugin_report_nocert(capsys): - """Test the output of the reporting plugin.""" - pjrp = PrintJsonReportingPlugin() - package = Package( - "valid_package", os.path.join(os.path.dirname(__file__), "valid_package") - ) - issues = { - "tool_a": [ - Issue("test.txt", 1, "tool_a", "type", 1, "This is a test", None), - Issue("test2.txt", 2, "tool_b", "type", 2, "This is a second test", None), - ] - } - - pjrp.report(package, issues, "level") - captured = capsys.readouterr() - output = captured.out.splitlines()[0] - assert ( - output - == '{"issues": [{"fileName": "test.txt", "lineNumber": 1, "tool": "tool_a", "type": "type", "severity": 1, "message": "This is a test", "certReference": ""}, {"fileName": "test2.txt", "lineNumber": 2, "tool": "tool_b", "type": "type", "severity": 2, "message": "This is a second test", "certReference": ""}]}' - ) - assert json.loads(output) diff --git a/tests/statick/test_statick.py b/tests/statick/test_statick.py index a0dbd3c6..a7a0ee16 100644 --- a/tests/statick/test_statick.py +++ b/tests/statick/test_statick.py @@ -1309,26 +1309,3 @@ def test_print_logging_level_invalid(): logger = logging.getLogger() assert logger.getEffectiveLevel() == logging.WARNING - - -def test_show_tool_output_deprecated(caplog): - """Test that the deprecation warning is shown for --show-tool-output flag.""" - args = Args("Statick tool") - args.parser.add_argument("--path", help="Path of package to scan") - - statick = Statick(args.get_user_paths()) - statick.gather_args(args.parser) - sys.argv = [ - "--path", - os.path.dirname(__file__), - "--log", - "INFO", - "--show-tool-output", - ] - args.output_directory = os.path.dirname(__file__) - parsed_args = args.get_args(sys.argv) - statick.set_logging_level(parsed_args) - - print("caplog: {}".format(caplog.text)) - output = caplog.text.splitlines()[1] - assert "The --show-tool-output argument has been deprecated since v0.5.0." in output diff --git a/tox.ini b/tox.ini index c51903a3..f9412cf2 100644 --- a/tox.ini +++ b/tox.ini @@ -36,7 +36,6 @@ passenv = CI setenv = PY_IGNORE_IMPORTMISMATCH = 1 deps = codecov - deprecated flake8-pep3101 pycodestyle pydocstyle