From 02c0d14148d3fda0129c57c09d3db87a638ad644 Mon Sep 17 00:00:00 2001 From: laundmo Date: Sun, 1 Aug 2021 19:26:31 +0200 Subject: [PATCH 1/5] Add __pycache__ to .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 3d99432..d06209e 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ poetry.lock dist docs/build .vscode +__pycache__ \ No newline at end of file From 5a216d7f9769bfa05612bc0fed24a15604894a3f Mon Sep 17 00:00:00 2001 From: laundmo Date: Sun, 1 Aug 2021 19:27:01 +0200 Subject: [PATCH 2/5] Add prospector-json reporter --- pyproject.toml | 1 + src/tidypy/reports/prospector_json.py | 44 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 src/tidypy/reports/prospector_json.py diff --git a/pyproject.toml b/pyproject.toml index a20ca94..e3d1b0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -104,6 +104,7 @@ csv = "tidypy.reports.structured:CsvReport" pylint = "tidypy.reports.pylint:PyLintReport" pylint-parseable = "tidypy.reports.pylint:PyLintParseableReport" null = "tidypy.reports.null:NullReport" +prospector-json = "tidypy.reports.prospector_json:ProspectorJsonReport" [tool.poetry.plugins."tidypy.extenders"] github = "tidypy.extenders.github:GithubExtender" diff --git a/src/tidypy/reports/prospector_json.py b/src/tidypy/reports/prospector_json.py new file mode 100644 index 0000000..9de351e --- /dev/null +++ b/src/tidypy/reports/prospector_json.py @@ -0,0 +1,44 @@ +from datetime import datetime + +import basicserial + +from ..config import get_tools +from .base import Report + + +class ProspectorJsonReport(Report): + """ + Formats the report in Prospector JSON format. + """ + + def execute(self, collector): + issues = collector.get_issues(sortby=("filename", "line", "character")) + result_json = { + "summary": { + "started": datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), + "libraries": [], + "strictness": "from profile", + "profiles": "tidypy", + "tools": list(get_tools().keys()), + "message_count": collector.issue_count(), + "completed": datetime.now().strftime("%Y-%m-%d %H:%M:%S.%f"), + "time_taken": "0", + "formatter": "json", + }, + "messages": [ + { + "source": issue.tool, + "code": issue.code, + "location": { + "path": self.relative_filename(issue.filename), + "module": None, + "function": None, + "line": issue.line, + "character": issue.character or 0, + }, + "message": issue.message, + } + for issue in issues + ], + } + self.output(basicserial.to_json(result_json, pretty=True)) From 0dc39ca147b87d5e0f0078e8ac6c7c2e0fb1986e Mon Sep 17 00:00:00 2001 From: laundmo Date: Sun, 1 Aug 2021 19:34:48 +0200 Subject: [PATCH 3/5] Add egg-info to gitignore --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index d06209e..969b791 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,5 @@ poetry.lock dist docs/build .vscode -__pycache__ \ No newline at end of file +__pycache__ +*.egg-info \ No newline at end of file From 995ae41aa3d2bb5c5665d6286624f696c8122035 Mon Sep 17 00:00:00 2001 From: laundmo Date: Sun, 1 Aug 2021 19:35:09 +0200 Subject: [PATCH 4/5] Add prospector-json to test_get_reports --- test/test_config.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_config.py b/test/test_config.py index 0934e29..36088b1 100644 --- a/test/test_config.py +++ b/test/test_config.py @@ -57,6 +57,7 @@ def test_get_reports(): 'custom', 'json', 'null', + 'prospector-json', 'pycodestyle', 'pylint', 'pylint-parseable', From 3d08b4f95ed7c8827789222c9670a131cdf965b7 Mon Sep 17 00:00:00 2001 From: laundmo Date: Mon, 9 Aug 2021 16:32:19 +0200 Subject: [PATCH 5/5] test prospector-json (fails, please advise) --- test/test_report_prospector.py | 130 +++++++++++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 test/test_report_prospector.py diff --git a/test/test_report_prospector.py b/test/test_report_prospector.py new file mode 100644 index 0000000..51e8eed --- /dev/null +++ b/test/test_report_prospector.py @@ -0,0 +1,130 @@ +from tidypy import execute_reports, get_default_config, Collector, TidyPyIssue + + +ISSUES = [ + TidyPyIssue( + 'code1', + 'Message 1', + u'someproject/foo.py', + 5, + 23, + ), + TidyPyIssue( + 'code2', + 'Message 2', + u'someproject/foo.py', + 2, + ), + TidyPyIssue( + 'code1', + 'Message 1', + 'someproject/blah/bar.py', + 28, + ), + TidyPyIssue( + 'code3', + 'Message 3', + 'someproject/subdir/foobar.json', + 5, + 23, + ), +] + + +EXPECTED_JSON = '''{ + "summary": { + "started": "2021-08-09 16:27:54.695977", + "libraries": [], + "strictness": "from profile", + "profiles": "tidypy", + "tools": [ + "bandit", + "dlint", + "eradicate", + "jsonlint", + "manifest", + "mccabe", + "polint", + "pycodestyle", + "pydiatra", + "pydocstyle", + "pyflakes", + "pylint", + "pyroma", + "rstlint", + "secrets", + "vulture", + "yamllint" + ], + "message_count": 4, + "completed": "2021-08-09 16:27:54.695977", + "time_taken": "0", + "formatter": "json" + }, + "messages": [ + { + "source": "tidypy", + "code": "code1", + "location": { + "path": "blah/bar.py", + "module": null, + "function": null, + "line": 28, + "character": 0 + }, + "message": "Message 1" + }, + { + "source": "tidypy", + "code": "code2", + "location": { + "path": "foo.py", + "module": null, + "function": null, + "line": 2, + "character": 0 + }, + "message": "Message 2" + }, + { + "source": "tidypy", + "code": "code1", + "location": { + "path": "foo.py", + "module": null, + "function": null, + "line": 5, + "character": 23 + }, + "message": "Message 1" + }, + { + "source": "tidypy", + "code": "code3", + "location": { + "path": "subdir/foobar.json", + "module": null, + "function": null, + "line": 5, + "character": 23 + }, + "message": "Message 3" + } + ] +} +''' + + +def test_json_execute(capsys): + cfg = get_default_config() + cfg['requested_reports'] = [{'type': 'prospector-json'}] + + collector = Collector(cfg) + collector.add_issues(ISSUES) + + execute_reports(cfg, 'someproject', collector) + + out, err = capsys.readouterr() + + assert EXPECTED_JSON == out.replace('\r\n', '\n') + assert err == ''