Skip to content

Commit d22437b

Browse files
authored
Merge pull request #198 from rhooper/fix-stray-stuff-in-output
Fix a bug where an error was a string instead of a list.
2 parents 665d9ae + 35c29c3 commit d22437b

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

adabot/lib/circuitpython_library_validators.py

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@
2424
import logging
2525
import pathlib
2626
import re
27+
from io import StringIO
2728
from tempfile import TemporaryDirectory
2829

29-
from pylint import epylint as linter
30-
3130
import requests
3231

3332
import sh
33+
from pylint import lint
34+
from pylint.reporters import JSONReporter
3435
from sh.contrib import git
3536

3637
from adabot import github_requests as github
@@ -42,6 +43,15 @@
4243
from packaging.requirements import Requirement as pkg_Requirement
4344

4445

46+
class CapturedJsonReporter(JSONReporter):
47+
48+
def __init__(self):
49+
self._stringio = StringIO()
50+
super().__init__(self._stringio)
51+
52+
def get_result(self):
53+
return self._stringio.getvalue()
54+
4555
# Define constants for error strings to make checking against them more robust:
4656
ERROR_README_DOWNLOAD_FAILED = "Failed to download README"
4757
ERROR_README_IMAGE_MISSING_ALT = "README image missing alt text"
@@ -166,6 +176,7 @@
166176
# Cache the CircuitPython driver page so we can make sure every driver is linked to.
167177
core_driver_page = None
168178

179+
169180
class library_validator():
170181
""" Class to hold instance variables needed to traverse the calling
171182
code, and the validator functions.
@@ -1084,27 +1095,26 @@ def validate_passes_linting(self, repo):
10841095
if file.name in ignored_py_files or str(file.parent).endswith("examples"):
10851096
continue
10861097

1087-
py_run_args = f"{file} --output-format=json"
1098+
pylint_args = [str(file)]
10881099
if (repo_dir / '.pylintrc').exists():
1089-
py_run_args += (
1090-
f" --rcfile={str(repo_dir / '.pylintrc')}"
1091-
)
1100+
pylint_args += [f"--rcfile={str(repo_dir / '.pylintrc')}"]
1101+
1102+
reporter = CapturedJsonReporter()
10921103

10931104
logging.debug("Running pylint on %s", file)
10941105

1095-
pylint_stdout, pylint_stderr = linter.py_run(
1096-
py_run_args,
1097-
return_std=True
1098-
)
1106+
linted = lint.Run(pylint_args, reporter=reporter, exit=False)
1107+
pylint_stderr = ''
1108+
pylint_stdout = reporter.get_result()
10991109

1100-
if pylint_stderr.getvalue():
1110+
if pylint_stderr:
11011111
self.output_file_data.append(
1102-
f"PyLint error ({repo['name']}): '{pylint_stderr.getvalue()}'"
1112+
f"PyLint error ({repo['name']}): '{pylint_stderr}'"
11031113
)
11041114
return [ERROR_OUTPUT_HANDLER]
11051115

11061116
try:
1107-
pylint_result = json.loads(pylint_stdout.getvalue())
1117+
pylint_result = json.loads(pylint_stdout)
11081118
except json.JSONDecodeError as json_err:
11091119
self.output_file_data.append(
11101120
f"PyLint output JSONDecodeError: {json_err.msg}"
@@ -1116,6 +1126,6 @@ def validate_passes_linting(self, repo):
11161126

11171127
if self.keep_repos:
11181128
with open(repo_dir / '.pylint-ok', 'w') as f:
1119-
f.write(pylint_result)
1129+
f.write(''.join(pylint_result))
11201130

11211131
return []

adabot/update_cp_org_libraries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ def get_contributors(repo):
244244
errors = validator.run_repo_validation(repo)
245245
except Exception as e:
246246
logging.exception("Unhandled exception %s", str(e))
247-
errors.extend(cpy_vals.ERROR_OUTPUT_HANDLER)
247+
errors.extend([cpy_vals.ERROR_OUTPUT_HANDLER])
248248
for error in errors:
249249
if not isinstance(error, tuple):
250250
# check for an error occurring in the validator module

0 commit comments

Comments
 (0)