From 85e0ab4b51112fc1879512bc034aa9023749634c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Alvergnat?= Date: Sun, 14 Oct 2018 21:32:15 +0200 Subject: [PATCH] Add python 3.7 support and fix pylint issues --- .travis.yml | 8 +++++++- guessit/jsonutils.py | 6 +++--- guessit/rules/common/date.py | 6 +++--- guessit/rules/properties/country.py | 2 +- guessit/rules/properties/episodes.py | 8 ++++---- guessit/rules/properties/language.py | 2 +- guessit/rules/properties/other.py | 2 +- guessit/rules/properties/title.py | 6 +++--- guessit/test/test_yml.py | 30 ++++++++++++---------------- pylintrc | 2 +- setup.py | 7 +++---- tox.ini | 2 +- 12 files changed, 41 insertions(+), 40 deletions(-) diff --git a/.travis.yml b/.travis.yml index 210ca7f..d2b7cfe 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,11 +6,17 @@ python: - 3.6 - pypy - pypy3 +matrix: + include: + - python: 3.7 + dist: xenial + sudo: true install: - pip install pip --upgrade - - pip install -e .[dev,test] + - pip install -e .[dev,test] --upgrade - pip install pytest --upgrade - pip install coveralls + - pytest --version script: - pylint guessit - coverage run --source=guessit setup.py test diff --git a/guessit/jsonutils.py b/guessit/jsonutils.py index a8bb24e..35d2ced 100644 --- a/guessit/jsonutils.py +++ b/guessit/jsonutils.py @@ -29,7 +29,7 @@ class GuessitEncoder(json.JSONEncoder): ret['start'] = o.start ret['end'] = o.end return ret - elif hasattr(o, 'name'): # Babelfish languages/countries long name + if hasattr(o, 'name'): # Babelfish languages/countries long name return text_type(o.name) - else: # pragma: no cover - return text_type(o) + # pragma: no cover + return text_type(o) diff --git a/guessit/rules/common/date.py b/guessit/rules/common/date.py index cef31fd..e513af9 100644 --- a/guessit/rules/common/date.py +++ b/guessit/rules/common/date.py @@ -57,13 +57,13 @@ def _guess_day_first_parameter(groups): # pylint:disable=inconsistent-return-st if _is_int(groups[0]) and valid_year(int(groups[0][:4])): return False # If match ends with a long year, the day_first is forced to true. - elif _is_int(groups[-1]) and valid_year(int(groups[-1][-4:])): + if _is_int(groups[-1]) and valid_year(int(groups[-1][-4:])): return True # If match starts with a short year, then day_first is force to false. - elif _is_int(groups[0]) and int(groups[0][:2]) > 31: + if _is_int(groups[0]) and int(groups[0][:2]) > 31: return False # If match ends with a short year, then day_first is force to true. - elif _is_int(groups[-1]) and int(groups[-1][-2:]) > 31: + if _is_int(groups[-1]) and int(groups[-1][-2:]) > 31: return True diff --git a/guessit/rules/properties/country.py b/guessit/rules/properties/country.py index 138c80a..172c299 100644 --- a/guessit/rules/properties/country.py +++ b/guessit/rules/properties/country.py @@ -91,7 +91,7 @@ class CountryFinder(object): """Helper class to search and return country matches.""" def __init__(self, allowed_countries, common_words): - self.allowed_countries = set([l.lower() for l in allowed_countries or []]) + self.allowed_countries = {l.lower() for l in allowed_countries or []} self.common_words = common_words def find(self, string): diff --git a/guessit/rules/properties/episodes.py b/guessit/rules/properties/episodes.py index 0f2e173..13a92e3 100644 --- a/guessit/rules/properties/episodes.py +++ b/guessit/rules/properties/episodes.py @@ -553,8 +553,8 @@ class RenameToAbsoluteEpisode(Rule): consequence = RenameMatch('absolute_episode') def when(self, matches, context): # pylint:disable=inconsistent-return-statements - initiators = set([match.initiator for match in matches.named('episode') - if len(match.initiator.children.named('episode')) > 1]) + initiators = {match.initiator for match in matches.named('episode') + if len(match.initiator.children.named('episode')) > 1} if len(initiators) != 2: ret = [] for filepart in matches.markers.named('path'): @@ -791,8 +791,8 @@ class RemoveDetachedEpisodeNumber(Rule): episode_numbers = list(sorted(episode_numbers, key=lambda m: m.value)) if len(episode_numbers) > 1 and \ - episode_numbers[0].value < 10 and \ - episode_numbers[1].value - episode_numbers[0].value != 1: + episode_numbers[0].value < 10 and \ + episode_numbers[1].value - episode_numbers[0].value != 1: parent = episode_numbers[0] while parent: # TODO: Add a feature in rebulk to avoid this ... ret.append(parent) diff --git a/guessit/rules/properties/language.py b/guessit/rules/properties/language.py index 0cc4b94..bcdbda8 100644 --- a/guessit/rules/properties/language.py +++ b/guessit/rules/properties/language.py @@ -197,7 +197,7 @@ class LanguageFinder(object): subtitle_prefixes, subtitle_suffixes, lang_prefixes, lang_suffixes, weak_affixes): allowed_languages = context.get('allowed_languages') if context else None - self.allowed_languages = set([l.lower() for l in allowed_languages or []]) + self.allowed_languages = {l.lower() for l in allowed_languages or []} self.weak_affixes = weak_affixes self.prefixes_map = {} self.suffixes_map = {} diff --git a/guessit/rules/properties/other.py b/guessit/rules/properties/other.py index b3d49ca..bece70c 100644 --- a/guessit/rules/properties/other.py +++ b/guessit/rules/properties/other.py @@ -16,7 +16,7 @@ from ...reutils import build_or_pattern from ...rules.common.formatters import raw_cleanup -def other(config): # pylint:disable=unused-argument +def other(config): # pylint:disable=unused-argument,too-many-statements """ Builder for rebulk object. diff --git a/guessit/rules/properties/title.py b/guessit/rules/properties/title.py index 798df1e..d1cafe2 100644 --- a/guessit/rules/properties/title.py +++ b/guessit/rules/properties/title.py @@ -317,13 +317,13 @@ class PreferTitleWithYear(Rule): to_tag = [] if with_year_in_group: - title_values = set([title_match.value for title_match in with_year_in_group]) + title_values = {title_match.value for title_match in with_year_in_group} to_tag.extend(with_year_in_group) elif with_year: - title_values = set([title_match.value for title_match in with_year]) + title_values = {title_match.value for title_match in with_year} to_tag.extend(with_year) else: - title_values = set([title_match.value for title_match in titles]) + title_values = {title_match.value for title_match in titles} to_remove = [] for title_match in titles: diff --git a/guessit/test/test_yml.py b/guessit/test/test_yml.py index c866093..bb1fc59 100644 --- a/guessit/test/test_yml.py +++ b/guessit/test/test_yml.py @@ -2,24 +2,20 @@ # -*- coding: utf-8 -*- # pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name import logging - +import os # io.open supports encoding= in python 2.7 from io import open # pylint: disable=redefined-builtin -import os -import yaml - -import six import babelfish import pytest - +import six +import yaml from rebulk.remodule import re from rebulk.utils import is_iterable +from .. import guessit from ..options import parse_options, load_config from ..yamlutils import OrderedDictYAMLLoader -from .. import guessit - logger = logging.getLogger(__name__) @@ -64,10 +60,10 @@ class EntryResult(object): def __repr__(self): if self.ok: return self.string + ': OK!' - elif self.warning: + if self.warning: return '%s%s: WARNING! (valid=%i, extra=%i)' % ('-' if self.negates else '', self.string, len(self.valid), len(self.extra)) - elif self.error: + if self.error: return '%s%s: ERROR! (valid=%i, missing=%i, different=%i, extra=%i, others=%i)' % \ ('-' if self.negates else '', self.string, len(self.valid), len(self.missing), len(self.different), len(self.extra), len(self.others)) @@ -190,13 +186,13 @@ class TestYml(object): if not string_predicate or string_predicate(string): # pylint: disable=not-callable entry = self.check(string, expected) if entry.ok: - logger.debug('[' + filename + '] ' + str(entry)) + logger.debug('[%s] %s', filename, entry) elif entry.warning: - logger.warning('[' + filename + '] ' + str(entry)) + logger.warning('[%s] %s', filename, entry) elif entry.error: - logger.error('[' + filename + '] ' + str(entry)) + logger.error('[%s] %s', filename, entry) for line in entry.details: - logger.error('[' + filename + '] ' + ' ' * 4 + line) + logger.error('[%s] %s', filename, ' ' * 4 + line) return entry def check(self, string, expected): @@ -212,7 +208,7 @@ class TestYml(object): try: result = guessit(string, options) except Exception as exc: - logger.error('[' + string + '] Exception: ' + str(exc)) + logger.error('[%s] Exception: %s', string, exc) raise exc entry = EntryResult(string, negates) @@ -258,10 +254,10 @@ class TestYml(object): return False if isinstance(next(iter(values)), babelfish.Language): # pylint: disable=no-member - expecteds = set([babelfish.Language.fromguessit(expected) for expected in expecteds]) + expecteds = {babelfish.Language.fromguessit(expected) for expected in expecteds} elif isinstance(next(iter(values)), babelfish.Country): # pylint: disable=no-member - expecteds = set([babelfish.Country.fromguessit(expected) for expected in expecteds]) + expecteds = {babelfish.Country.fromguessit(expected) for expected in expecteds} return values == expecteds def check_expected(self, result, expected, entry): diff --git a/pylintrc b/pylintrc index 10d3e7c..f47beb2 100644 --- a/pylintrc +++ b/pylintrc @@ -68,7 +68,7 @@ disable=unichr-builtin,backtick,delslice-method,indexing-exception,execfile-buil unpacking-in-except,import-star-module-level,buffer-builtin,round-builtin,file-builtin,reload-builtin,old-division, apply-builtin,oct-method,nonzero-method,basestring-builtin,raising-string,too-few-public-methods,too-many-arguments, too-many-instance-attributes,bad-builtin,too-many-ancestors,too-few-format-args,fixme,duplicate-code, - deprecated-lambda,too-many-nested-blocks, + deprecated-lambda,too-many-nested-blocks,useless-object-inheritance, I diff --git a/setup.py b/setup.py index 604b97c..3036cea 100644 --- a/setup.py +++ b/setup.py @@ -16,14 +16,13 @@ with io.open(os.path.join(here, 'README.rst'), encoding='utf-8') as f: with io.open(os.path.join(here, 'HISTORY.rst'), encoding='utf-8') as f: history = f.read() -install_requires = ['rebulk>=0.9.0', 'babelfish>=0.5.5', 'python-dateutil'] -if sys.version_info < (2, 7): - install_requires.extend(['argparse', 'ordereddict']) +install_requires = ['rebulk', 'babelfish', 'python-dateutil'] + setup_requires = ['pytest-runner'] dev_require = ['zest.releaser[recommended]', 'pylint', 'tox', 'sphinx', 'sphinx-autobuild'] -tests_require = ['pytest>=2.7.3', 'pytest-benchmark', 'PyYAML'] +tests_require = ['pytest>=3.3', 'pytest-benchmark', 'PyYAML'] package_data = ['config/*'] diff --git a/tox.ini b/tox.ini index c0572cd..0bbaa57 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py27,py34,py35,py36,pypy2,pypy +envlist = py27,py34,py35,py36,py37,pypy2,pypy [testenv] commands =