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

Update Python dependency guessit to v3.2.0 #8913

Merged
merged 3 commits into from
Dec 26, 2020
Merged
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
35 changes: 6 additions & 29 deletions ext/guessit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
Entry point module
"""
# pragma: no cover
from __future__ import print_function

import json
import logging
import os
import sys

import six
from collections import OrderedDict

from rebulk.__version__ import __version__ as __rebulk_version__

from guessit import api
Expand All @@ -20,12 +18,6 @@
from guessit.options import argument_parser, parse_options, load_config, merge_options


try:
from collections import OrderedDict
except ImportError: # pragma: no-cover
from ordereddict import OrderedDict # pylint:disable=import-error


def guess_filename(filename, options):
"""
Guess a single filename using given options
Expand All @@ -48,6 +40,7 @@ def guess_filename(filename, options):
if options.get('json'):
print(json.dumps(guess, cls=GuessitEncoder, ensure_ascii=False))
elif options.get('yaml'):
# pylint:disable=import-outside-toplevel
import yaml
from guessit import yamlutils

Expand Down Expand Up @@ -78,6 +71,7 @@ def display_properties(options):
else:
print(json.dumps(list(properties.keys()), cls=GuessitEncoder, ensure_ascii=False))
elif options.get('yaml'):
# pylint:disable=import-outside-toplevel
import yaml
from guessit import yamlutils
if options.get('values'):
Expand All @@ -97,24 +91,10 @@ def display_properties(options):
print(4 * ' ' + '[!] %s' % (property_value,))


def fix_argv_encoding():
"""
Fix encoding of sys.argv on windows Python 2
"""
if six.PY2 and os.name == 'nt': # pragma: no cover
# see http://bugs.python.org/issue2128
import locale

for i, j in enumerate(sys.argv):
sys.argv[i] = j.decode(locale.getpreferredencoding())


def main(args=None): # pylint:disable=too-many-branches
"""
Main function for entry point
"""
fix_argv_encoding()

if args is None: # pragma: no cover
options = parse_options()
else:
Expand Down Expand Up @@ -142,7 +122,7 @@ def main(args=None): # pylint:disable=too-many-branches

if options.get('yaml'):
try:
import yaml # pylint:disable=unused-variable,unused-import
import yaml # pylint:disable=unused-variable,unused-import,import-outside-toplevel
except ImportError: # pragma: no cover
del options['yaml']
print('PyYAML is not installed. \'--yaml\' option will be ignored ...', file=sys.stderr)
Expand All @@ -156,10 +136,7 @@ def main(args=None): # pylint:disable=too-many-branches
for filename in options.get('filename'):
filenames.append(filename)
if options.get('input_file'):
if six.PY2:
input_file = open(options.get('input_file'), 'r')
else:
input_file = open(options.get('input_file'), 'r', encoding='utf-8')
input_file = open(options.get('input_file'), 'r', encoding='utf-8')
try:
filenames.extend([line.strip() for line in input_file.readlines()])
finally:
Expand Down
2 changes: 1 addition & 1 deletion ext/guessit/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
Version module
"""
# pragma: no cover
__version__ = '3.1.1'
__version__ = '3.2.0'
78 changes: 30 additions & 48 deletions ext/guessit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
API functions that can be used by external software
"""

try:
from collections import OrderedDict
except ImportError: # pragma: no-cover
from ordereddict import OrderedDict # pylint:disable=import-error
from collections import OrderedDict

from pathlib import Path
import os
import traceback

import six
from rebulk.introspector import introspect

from .__version__ import __version__
Expand All @@ -26,18 +23,18 @@ class GuessitException(Exception):
"""

def __init__(self, string, options):
super(GuessitException, self).__init__("An internal error has occured in guessit.\n"
"===================== Guessit Exception Report =====================\n"
"version=%s\n"
"string=%s\n"
"options=%s\n"
"--------------------------------------------------------------------\n"
"%s"
"--------------------------------------------------------------------\n"
"Please report at "
"https://github.com/guessit-io/guessit/issues.\n"
"====================================================================" %
(__version__, str(string), str(options), traceback.format_exc()))
super().__init__("An internal error has occured in guessit.\n"
"===================== Guessit Exception Report =====================\n"
"version=%s\n"
"string=%s\n"
"options=%s\n"
"--------------------------------------------------------------------\n"
"%s"
"--------------------------------------------------------------------\n"
"Please report at "
"https://github.com/guessit-io/guessit/issues.\n"
"====================================================================" %
(__version__, str(string), str(options), traceback.format_exc()))

self.string = string
self.options = options
Expand Down Expand Up @@ -113,9 +110,7 @@ def _fix_encoding(cls, value):
return [cls._fix_encoding(item) for item in value]
if isinstance(value, dict):
return {cls._fix_encoding(k): cls._fix_encoding(v) for k, v in value.items()}
if six.PY2 and isinstance(value, six.text_type):
return value.encode('utf-8')
if six.PY3 and isinstance(value, six.binary_type):
if isinstance(value, bytes):
return value.decode('ascii')
return value

Expand Down Expand Up @@ -175,16 +170,12 @@ def guessit(self, string, options=None): # pylint: disable=too-many-branches
:return:
:rtype:
"""
try:
from pathlib import Path
if isinstance(string, Path):
try:
# Handle path-like object
string = os.fspath(string)
except AttributeError:
string = str(string)
except ImportError:
pass
if isinstance(string, Path):
try:
# Handle path-like object
string = os.fspath(string)
except AttributeError:
string = str(string)

try:
options = parse_options(options, True)
Expand All @@ -194,32 +185,23 @@ def guessit(self, string, options=None): # pylint: disable=too-many-branches
result_decode = False
result_encode = False

if six.PY2:
if isinstance(string, six.text_type):
string = string.encode("utf-8")
result_decode = True
elif isinstance(string, six.binary_type):
string = six.binary_type(string)
if six.PY3:
if isinstance(string, six.binary_type):
string = string.decode('ascii')
result_encode = True
elif isinstance(string, six.text_type):
string = six.text_type(string)
if isinstance(string, bytes):
string = string.decode('ascii')
result_encode = True

matches = self.rebulk.matches(string, options)
if result_decode:
for match in matches:
if isinstance(match.value, six.binary_type):
if isinstance(match.value, bytes):
match.value = match.value.decode("utf-8")
if result_encode:
for match in matches:
if isinstance(match.value, six.text_type):
if isinstance(match.value, str):
match.value = match.value.encode("ascii")
return matches.to_dict(options.get('advanced', False), options.get('single_value', False),
options.get('enforce_list', False))
except:
raise GuessitException(string, options)
except Exception as err:
raise GuessitException(string, options) from err

def properties(self, options=None):
"""
Expand All @@ -235,8 +217,8 @@ def properties(self, options=None):
options = merge_options(config, options)
unordered = introspect(self.rebulk, options).properties
ordered = OrderedDict()
for k in sorted(unordered.keys(), key=six.text_type):
ordered[k] = list(sorted(unordered[k], key=six.text_type))
for k in sorted(unordered.keys(), key=str):
ordered[k] = list(sorted(unordered[k], key=str))
if hasattr(self.rebulk, 'customize_properties'):
ordered = self.rebulk.customize_properties(ordered)
return ordered
Expand Down
27 changes: 0 additions & 27 deletions ext/guessit/backports.py

This file was deleted.

5 changes: 1 addition & 4 deletions ext/guessit/monkeypatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@
Monkeypatch initialisation functions
"""

try:
from collections import OrderedDict
except ImportError: # pragma: no-cover
from ordereddict import OrderedDict # pylint:disable=import-error
from collections import OrderedDict

from rebulk.match import Match

Expand Down
12 changes: 5 additions & 7 deletions ext/guessit/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@

from argparse import ArgumentParser

import six


def build_argument_parser():
"""
Expand Down Expand Up @@ -108,7 +106,7 @@ def parse_options(options=None, api=False):
:return:
:rtype:
"""
if isinstance(options, six.string_types):
if isinstance(options, str):
args = shlex.split(options)
options = vars(argument_parser.parse_args(args))
elif options is None:
Expand Down Expand Up @@ -153,7 +151,7 @@ def load_config(options):
cwd = os.getcwd()
yaml_supported = False
try:
import yaml # pylint:disable=unused-variable,unused-import
import yaml # pylint:disable=unused-variable,unused-import,import-outside-toplevel
yaml_supported = True
except ImportError:
pass
Expand Down Expand Up @@ -250,13 +248,13 @@ def load_config_file(filepath):
return json.load(config_file_data)
if filepath.endswith('.yaml') or filepath.endswith('.yml'):
try:
import yaml
import yaml # pylint:disable=import-outside-toplevel
with open(filepath) as config_file_data:
return yaml.load(config_file_data, yaml.SafeLoader)
except ImportError: # pragma: no cover
except ImportError as err: # pragma: no cover
raise ConfigurationException('Configuration file extension is not supported. '
'PyYAML should be installed to support "%s" file' % (
filepath,))
filepath,)) from err

try:
# Try to load input as JSON
Expand Down
2 changes: 1 addition & 1 deletion ext/guessit/rules/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Common module
"""
import re
from rebulk.remodule import re

seps = r' [](){}+*|=-_~#/\\.,;:' # list of tags/words separators
seps_no_groups = seps.replace('[](){}', '')
Expand Down
14 changes: 6 additions & 8 deletions ext/guessit/rules/common/comparators.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,19 @@
"""
Comparators
"""
try:
from functools import cmp_to_key
except ImportError:
from ...backports import cmp_to_key

from functools import cmp_to_key


def marker_comparator_predicate(match):
"""
Match predicate used in comparator
"""
return (
not match.private
and match.name not in ('proper_count', 'title')
and not (match.name == 'container' and 'extension' in match.tags)
and not (match.name == 'other' and match.value == 'Rip')
not match.private
and match.name not in ('proper_count', 'title')
and not (match.name == 'container' and 'extension' in match.tags)
and not (match.name == 'other' and match.value == 'Rip')
)


Expand Down
2 changes: 1 addition & 1 deletion ext/guessit/rules/common/expected.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
Expected property factory
"""
import re
from rebulk.remodule import re

from rebulk import Rebulk
from rebulk.utils import find_all
Expand Down
5 changes: 2 additions & 3 deletions ext/guessit/rules/common/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"""
Quantities: Size
"""
import re
from abc import abstractmethod

import six
from rebulk.remodule import re

from ..common import seps

Expand Down Expand Up @@ -50,7 +49,7 @@ def __hash__(self):
return hash(str(self))

def __eq__(self, other):
if isinstance(other, six.string_types):
if isinstance(other, str):
return str(self) == other
if not isinstance(other, self.__class__):
return NotImplemented
Expand Down
Loading