Skip to content

Commit

Permalink
Merge pull request #186 from sommersoft/run_pylint
Browse files Browse the repository at this point in the history
Add Validator To Run Pylint On Libraries
  • Loading branch information
kattni committed Sep 10, 2020
2 parents b17b8fd + 4b87cac commit c01bb3a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
57 changes: 57 additions & 0 deletions adabot/lib/circuitpython_library_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import datetime
import json
import pathlib
import re
from tempfile import TemporaryDirectory

from pylint import epylint as linter

import requests

import sh
from sh.contrib import git

from adabot import github_requests as github
from adabot import pypi_requests as pypi
from adabot.lib import common_funcs
Expand Down Expand Up @@ -99,6 +107,7 @@
ERROR_NOT_ON_PYPI = "Not listed on PyPi for CPython use"
ERROR_PYLINT_VERSION_NOT_FIXED = "PyLint version not fixed"
ERROR_PYLINT_VERSION_NOT_LATEST = "PyLint version not latest"
ERROR_PYLINT_FAILED_LINTING = "Failed PyLint checks"
ERROR_NEW_REPO_IN_WORK = "New repo(s) currently in work, and unreleased"

# Temp category for GitHub Actions migration.
Expand Down Expand Up @@ -1041,3 +1050,51 @@ def validate_labels(self, repo):
errors.append(ERROR_MISSING_STANDARD_LABELS)

return errors

def validate_passes_linting(self, repo):
""" Clones the repo and runs pylint on the Python files"""
if not repo["name"].startswith("Adafruit_CircuitPython"):
return []

ignored_py_files = ["setup.py", "conf.py"]

with TemporaryDirectory() as tempdir:
repo_dir = pathlib.Path(tempdir) / repo["name"]
try:
git.clone("--depth=1", repo["git_url"], repo_dir)
except sh.ErrorReturnCode as err:
self.output_file_data.append(
f"Failed to clone repo for linting: {repo['full_name']}\n {err.stderr}"
)
return [ERROR_OUTPUT_HANDLER]

for file in repo_dir.rglob("*.py"):
if not file.name in ignored_py_files and not str(file.parent).endswith("examples"):
py_run_args = f"{file} --output-format=json"
if (repo_dir / '.pylintrc').exists():
py_run_args += (
f" --rcfile={str(repo_dir / '.pylintrc')}"
)

pylint_stdout, pylint_stderr = linter.py_run(
py_run_args,
return_std=True
)

if pylint_stderr.getvalue():
self.output_file_data.append(
f"PyLint error ({repo['name']}): '{pylint_stderr.getvalue()}'"
)
return [ERROR_OUTPUT_HANDLER]

try:
pylint_result = json.loads(pylint_stdout.getvalue())
except json.JSONDecodeError as json_err:
self.output_file_data.append(
f"PyLint output JSONDecodeError: {json_err.msg}"
)
return [ERROR_OUTPUT_HANDLER]

if pylint_result:
return [ERROR_PYLINT_FAILED_LINTING]
return []
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ certifi==2017.11.5
chardet==3.0.4
idna==2.6
packaging==20.3
pylint
redis==2.10.6
requests==2.20.0
sh==1.12.14
Expand Down

0 comments on commit c01bb3a

Please sign in to comment.