From b282b3ef34e288e6397618e1f091ec328a4bf564 Mon Sep 17 00:00:00 2001 From: Dag Wieers Date: Wed, 25 Mar 2020 08:08:15 +0100 Subject: [PATCH] Various check fixes (#11) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Various check fixes This PR includes: - Fix invalid-name pylint check - Enable overriding PYTHON in Makefile - Supporting multiple languages * Add invalid-name to routing tests Co-authored-by: Michaƫl Arnauts --- .pylintrc | 3 +-- Makefile | 28 ++++++++++++------------ resources/lib/addon.py | 2 +- resources/lib/modules/catalog.py | 10 ++++----- resources/lib/service.py | 2 +- resources/lib/viervijfzes/auth.py | 12 +++++----- resources/lib/viervijfzes/auth_awsidp.py | 8 +++---- resources/lib/viervijfzes/content.py | 15 ++++++------- resources/lib/viervijfzes/epg.py | 1 + test/test_routing.py | 12 +++++----- tox.ini | 3 ++- 11 files changed, 48 insertions(+), 48 deletions(-) diff --git a/.pylintrc b/.pylintrc index edb8912..f88d6b4 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,10 +1,10 @@ [MESSAGES CONTROL] disable= bad-option-value, + cyclic-import, # This shoud be fixed duplicate-code, fixme, import-outside-toplevel, - invalid-name, line-too-long, old-style-class, too-few-public-methods, @@ -13,4 +13,3 @@ disable= too-many-instance-attributes, too-many-locals, too-many-public-methods, - cyclic-import, # This shoud be fixed \ No newline at end of file diff --git a/Makefile b/Makefile index 682c45d..3535dca 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,20 @@ -ENVS = py27,py36,py37 export PYTHONPATH := $(CURDIR):$(CURDIR)/test +PYTHON := python # Collect information to build as sensible package name -name = plugin.video.viervijfzes +name = $(shell xmllint --xpath 'string(/addon/@id)' addon.xml) version = $(shell xmllint --xpath 'string(/addon/@version)' addon.xml) git_branch = $(shell git rev-parse --abbrev-ref HEAD) git_hash = $(shell git rev-parse --short HEAD) zip_name = $(name)-$(version)-$(git_branch)-$(git_hash).zip -include_files = addon_entry.py addon.xml CHANGELOG.md LICENSE README.md service_entry.py resources/ +include_files = addon_entry.py addon.xml CHANGELOG.md LICENSE README.md resources/ service_entry.py include_paths = $(patsubst %,$(name)/%,$(include_files)) exclude_files = \*.new \*.orig \*.pyc \*.pyo +languages = $(filter-out en_gb, $(patsubst resources/language/resource.language.%, %, $(wildcard resources/language/*))) + +.PHONY: check test + all: check test build zip: build @@ -18,15 +22,17 @@ check: check-pylint check-tox check-translations check-pylint: @echo ">>> Running pylint checks" - @pylint *.py resources/ test/ + @$(PYTHON) -m pylint *.py resources/lib/ test/ check-tox: @echo ">>> Running tox checks" - @tox -q + @$(PYTHON) -m tox -q check-translations: @echo ">>> Running translation checks" - @msgcmp resources/language/resource.language.nl_nl/strings.po resources/language/resource.language.en_gb/strings.po + @$(foreach lang,$(languages), \ + msgcmp resources/language/resource.language.$(lang)/strings.po resources/language/resource.language.en_gb/strings.po; \ + ) check-addon: clean build @echo ">>> Running addon checks" @@ -43,7 +49,7 @@ ifdef GITHUB_ACTIONS @coverage run -m unittest discover @coverage xml else - @python -m unittest discover -v -b -f + @$(PYTHON) -m unittest discover -v -b -f endif clean: @@ -60,11 +66,5 @@ build: clean @echo "Successfully wrote package as: ../$(zip_name)" release: build - rm -rf ../repo-plugins/plugin.video.viervijfzes/* + rm -rf ../repo-plugins/$(name)/* unzip ../$(zip_name) -d ../repo-plugins/ - -run: - @echo ">>> Run CLI" - python test/run.py / - -.PHONY: check test diff --git a/resources/lib/addon.py b/resources/lib/addon.py index 65f287a..e7382eb 100644 --- a/resources/lib/addon.py +++ b/resources/lib/addon.py @@ -10,7 +10,7 @@ from routing import Plugin from resources.lib import kodilogging kodilogging.config() -routing = Plugin() +routing = Plugin() # pylint: disable=invalid-name _LOGGER = logging.getLogger('addon') diff --git a/resources/lib/modules/catalog.py b/resources/lib/modules/catalog.py index 0a266f5..9ff8e9c 100644 --- a/resources/lib/modules/catalog.py +++ b/resources/lib/modules/catalog.py @@ -104,18 +104,18 @@ class Catalog: ) # Add the seasons - for s in list(program.seasons.values()): + for season in list(program.seasons.values()): listing.append( TitleItem( - title=s.title, # kodiutils.localize(30205, season=s.number), # Season {season} - path=kodiutils.url_for('show_catalog_program_season', channel=channel, program=program_id, season=s.uuid), + title=season.title, # kodiutils.localize(30205, season=season.number), # Season {season} + path=kodiutils.url_for('show_catalog_program_season', channel=channel, program=program_id, season=season.uuid), art_dict={ 'fanart': program.background, }, info_dict={ 'tvshowtitle': program.title, - 'title': kodiutils.localize(30205, season=s.number), # Season {season} - 'plot': s.description, + 'title': kodiutils.localize(30205, season=season.number), # Season {season} + 'plot': season.description, 'set': program.title, 'studio': studio, } diff --git a/resources/lib/service.py b/resources/lib/service.py index be37472..e3fac5b 100644 --- a/resources/lib/service.py +++ b/resources/lib/service.py @@ -39,7 +39,7 @@ class BackgroundService(Monitor): _LOGGER.info('Service stopped') - def onSettingsChanged(self): + def onSettingsChanged(self): # pylint: disable=invalid-name """ Callback when a setting has changed """ if self._has_credentials_changed(): _LOGGER.info('Clearing auth tokens due to changed credentials') diff --git a/resources/lib/viervijfzes/auth.py b/resources/lib/viervijfzes/auth.py index 445febb..7341fe8 100644 --- a/resources/lib/viervijfzes/auth.py +++ b/resources/lib/viervijfzes/auth.py @@ -32,8 +32,8 @@ class AuthApi: # Load tokens from cache try: - with kodiutils.open_file(self._cache_dir + self.TOKEN_FILE, 'rb') as f: - data_json = json.loads(f.read()) + with kodiutils.open_file(self._cache_dir + self.TOKEN_FILE, 'rb') as fdesc: + data_json = json.loads(fdesc.read()) self._id_token = data_json.get('id_token') self._refresh_token = data_json.get('refresh_token') self._expiry = int(data_json.get('expiry', 0)) @@ -57,8 +57,8 @@ class AuthApi: self._id_token = self._refresh(self._refresh_token) self._expiry = now + 3600 _LOGGER.debug('Got an id token by refreshing: %s', self._id_token) - except (InvalidLoginException, AuthenticationException) as e: - _LOGGER.error('Error logging in: %s', str(e)) + except (InvalidLoginException, AuthenticationException) as exc: + _LOGGER.error('Error logging in: %s', str(exc)) self._id_token = None self._refresh_token = None self._expiry = 0 @@ -76,13 +76,13 @@ class AuthApi: # Store new tokens in cache if not kodiutils.exists(self._cache_dir): kodiutils.mkdirs(self._cache_dir) - with kodiutils.open_file(self._cache_dir + self.TOKEN_FILE, 'wb') as f: + with kodiutils.open_file(self._cache_dir + self.TOKEN_FILE, 'wb') as fdesc: data = json.dumps(dict( id_token=self._id_token, refresh_token=self._refresh_token, expiry=self._expiry, )) - f.write(data.encode('utf8')) + fdesc.write(data.encode('utf8')) return self._id_token diff --git a/resources/lib/viervijfzes/auth_awsidp.py b/resources/lib/viervijfzes/auth_awsidp.py index 72884c8..eb5fd2e 100644 --- a/resources/lib/viervijfzes/auth_awsidp.py +++ b/resources/lib/viervijfzes/auth_awsidp.py @@ -71,8 +71,8 @@ class AwsIdp: self.info_bits = bytearray('Caldera Derived Key', 'utf-8') self.big_n = self.__hex_to_long(self.n_hex) - self.g = self.__hex_to_long(self.g_hex) - self.k = self.__hex_to_long(self.__hex_hash('00' + self.n_hex + '0' + self.g_hex)) + self.g = self.__hex_to_long(self.g_hex) # pylint: disable=invalid-name + self.k = self.__hex_to_long(self.__hex_hash('00' + self.n_hex + '0' + self.g_hex)) # pylint: disable=invalid-name self.small_a_value = self.__generate_random_small_a() self.large_a_value = self.__calculate_a() _LOGGER.debug("Created %s", self) @@ -299,8 +299,8 @@ class AwsIdp: @staticmethod def __hash_sha256(buf): """AuthenticationHelper.hash""" - a = hashlib.sha256(buf).hexdigest() - return (64 - len(a)) * '0' + a + digest = hashlib.sha256(buf).hexdigest() + return (64 - len(digest)) * '0' + digest @staticmethod def __pad_hex(long_int): diff --git a/resources/lib/viervijfzes/content.py b/resources/lib/viervijfzes/content.py index 2ac2325..596146e 100644 --- a/resources/lib/viervijfzes/content.py +++ b/resources/lib/viervijfzes/content.py @@ -187,9 +187,9 @@ class ContentApi: content_tree = self.get_content_tree(channel) programs = [] - for p in content_tree['programs']: + for uuid in content_tree['programs']: try: - program = self.get_program_by_uuid(p) + program = self.get_program_by_uuid(uuid) program.channel = channel programs.append(program) except UnavailableException: @@ -211,7 +211,7 @@ class ContentApi: data = self._get_url(CHANNELS[channel]['url']) # Parse programs - h = HTMLParser() + parser = HTMLParser() regex_programs = re.compile(r'\s+' r'\s+(?P[^<]+)</span>.*?' r'</a>', re.DOTALL) @@ -228,8 +228,7 @@ class ContentApi: # Use program with the values that we've parsed from the page programs.append(Program(channel=channel, path=path, - title=h.unescape(item.group('title').strip()))) - + title=parser.unescape(item.group('title').strip()))) return programs def get_program(self, channel, path, cache=CACHE_AUTO): @@ -314,15 +313,15 @@ class ContentApi: page = self._get_url(CHANNELS[channel]['url'] + '/' + path) # Extract program JSON - h = HTMLParser() + parser = HTMLParser() regex_program = re.compile(r'data-hero="([^"]+)', re.DOTALL) - json_data = h.unescape(regex_program.search(page).group(1)) + json_data = parser.unescape(regex_program.search(page).group(1)) data = json.loads(json_data)['data'] program = self._parse_program_data(data) # Extract episode JSON regex_episode = re.compile(r'<script type="application/json" data-drupal-selector="drupal-settings-json">(.*?)</script>', re.DOTALL) - json_data = h.unescape(regex_episode.search(page).group(1)) + json_data = parser.unescape(regex_episode.search(page).group(1)) data = json.loads(json_data) # Lookup the episode in the program JSON based on the nodeId diff --git a/resources/lib/viervijfzes/epg.py b/resources/lib/viervijfzes/epg.py index aef942d..2cf0e21 100644 --- a/resources/lib/viervijfzes/epg.py +++ b/resources/lib/viervijfzes/epg.py @@ -16,6 +16,7 @@ _LOGGER = logging.getLogger('epg-api') class EpgProgram: """ Defines a Program in the EPG. """ + # pylint: disable=invalid-name def __init__(self, channel, program_title, episode_title, episode_title_original, number, season, genre, start, won_id, won_program_id, program_description, description, duration, program_url, video_url, cover, airing): self.channel = channel diff --git a/test/test_routing.py b/test/test_routing.py index ce6cbdb..dfebaf3 100644 --- a/test/test_routing.py +++ b/test/test_routing.py @@ -9,13 +9,13 @@ import unittest from resources.lib import addon -xbmc = __import__('xbmc') -xbmcaddon = __import__('xbmcaddon') -xbmcgui = __import__('xbmcgui') -xbmcplugin = __import__('xbmcplugin') -xbmcvfs = __import__('xbmcvfs') +xbmc = __import__('xbmc') # pylint: disable=invalid-name +xbmcaddon = __import__('xbmcaddon') # pylint: disable=invalid-name +xbmcgui = __import__('xbmcgui') # pylint: disable=invalid-name +xbmcplugin = __import__('xbmcplugin') # pylint: disable=invalid-name +xbmcvfs = __import__('xbmcvfs') # pylint: disable=invalid-name -routing = addon.routing +routing = addon.routing # pylint: disable=invalid-name class TestRouting(unittest.TestCase): diff --git a/tox.ini b/tox.ini index ff4f2da..41396ec 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py36,py37,flake8 +envlist = py27,py36,py37,py38,flake8 skipsdist = True skip_missing_interpreters = True @@ -17,6 +17,7 @@ max-line-length = 160 ignore = FI13,FI50,FI51,FI53,FI54,W503 require-code = True min-version = 2.7 +exclude = .git,.tox [pytest] filterwarnings = default