Import ABC from collections.abc for Python 3.9+ compatibility (#330)

* Import ABC from collections.abc instead of collections for Python 3.9 compatibility.

* Fix deprecation warnings due to invalid escape sequences.

* Support Python 3.10

Co-authored-by: Karl Kroening <karlk@kralnet.us>
This commit is contained in:
Karthikeyan Singaravelan 2022-03-07 15:16:52 +05:30 committed by GitHub
parent cb9d400467
commit 6189cd6861
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 12 deletions

View File

@ -15,7 +15,7 @@ jobs:
- "3.7"
- "3.8"
- "3.9"
# - "3.10" # FIXME: broken due to `collections.Iterable` issue; see #330 / #624 / etc.
- "3.10"
steps:
- uses: actions/checkout@v1
- name: Set up Python ${{ matrix.python-version }}

View File

@ -27,10 +27,10 @@ parser.add_argument('--start-time', type=float, help='Start time (seconds)')
parser.add_argument('--end-time', type=float, help='End time (seconds)')
parser.add_argument('-v', dest='verbose', action='store_true', help='Verbose mode')
silence_start_re = re.compile(' silence_start: (?P<start>[0-9]+(\.?[0-9]*))$')
silence_end_re = re.compile(' silence_end: (?P<end>[0-9]+(\.?[0-9]*)) ')
silence_start_re = re.compile(r' silence_start: (?P<start>[0-9]+(\.?[0-9]*))$')
silence_end_re = re.compile(r' silence_end: (?P<end>[0-9]+(\.?[0-9]*)) ')
total_duration_re = re.compile(
'size=[^ ]+ time=(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9\.]{5}) bitrate=')
r'size=[^ ]+ time=(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9\.]{5}) bitrate=')
def _logged_popen(cmd_line, *args, **kwargs):

View File

@ -3,7 +3,6 @@ from .dag import get_outgoing_edges, topo_sort
from ._utils import basestring, convert_kwargs_to_cmd_line_args
from builtins import str
from functools import reduce
import collections
import copy
import operator
import subprocess
@ -18,6 +17,11 @@ from .nodes import (
output_operator,
)
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
class Error(Exception):
def __init__(self, cmd, stdout, stderr):
@ -136,9 +140,7 @@ def _get_output_args(node, stream_name_map):
args += ['-b:a', str(kwargs.pop('audio_bitrate'))]
if 'video_size' in kwargs:
video_size = kwargs.pop('video_size')
if not isinstance(video_size, basestring) and isinstance(
video_size, collections.Iterable
):
if not isinstance(video_size, basestring) and isinstance(video_size, Iterable):
video_size = '{}x{}'.format(video_size[0], video_size[1])
args += ['-video_size', video_size]
args += convert_kwargs_to_cmd_line_args(kwargs)

View File

@ -3,13 +3,17 @@ from builtins import str
from past.builtins import basestring
import hashlib
import sys
import collections
if sys.version_info.major == 2:
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
str = str
try:
from collections.abc import Iterable
except ImportError:
from collections import Iterable
# `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
# This code is copy-pasted from it to avoid crashes.
@ -92,7 +96,7 @@ def convert_kwargs_to_cmd_line_args(kwargs):
args = []
for k in sorted(kwargs.keys()):
v = kwargs[k]
if isinstance(v, collections.Iterable) and not isinstance(v, str):
if isinstance(v, Iterable) and not isinstance(v, str):
for value in v:
args.append('-{}'.format(k))
if value is not None:

View File

@ -30,7 +30,7 @@ subprocess.check_call(['ffmpeg', '-version'])
def test_escape_chars():
assert ffmpeg._utils.escape_chars('a:b', ':') == 'a\:b'
assert ffmpeg._utils.escape_chars('a:b', ':') == r'a\:b'
assert ffmpeg._utils.escape_chars('a\\:b', ':\\') == 'a\\\\\\:b'
assert (
ffmpeg._utils.escape_chars('a:b,c[d]e%{}f\'g\'h\\i', '\\\':,[]%')

View File

@ -92,5 +92,9 @@ setup(
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
)

View File

@ -4,7 +4,7 @@
# and then run "tox" from this directory.
[tox]
envlist = py27, py35, py36, py37, py38, py39
envlist = py27, py35, py36, py37, py38, py39, py310
[gh-actions]
python =
@ -14,6 +14,7 @@ python =
3.7: py37
3.8: py38
3.9: py39
3.10: py310
[testenv]
commands = py.test -vv