Skip to content

Commit

Permalink
feat(python): add python 3.10 support, drop python 3.5 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Nov 4, 2021
1 parent 1a7db40 commit a8ea88d
Show file tree
Hide file tree
Showing 21 changed files with 76 additions and 82 deletions.
41 changes: 18 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,22 @@ jobs:

strategy:
matrix:
python-version: [ 3.5, 3.6, 3.7, 3.8, 3.9 ] # pypy-3.6, pypy-3.7 are supported but a bit slow.
python-version: [ "3.6", "3.7", "3.8", "3.9", "3.10" ] # pypy-3.6, pypy-3.7 are supported but a bit slow.
regex: [ "0", "1" ]
exclude:
# regex module doesn't play well with pypy and unicode.
- python-version: pypy-3.6
- python-version: "pypy-3.6"
regex: "1"
- python-version: pypy-3.7
- python-version: "pypy-3.7"
regex: "1"
# test regex module only with Python 3.8.
- python-version: 3.5
# test regex module only with Python 3.9.
- python-version: "3.6"
regex: "1"
- python-version: 3.6
- python-version: "3.7"
regex: "1"
- python-version: 3.7
- python-version: "3.8"
regex: "1"
- python-version: 3.9
- python-version: "3.10"
regex: "1"

steps:
Expand All @@ -35,11 +35,6 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Upgrade setuptools
run: |
pip install --upgrade setuptools
if: matrix.python-version == '3.5'

- name: Checkout
uses: actions/checkout@v2

Expand Down Expand Up @@ -82,10 +77,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup python 3.8
- name: Setup python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -119,10 +114,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup python 3.8
- name: Setup python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -160,10 +155,10 @@ jobs:
runs-on: windows-latest

steps:
- name: Setup python 3.8
- name: Setup python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -200,10 +195,10 @@ jobs:
runs-on: macos-latest

steps:
- name: Setup python 3.8
- name: Setup python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Checkout
uses: actions/checkout@v2
Expand Down Expand Up @@ -240,10 +235,10 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Setup python 3.8
- name: Setup python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.8
python-version: 3.9

- name: Checkout
uses: actions/checkout@v2
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ jobs:
- run: mkdocs build

- name: Deploy 🚀
uses: JamesIves/github-pages-deploy-action@3.7.1
uses: JamesIves/github-pages-deploy-action@4.1.5
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: site
CLEAN: true
SINGLE_COMMIT: true
token: ${{ secrets.GITHUB_TOKEN }}
branch: gh-pages
folder: site
clean: true
single-commit: true
4 changes: 2 additions & 2 deletions guessit/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ def display_properties(options):
properties_list = list(sorted(properties.keys()))
for property_name in properties_list:
property_values = properties.get(property_name)
print(2 * ' ' + '[+] %s' % (property_name,))
print(2 * ' ' + f'[+] {property_name}')
if property_values and options.get('values'):
for property_value in property_values:
print(4 * ' ' + '[!] %s' % (property_value,))
print(4 * ' ' + f'[!] {property_value}')


def main(args=None): # pylint:disable=too-many-branches
Expand Down
11 changes: 5 additions & 6 deletions guessit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@ class GuessitException(Exception):
def __init__(self, string, options):
super().__init__("An internal error has occured in guessit.\n"
"===================== Guessit Exception Report =====================\n"
"version=%s\n"
"string=%s\n"
"options=%s\n"
f"version={__version__}\n"
f"string={str(string)}\n"
f"options={str(options)}\n"
"--------------------------------------------------------------------\n"
"%s"
f"{traceback.format_exc()}"
"--------------------------------------------------------------------\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
11 changes: 5 additions & 6 deletions guessit/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
import json
import os
import shlex

from argparse import ArgumentParser

from importlib_resources import read_text


Expand Down Expand Up @@ -246,25 +246,24 @@ def load_config_file(filepath):
:rtype:
"""
if filepath.endswith('.json'):
with open(filepath) as config_file_data:
with open(filepath, encoding='utf-8') as config_file_data:
return json.load(config_file_data)
if filepath.endswith('.yaml') or filepath.endswith('.yml'):
try:
import yaml # pylint:disable=import-outside-toplevel
with open(filepath) as config_file_data:
with open(filepath, encoding='utf-8') as config_file_data:
return yaml.load(config_file_data, yaml.SafeLoader)
except ImportError as err: # pragma: no cover
raise ConfigurationException('Configuration file extension is not supported. '
'PyYAML should be installed to support "%s" file' % (
filepath,)) from err
f'PyYAML should be installed to support "{filepath}" file') from err

try:
# Try to load input as JSON
return json.loads(filepath)
except: # pylint: disable=bare-except
pass

raise ConfigurationException('Configuration file extension is not supported for "%s" file.' % (filepath,))
raise ConfigurationException(f'Configuration file extension is not supported for "{filepath}" file.')


def get_options_file_locations(homedir, cwd, yaml_supported=False):
Expand Down
4 changes: 2 additions & 2 deletions guessit/reutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ def build_or_pattern(patterns, name=None, escape=False):
if not or_pattern:
or_pattern.append('(?')
if name:
or_pattern.append('P<' + name + '>')
or_pattern.append(f'P<{name}>')
else:
or_pattern.append(':')
else:
or_pattern.append('|')
or_pattern.append('(?:%s)' % re.escape(pattern) if escape else pattern)
or_pattern.append(f'(?:{re.escape(pattern)})' if escape else pattern)
or_pattern.append(')')
return ''.join(or_pattern)
8 changes: 8 additions & 0 deletions guessit/rules/common/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@
_dsep_bis = r'[-/ \.x]'

date_regexps = [
# pylint:disable=consider-using-f-string
re.compile(r'%s((\d{8}))%s' % (_dsep, _dsep), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'%s((\d{6}))%s' % (_dsep, _dsep), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'(?:^|[^\d])((\d{2})%s(\d{1,2})%s(\d{1,2}))(?:$|[^\d])' % (_dsep, _dsep), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'(?:^|[^\d])((\d{1,2})%s(\d{1,2})%s(\d{2}))(?:$|[^\d])' % (_dsep, _dsep), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'(?:^|[^\d])((\d{4})%s(\d{1,2})%s(\d{1,2}))(?:$|[^\d])' % (_dsep_bis, _dsep), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'(?:^|[^\d])((\d{1,2})%s(\d{1,2})%s(\d{4}))(?:$|[^\d])' % (_dsep, _dsep_bis), re.IGNORECASE),
# pylint:disable=consider-using-f-string
re.compile(r'(?:^|[^\d])((\d{1,2}(?:st|nd|rd|th)?%s(?:[a-z]{3,10})%s\d{4}))(?:$|[^\d])' % (_dsep, _dsep),
# pylint:disable=consider-using-f-string
re.IGNORECASE)]


Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/common/numeral.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def __parse_roman(value):
:rtype:
"""
if not __romanNumeralPattern.search(value):
raise ValueError('Invalid Roman numeral: %s' % value)
raise ValueError(f'Invalid Roman numeral: {value}')

result = 0
index = 0
Expand Down
4 changes: 2 additions & 2 deletions guessit/rules/common/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ def __ne__(self, other):
return not self == other

def __repr__(self):
return '<{0} [{1}]>'.format(self.__class__.__name__, self)
return f'<{self.__class__.__name__} [{self}]>'

def __str__(self):
return '{0}{1}'.format(self.magnitude, self.units)
return f'{self.magnitude}{self.units}'


class Size(Quantity):
Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/properties/country.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def convert(self, alpha2):
return 'UK'
return str(babelfish.Country(alpha2))

def reverse(self, name): # pylint:disable=arguments-differ
def reverse(self, name): # pylint:disable=arguments-renamed
# exceptions come first, as they need to override a potential match
# with any of the other guessers
try:
Expand Down
4 changes: 2 additions & 2 deletions guessit/rules/properties/language.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def codes(self): # pylint: disable=missing-docstring
def convert(self, alpha3, country=None, script=None):
return str(babelfish.Language(alpha3, country, script))

def reverse(self, name): # pylint:disable=arguments-differ
def reverse(self, name): # pylint:disable=arguments-renamed
name = name.lower()
# exceptions come first, as they need to override a potential match
# with any of the other guessers
Expand Down Expand Up @@ -166,7 +166,7 @@ def extended_word(self): # pylint:disable=inconsistent-return-statements
return LanguageWord(self.start, self.next_word.end, value, self.input_string, self.next_word.next_word)

def __repr__(self):
return '<({start},{end}): {value}'.format(start=self.start, end=self.end, value=self.value)
return f'<({self.start},{self.end}): {self.value}'


def to_rebulk_match(language_match):
Expand Down
6 changes: 3 additions & 3 deletions guessit/rules/properties/screen_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def when(self, matches, context):
scan_type = (values.get('scan_type') or 'p').lower()
height = values['height']
if 'width' not in values:
match.value = '{0}{1}'.format(height, scan_type)
match.value = f'{height}{scan_type}'
continue

width = values['width']
Expand All @@ -102,9 +102,9 @@ def when(self, matches, context):
to_append.append(aspect_ratio)

if height in self.standard_heights and self.min_ar < calculated_ar < self.max_ar:
match.value = '{0}{1}'.format(height, scan_type)
match.value = f'{height}{scan_type}'
else:
match.value = '{0}x{1}'.format(width, height)
match.value = f'{width}x{height}'

return to_append

Expand Down
4 changes: 2 additions & 2 deletions guessit/rules/properties/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ def source(config): # pylint:disable=unused-argument

def build_source_pattern(*patterns, prefix='', suffix=''):
"""Helper pattern to build source pattern."""
return [prefix + '({0})'.format(pattern) + suffix for pattern in patterns]
return [prefix + f'({pattern})' + suffix for pattern in patterns]

def demote_other(match, other): # pylint: disable=unused-argument
"""Default conflict solver with 'other' property."""
return other if other.name == 'other' or other.name == 'release_group' else '__default__'
return other if other.name in ['other', 'release_group'] else '__default__'

rebulk.regex(*build_source_pattern('VHS', suffix=optional(rip_suffix)),
value={'source': 'VHS', 'other': 'Rip'})
Expand Down
2 changes: 1 addition & 1 deletion guessit/rules/properties/title.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def check_titles_in_filepart(self, filepart, matches, context): # pylint:disabl
for ignored_match in ignored_matches:
if ignored_match not in to_keep:
starting = matches.chain_after(hole.start, seps,
predicate=lambda m: m == ignored_match)
predicate=lambda m, im=ignored_match: m == im)
if starting:
should_keep = self.should_keep(ignored_match, to_keep, matches, filepart, hole, True)
if should_keep:
Expand Down
2 changes: 1 addition & 1 deletion guessit/test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_exception():


def test_suggested_expected():
with open(os.path.join(__location__, 'suggested.json'), 'r') as f:
with open(os.path.join(__location__, 'suggested.json'), 'r', encoding='utf-8') as f:
content = json.load(f)
actual = suggested_expected(content['titles'])
assert actual == content['suggested']
Expand Down
2 changes: 1 addition & 1 deletion guessit/test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Prevent output from spamming the console
@pytest.fixture(scope="function", autouse=True)
def no_stdout(monkeypatch):
with open(os.devnull, "w") as f:
with open(os.devnull, "w") as f: # pylint:disable=unspecified-encoding
monkeypatch.setattr(sys, "stdout", f)
yield

Expand Down
18 changes: 8 additions & 10 deletions guessit/test/test_yml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
# 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 babelfish
import yaml # pylint:disable=wrong-import-order
Expand Down Expand Up @@ -52,16 +50,16 @@ def __repr__(self):
if self.ok:
return self.string + ': OK!'
if self.warning:
return '%s%s: WARNING! (valid=%i, extra=%s)' % ('-' if self.negates else '', self.string, len(self.valid),
self.extra)
return f'{"-" if self.negates else ""}{self.string}: ' \
f'WARNING! (valid={len(self.valid)}, extra={self.extra})'
if self.error:
return '%s%s: ERROR! (valid=%i, extra=%s, missing=%s, different=%s, others=%s)' % \
('-' if self.negates else '', self.string, len(self.valid), self.extra, self.missing,
self.different, self.others)
return f'{"-" if self.negates else ""}{self.string}: ' \
f'ERROR! (valid={len(self.valid)}, extra={self.extra}, ' \
f'missing={self.missing}, different={self.different}, others={self.others})'

return '%s%s: UNKOWN! (valid=%i, extra=%s, missing=%s, different=%s, others=%s)' % \
('-' if self.negates else '', self.string, len(self.valid), self.extra, self.missing, self.different,
self.others)
return f'{"-" if self.negates else ""}{self.string}: ' \
f'UNKOWN! (valid={len(self.valid)}, extra={self.extra}, ' \
f'missing={self.missing}, different={self.different}, others={self.others})'

@property
def details(self):
Expand Down
Loading

0 comments on commit a8ea88d

Please sign in to comment.