Skip to content

Commit

Permalink
Add python 3.7 support and fix pylint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Oct 14, 2018
1 parent a54e8ac commit 0c2a065
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 40 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -6,10 +6,14 @@ 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 pytest --upgrade
- pip install coveralls
script:
- pylint guessit
Expand Down
6 changes: 3 additions & 3 deletions guessit/jsonutils.py
Expand Up @@ -29,7 +29,7 @@ def default(self, o): # pylint:disable=method-hidden
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)
6 changes: 3 additions & 3 deletions guessit/rules/common/date.py
Expand Up @@ -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


Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/properties/country.py
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions guessit/rules/properties/episodes.py
Expand Up @@ -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'):
Expand Down Expand Up @@ -791,8 +791,8 @@ def when(self, matches, context):

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)
Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/properties/language.py
Expand Up @@ -197,7 +197,7 @@ def __init__(self, context,
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 = {}
Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/properties/other.py
Expand Up @@ -16,7 +16,7 @@
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.
Expand Down
6 changes: 3 additions & 3 deletions guessit/rules/properties/title.py
Expand Up @@ -317,13 +317,13 @@ def when(self, matches, context):

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:
Expand Down
30 changes: 13 additions & 17 deletions guessit/test/test_yml.py
Expand Up @@ -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__)

Expand Down Expand Up @@ -64,10 +60,10 @@ def error(self):
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))
Expand Down Expand Up @@ -190,13 +186,13 @@ def check_data(self, filename, string, expected):
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):
Expand All @@ -212,7 +208,7 @@ def check(self, string, expected):
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)
Expand Down Expand Up @@ -258,10 +254,10 @@ def is_same(self, value, expected):
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):
Expand Down
2 changes: 1 addition & 1 deletion pylintrc
Expand Up @@ -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


Expand Down
7 changes: 3 additions & 4 deletions setup.py
Expand Up @@ -16,14 +16,13 @@
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', 'pytest-capturelog', 'pytest-benchmark', 'PyYAML']

package_data = ['config/*']

Expand Down
2 changes: 1 addition & 1 deletion tox.ini
@@ -1,5 +1,5 @@
[tox]
envlist = py27,py34,py35,py36,pypy2,pypy
envlist = py27,py34,py35,py36,py37,pypy2,pypy

[testenv]
commands =
Expand Down

0 comments on commit 0c2a065

Please sign in to comment.