Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pylint checks #98

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions kodi_addon_checker/.pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[Master]

#Files to be ignored
ignore=CVS,ini,xml

# Pickle collected data for later comparisons.
persistent=yes

# Message to be disabled
#disable= R, C, W, E

# All the checks you want
#enable=E0601, R1705, R1703, R1710, E0001, W0611, W0612, W0621, W0622, W0311, W0301, W1501, E0102, W0704, F0401,RP0801, RP0004
enable=R, W, E, F
[REPORTS]

# Python expression which should return a note less than 10 (10 is the highest
# note). You have access to the variables errors warning, statement which
# respectively contain the number of errors / warnings messages and the total
# number of statements analyzed. This is used by the global evaluation report
# (RP0004).
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)

output-format=colorized

# Full report or not
reports=yes

# Activate the evaluation score.
score=yes

[FORMAT]

# Maximum number of characters on a single line.
max-line-length=120

# Maximum number of lines in a module
max-module-lines=300

4 changes: 3 additions & 1 deletion kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from . import (check_allowed_versions, check_artwork, check_dependencies,
check_entrypoint, check_files, check_addon_branches,
check_py3_compatibility, check_string, check_url, common,
handle_files, schema_validation, ValidKodiVersions)
handle_files, pylint_checks, schema_validation, ValidKodiVersions)
from .addons.Addon import Addon
from .addons.Repository import Repository
from .versions import KodiVersion
Expand Down Expand Up @@ -71,6 +71,8 @@ def start(addon_path, args, all_repo_addons, config=None):

check_files.check_file_permission(addon_report, file_index)

pylint_checks.analyze(addon_report, addon_path)

check_files.check_for_invalid_xml_files(addon_report, file_index)

check_files.check_for_invalid_json_files(addon_report, file_index)
Expand Down
66 changes: 66 additions & 0 deletions kodi_addon_checker/pylint_checks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
"""
Copyright (C) 2019 Team Kodi
This file is part of Kodi - kodi.tv

SPDX-License-Identifier: GPL-3.0-only
See LICENSES/README.md for more information.
"""

import io
import json
import os

from pylint.lint import Run
from pylint.reporters.json import JSONReporter
from terminaltables import AsciiTable

from .report import Report
from .record import Record, WARNING, INFORMATION


def analyze(report: Report, filename: str):
table_format = [["Line no", "Message", "message-id"]]

ARGS = ["-r", "n", "--score=yes", "--lint-all=y",
"--rcfile={}/.pylintrc".format(os.path.dirname(os.path.realpath(__file__)))]

out = io.StringIO()
Run([filename] + ARGS, reporter=JSONReporter(out), do_exit=False)

if out.getvalue():
json_data = json.loads(out.getvalue())
paths = []

for dicts in json_data:
paths.append(dicts['path'])

paths = list(set(paths))
data_dict = _path_dictionary(json_data, paths)

for path in paths:
report.add(Record(INFORMATION, (path + '\n')))
for issue in data_dict[path]:
table_format.append([issue['line'], issue['message'], issue['message-id'], ''])
table = AsciiTable(table_format).table
report.add(Record(WARNING, table))
table_format = [["Line no", "Message", "message-id"]]
else:
report.add(Record(INFORMATION, "Addin is free from pylint errors"))


def short_path(path):
return os.path.split(path)[1]


def _path_dictionary(data, paths):
path_dict = {}

for issue in data:
if issue['path'] not in paths:
continue
elif issue['path'] not in path_dict:
path_dict[issue['path']] = [issue]
else:
path_dict[issue['path']].append(issue)

return path_dict
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
packaging
pillow
polib
git+git://github.com/mzfr/pylint.git@master
requests
radon
terminaltables
urllib3
xmlschema