Skip to content

Commit

Permalink
fixed pylint error. score improved from 9.49/10 to 9.92/10
Browse files Browse the repository at this point in the history
  • Loading branch information
Shanmugapriya03 committed Oct 3, 2019
1 parent 31c54f6 commit bcd8274
Show file tree
Hide file tree
Showing 26 changed files with 132 additions and 133 deletions.
2 changes: 0 additions & 2 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ disable=import-error,
no-name-in-module,

missing-docstring,
too-few-public-methods,
invalid-name,
useless-else-on-loop,
too-many-nested-blocks,

Expand Down
2 changes: 1 addition & 1 deletion kodi_addon_checker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

__version__ = "0.0.14"

ValidKodiVersions = [
VALID_KODI_VERSIONS = [
"gotham",
"helix",
"isengard",
Expand Down
4 changes: 2 additions & 2 deletions kodi_addon_checker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os
import sys

from kodi_addon_checker import __version__, check_addon, ValidKodiVersions
from kodi_addon_checker import __version__, check_addon, VALID_KODI_VERSIONS
from kodi_addon_checker.check_repo import check_repo
from kodi_addon_checker.common import load_plugins
from kodi_addon_checker.config import Config, ConfigManager
Expand Down Expand Up @@ -70,7 +70,7 @@ def main():
parser.add_argument("--version", action="version",
version="%(prog)s {version}".format(version=__version__))
parser.add_argument("dir", type=dir_type, nargs="*", help="optional add-on or repo directories")
parser.add_argument("--branch", choices=ValidKodiVersions, required=True,
parser.add_argument("--branch", choices=VALID_KODI_VERSIONS, required=True,
help="Target branch name where the checker will resolve dependencies")
parser.add_argument("--PR", help="Tell if tool is to run on a pull requests or not", action='store_true')
parser.add_argument("--allow-folder-id-mismatch", help="Allow the addon's folder name and id to mismatch",
Expand Down
6 changes: 3 additions & 3 deletions kodi_addon_checker/addons/Addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import xml.etree.ElementTree as ET

from .AddonDependency import AddonDependency
from .addon_dependency import AddonDependency


class Addon():
Expand All @@ -23,8 +23,8 @@ def __init__(self, addon_xml: ET.Element):
def __eq__(self, other):
return self.id == other.id and self.version == other.version

def dependsOn(self, addonId):
def depends_on(self, addon_id):
for dependency in self.dependencies:
if dependency.id == addonId:
if dependency.id == addon_id:
return True
return False
14 changes: 7 additions & 7 deletions kodi_addon_checker/addons/Repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import requests

from .Addon import Addon
from .addon import Addon


class Repository():
Expand All @@ -31,21 +31,21 @@ def __init__(self, version, path):
for addon in tree.findall("addon"):
self.addons.append(Addon(addon))

def __contains__(self, addonId):
def __contains__(self, addon_id):
for addon in self.addons:
if addon.id == addonId:
if addon.id == addon_id:
return True
return False

def find(self, addonId):
def find(self, addon_id):
for addon in self.addons:
if addon.id == addonId:
if addon.id == addon_id:
return addon
return None

def rdepends(self, addonId):
def rdepends(self, addon_id):
rdepends = []
for addon in self.addons:
if addon.dependsOn(addonId):
if addon.depends_on(addon_id):
rdepends.append(addon)
return rdepends
8 changes: 4 additions & 4 deletions kodi_addon_checker/check_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
from . import (check_artwork, check_dependencies, check_entrypoint,
check_files, check_old_addon, check_py3_compatibility,
check_string, check_url, common, handle_files,
schema_validation, ValidKodiVersions)
from .addons.Repository import Repository
from .KodiVersion import KodiVersion
schema_validation, VALID_KODI_VERSIONS)
from .addons.repository import Repository
from .kodi_version import KodiVersion
from .record import INFORMATION, Record
from .report import Report

Expand Down Expand Up @@ -116,7 +116,7 @@ def get_all_repo_addons():

repo_addons = {}

for branch in ValidKodiVersions:
for branch in VALID_KODI_VERSIONS:
branch_url = ROOT_URL.format(branch=branch)
repo_addons[branch] = Repository(branch, branch_url)

Expand Down
14 changes: 7 additions & 7 deletions kodi_addon_checker/check_artwork.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from PIL import Image

from .common import has_transparency, relative_path
from .KodiVersion import KodiVersion
from .kodi_version import KodiVersion
from .record import INFORMATION, PROBLEM, WARNING, Record
from .report import Report

Expand Down Expand Up @@ -55,17 +55,17 @@ def _check_image_type(report: Report, image_type: str, parsed_xml, addon_path: s
report.add(Record(
PROBLEM, "Image %s should be explicitly declared in addon.xml <assets>." % image_type))
try:
im = Image.open(filepath)
width, height = im.size
img = Image.open(filepath)
width, height = img.size

if image_type == "icon":
_check_icon(report, im, width, height)
_check_icon(report, img, width, height)

elif image_type == "fanart":
_check_fanart(report, width, height)
else:
# screenshots have no size definitions
if has_transparency(im):
if has_transparency(img):
report.add(Record(PROBLEM, "%s should be solid. It has transparency." % image))
LOGGER.info("Artwork was a screenshot")
except IOError:
Expand Down Expand Up @@ -108,14 +108,14 @@ def _assests(image_type: str, parsed_xml, addon_path: str):
return fallback, images


def _check_icon(report: Report, im, width, height):
def _check_icon(report: Report, img, width, height):
"""Check the icon of the addon for transparency and dimensions
:im: PIL.Image object
:width: width of the icon
:height: height of the icon
"""
if has_transparency(im):
if has_transparency(img):
report.add(Record(PROBLEM, "Icon.png should be solid. It has transparency."))

icon_sizes = [(256, 256), (512, 512)]
Expand Down
49 changes: 25 additions & 24 deletions kodi_addon_checker/check_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
import logging
from distutils.version import LooseVersion

from .addons.Addon import Addon
from .KodiVersion import KodiVersion
from .addons.addon import Addon
from .kodi_version import KodiVersion
from .record import INFORMATION, PROBLEM, WARNING, Record
from .report import Report

common_ignore_deps = ['xbmc.metadata.scraper.albums', 'xbmc.metadata.scraper.movies',
COMMON_IGNORE_DEPS = ['xbmc.metadata.scraper.albums', 'xbmc.metadata.scraper.movies',
'xbmc.metadata.scraper.musicvideos', 'xbmc.metadata.scraper.tvshows',
'xbmc.metadata.scraper.library', 'xbmc.ui.screensaver', 'xbmc.player.musicviz',
'xbmc.python.pluginsource', 'xbmc.python.script', 'xbmc.python.weather', 'xbmc.python.lyrics',
Expand All @@ -27,7 +27,7 @@
'kodi.resource.font', 'kodi.inputstream', 'kodi.vfs', 'kodi.imagedecoder', 'xbmc.addon',
'xbmc.gui', 'xbmc.json', 'xbmc.metadata', 'xbmc.python', 'script.module.pil']

extensions = {"kodi.gameclient": "kodi.binary.instance.game",
EXTENSIONS = {"kodi.gameclient": "kodi.binary.instance.game",
"xbmc.gui.skin": "xbmc.gui",
"kodi.vfs": "kodi.binary.instance.vfs",
"xbmc.metadata.scraper.albums": "xbmc.metadata",
Expand Down Expand Up @@ -92,7 +92,8 @@ def check_addon_dependencies(report: Report, repo_addons: dict, parsed_xml, bran
report.add(Record(WARNING, "For {} it is advised to set {} version to {}"
.format(branch_name, dependency.id, version)))
except KeyError:
LOGGER.warning("Misconfiguration in VERSION_ATTRB of check_dependencies")
LOGGER.warning(
"Misconfiguration in VERSION_ATTRB of check_dependencies")

_check_extensions(report, parsed_xml, addon)

Expand All @@ -106,38 +107,38 @@ def check_reverse_dependencies(report: Report, addon: str, branch_name: str, all
:all_repo_addons: a nested list having information
about all the repo addonst
"""
addonInRepo = None
addon_in_repo = None
rdepends = []
rdependsLowerBranch = []
branchFound = False
rdepends_lwr_branch = []
branch_found = False

for branch, repo in sorted(all_repo_addons.items()):
if not branchFound and branch != branch_name:
if not branch_found and branch != branch_name:
for rdepend in repo.rdepends(addon):
if rdepend not in rdependsLowerBranch:
rdependsLowerBranch.append(rdepend)
if rdepend not in rdepends_lwr_branch:
rdepends_lwr_branch.append(rdepend)
continue
branchFound = True
branch_found = True

addonFind = repo.find(addon)
if addonFind and addonInRepo and addonFind != addonInRepo:
addon_find = repo.find(addon)
if addon_find and addon_in_repo and addon_find != addon_in_repo:
break

addonInRepo = addonFind
addon_in_repo = addon_find

for rdepend in repo.rdepends(addon):
if rdepend not in rdependsLowerBranch and rdepend not in rdepends:
if rdepend not in rdepends_lwr_branch and rdepend not in rdepends:
rdepends.append(rdepend)
if addon.startswith("script.module.") and len(rdepends) + len(rdependsLowerBranch) == 0:
if addon.startswith("script.module.") and len(rdepends) + len(rdepends_lwr_branch) == 0:
report.add(Record(WARNING, "This module isn't required by any add-on."))

if rdepends:
report.add(Record(INFORMATION, "Reverse dependencies: {} ({})"
.format(", ".join(sorted([r.id for r in rdepends])), len(rdepends))))

if rdependsLowerBranch:
if rdepends_lwr_branch:
report.add(Record(INFORMATION, "Reverse dependencies (in lower branches): {} ({})"
.format(", ".join(sorted([r.id for r in rdependsLowerBranch])), len(rdependsLowerBranch))))
.format(", ".join(sorted([r.id for r in rdepends_lwr_branch])), len(rdepends_lwr_branch))))


def _get_ignore_list(kodi_version: KodiVersion):
Expand All @@ -146,12 +147,12 @@ def _get_ignore_list(kodi_version: KodiVersion):
"""

if kodi_version == KodiVersion("leia"):
common_ignore_deps.extend(["script.module.pycryptodome"])
COMMON_IGNORE_DEPS.extend(["script.module.pycryptodome"])

if kodi_version == KodiVersion("krypton"):
common_ignore_deps.extend(["inputstream.adaptive", "inputstream.rtmp"])
COMMON_IGNORE_DEPS.extend(["inputstream.adaptive", "inputstream.rtmp"])

return common_ignore_deps
return COMMON_IGNORE_DEPS


def _check_extensions(report: Report, parsed_xml, addon):
Expand All @@ -164,6 +165,6 @@ def _check_extensions(report: Report, parsed_xml, addon):

for extension in parsed_xml.findall("extension"):
point = extension.get("point")
if point in extensions and extensions[point] not in deps:
if point in EXTENSIONS and EXTENSIONS[point] not in deps:
report.add(Record(PROBLEM, "{} dependency is required for {} extensions"
.format(extensions[point], point)))
.format(EXTENSIONS[point], point)))
8 changes: 4 additions & 4 deletions kodi_addon_checker/check_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def _number_of_lines(report: Report, filepath: str, library: str, max_entrypoint
"Complex entry point. Check: %s | Counted lines: %d | Lines allowed: %d"
% (library, lineno, max_entrypoint_count)))

except UnicodeDecodeError as e:
report.add(Record(PROBLEM, "UnicodeDecodeError: {}".format(e)))
except UnicodeDecodeError as excep:
report.add(Record(PROBLEM, "UnicodeDecodeError: {}".format(excep)))

except SyntaxError as e:
if e.msg == 'SyntaxError at line: 1':
except SyntaxError as excep:
if excep.msg == 'SyntaxError at line: 1':
report.add(Record(PROBLEM,
("Error parsing file, is your file saved with UTF-8 encoding? "
"Make sure it has no BOM. Check: %s")
Expand Down
12 changes: 6 additions & 6 deletions kodi_addon_checker/check_old_addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
import xml.etree.ElementTree as ET
from distutils.version import LooseVersion

from .KodiVersion import KodiVersion
from .kodi_version import KodiVersion
from .record import INFORMATION, PROBLEM, Record
from .report import Report

LOGGER = logging.getLogger(__name__)


def check_for_existing_addon(report: Report, addon_path: str, all_repo_addons: dict, pr: bool,
def check_for_existing_addon(report: Report, addon_path: str, all_repo_addons: dict, preq: bool,
kodi_version: KodiVersion):
"""Check if addon submitted already exists or not
:addon_path: path of the addon
Expand All @@ -31,7 +31,7 @@ def check_for_existing_addon(report: Report, addon_path: str, all_repo_addons: d

for branch, repo in sorted(all_repo_addons.items(), reverse=True):
if KodiVersion(branch) <= kodi_version and addon_name in repo:
_check_versions(report, addon_details, branch, repo.find(addon_name).version, pr)
_check_versions(report, addon_details, branch, repo.find(addon_name).version, preq)
return

report.add(Record(INFORMATION, "This is a new addon"))
Expand All @@ -46,19 +46,19 @@ def _get_addon_name(xml_path: str):
return (tree.get("id"), tree.get("version"))


def _check_versions(report: Report, addon_details, branch, repo_addons_version, pr):
def _check_versions(report: Report, addon_details, branch, repo_addons_version, preq):
"""Check for version bump in the existing addon
:addon_details: a dict containing name and version of the addon {'name': .., 'version': ..}
:branch: branch of the addon present in Kodi repository
:repo_addons_version: version of addon present in Kodi repository
:pr: boolean value indicating whether the check is
:preq: boolean value indicating whether the check is
running on pull request or not
"""
addon_name = addon_details.get('name')
addon_version = addon_details.get('version')

if pr:
if preq:
if LooseVersion(addon_version) > LooseVersion(repo_addons_version):
LOGGER.info("%s addon have greater version: %s than repo_version: %s in branch %s",
addon_name, addon_version, repo_addons_version, branch)
Expand Down
Loading

0 comments on commit bcd8274

Please sign in to comment.