8000 Import ABC from collections.abc for Python 3.9+ compatibility (#330) · rodriveracom/ffmpeg-python@6189cd6 · GitHub 8000
[go: up one dir, main page]

Skip to content

Commit 6189cd6

Browse files
tirkarthikkroening
andauthored
Import ABC from collections.abc for Python 3.9+ compatibility (kkroening#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>
1 parent cb9d400 commit 6189cd6

File tree

7 files changed

+23
-12
lines changed
  • 7 files changed

    +23
    -12
    lines changed

    .github/workflows/ci.yml

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -15,7 +15,7 @@ jobs:
    1515
    - "3.7"
    1616
    - "3.8"
    1717
    - "3.9"
    18-
    # - "3.10" # FIXME: broken due to `collections.Iterable` issue; see #330 / #624 / etc.
    18+
    - "3.10"
    1919
    steps:
    2020
    - uses: actions/checkout@v1
    2121
    - name: Set up Python ${{ matrix.python-version }}

    examples/split_silence.py

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -27,10 +27,10 @@
    2727
    parser.add_argument('--end-time', type=float, help='End time (seconds)')
    2828
    parser.add_argument('-v', dest='verbose', action='store_true', help='Verbose mode')
    2929

    30-
    silence_start_re = re.compile(' silence_start: (?P<start>[0-9]+(\.?[0-9]*))$')
    31-
    silence_end_re = re.compile(' silence_end: (?P<end>[0-9]+(\.?[0-9]*)) ')
    30+
    silence_start_re = re.compile(r' silence_start: (?P<start>[0-9]+(\.?[0-9]*))$')
    31+
    silence_end_re = re.compile(r' silence_end: (?P<end>[0-9]+(\.?[0-9]*)) ')
    3232
    total_duration_re = re.compile(
    33-
    'size=[^ ]+ time=(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9\.]{5}) bitrate=')
    33+
    r'size=[^ ]+ time=(?P<hours>[0-9]{2}):(?P<minutes>[0-9]{2}):(?P<seconds>[0-9\.]{5}) bitrate=')
    3434

    3535

    3636
    def _logged_popen(cmd_line, *args, **kwargs):

    ffmpeg/_run.py

    Lines changed: 6 additions & 4 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3,7 +3,6 @@
    33
    from ._utils import basestring, convert_kwargs_to_cmd_line_args
    44
    from builtins import str
    55
    from functools import reduce
    6-
    import collections
    76
    import copy
    87
    import operator
    98
    import subprocess
    @@ -18,6 +17,11 @@
    1817
    output_operator,
    1918
    )
    2019

    20+
    try:
    21+
    from collections.abc import Iterable
    22+
    except ImportError:
    23+
    from collections import Iterable
    24+
    2125

    2226
    class Error(Exception):
    2327
    def __init__(self, cmd, stdout, stderr):
    @@ -136,9 +140,7 @@ def _get_output_args(node, stream_name_map):
    136140
    args += ['-b:a', str(kwargs.pop('audio_bitrate'))]
    137141
    if 'video_size' in kwargs:
    138142
    video_size = kwargs.pop('video_size')
    139-
    if not isinstance(video_size, basestring) and isinstance(
    140-
    video_size, collections.Iterable
    141-
    ):
    143+
    if not isinstance(video_size, basestring) and isinstance(video_size, Iterable):
    142144
    video_size = '{}x{}'.format(video_size[0], video_size[1])
    143145
    args += ['-video_size', video_size]
    144146
    args += convert_kwargs_to_cmd_line_args(kwargs)

    ffmpeg/_utils.py

    Lines changed: 6 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -3,13 +3,17 @@
    33
    from past.builtins import basestring
    44
    import hashlib
    55
    import sys
    6-
    import collections
    76

    87

    98
    if sys.version_info.major == 2:
    109
    # noinspection PyUnresolvedReferences,PyShadowingBuiltins
    1110
    str = str
    1211

    12+
    try:
    13+
    from collections.abc import Iterable
    14+
    except ImportError:
    15+
    from collections import Iterable
    16+
    1317

    1418
    # `past.builtins.basestring` module can't be imported on Python3 in some environments (Ubuntu).
    1519
    # This code is copy-pasted from it to avoid crashes.
    @@ -92,7 +96,7 @@ def convert_kwargs_to_cmd_line_args(kwargs):
    9296
    args = []
    9397
    for k in sorted(kwargs.keys()):
    9498
    v = kwargs[k]
    95-
    if isinstance(v, collections.Iterable) and not isinstance(v, str):
    99+
    if isinstance(v, Iterable) and not isinstance(v, str):
    96100
    for value in v:
    97101
    args.append('-{}'.format(k))
    98102
    if value is not None:

    ffmpeg/tests/test_ffmpeg.py

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -30,7 +30,7 @@
    3030

    3131

    3232
    def test_escape_chars():
    33-
    assert ffmpeg._utils.escape_chars('a:b', ':') == 'a\:b'
    33+
    assert ffmpeg._utils.escape_chars('a:b', ':') == r'a\:b'
    3434
    assert ffmpeg._utils.escape_chars('a\\:b', ':\\') == 'a\\\\\\:b'
    3535
    assert (
    3636
    ffmpeg._utils.escape_chars('a:b,c[d]e%{}f\'g\'h\\i', '\\\':,[]%')

    setup.py

    Lines changed: 4 additions & 0 deletions
    Original file line numberDiff line numberDiff line change
    @@ -92,5 +92,9 @@
    9292
    'Programming Language :: Python :: 3.4',
    9393
    'Programming Language :: Python :: 3.5',
    9494
    'Programming Language :: Python :: 3.6',
    95+
    'Programming Language :: Python :: 3.7',
    96+
    'Programming Language :: Python :: 3.8',
    97+
    'Programming Language :: Python :: 3.9',
    98+
    'Programming Language :: Python :: 3.10',
    9599
    ],
    96100
    )

    tox.ini

    Lines changed: 2 additions & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -4,7 +4,7 @@
    44
    # and then run "tox" from this directory.
    55

    66
    [tox]
    7-
    envlist = py27, py35, py36, py37, py38, py39
    7+
    envlist = py27, py35, py36, py37, py38, py39, py310
    88

    99
    [gh-actions]
    1010
    python =
    @@ -14,6 +14,7 @@ python =
    1414
    3.7: py37
    1515
    3.8: py38
    1616
    3.9: py39
    17+
    3.10: py310
    1718

    1819
    [testenv]
    1920
    commands = py.test -vv

    0 commit comments

    Comments
     (0)
    0