Skip to content

Commit b33dc1e

Browse files
authored
Merge pull request #114 from Bomme/py36
Remove support for Python 2 and require > 3.6
2 parents 75e6e35 + c186791 commit b33dc1e

File tree

14 files changed

+62
-99
lines changed

14 files changed

+62
-99
lines changed

.github/workflows/main.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Python Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
python: ["3.6", "3.7", "3.8", "3.9"]
12+
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Setup Python
16+
uses: actions/setup-python@v2
17+
with:
18+
python-version: ${{ matrix.python }}
19+
- name: Install ffmpeg
20+
run: sudo apt install -y ffmpeg
21+
- name: Install tox and any other packages
22+
run: pip install tox
23+
- name: Run tox
24+
# Run tox using the version of Python in `PATH`
25+
run: tox -e py

.travis.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,7 @@ A second optional parameter to ``audio_open`` specifies which backends to try
5858
``available_backends`` function to get a list backends that are usable on the
5959
current system.
6060

61-
Audioread is "universal" and supports both Python 2 (2.6+) and Python 3
62-
(3.2+).
61+
Audioread supports Python 3 (3.6+).
6362

6463
Example
6564
-------

audioread/ffdec.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,13 @@
1616
output.
1717
"""
1818

19-
import sys
20-
import subprocess
19+
import os
20+
import queue
2121
import re
22+
import subprocess
23+
import sys
2224
import threading
2325
import time
24-
import os
25-
try:
26-
import queue
27-
except ImportError:
28-
import Queue as queue
2926

3027
from .exceptions import DecodeError
3128

@@ -62,7 +59,7 @@ class QueueReaderThread(threading.Thread):
6259
over a Queue.
6360
"""
6461
def __init__(self, fh, blocksize=1024, discard=False):
65-
super(QueueReaderThread, self).__init__()
62+
super().__init__()
6663
self.fh = fh
6764
self.blocksize = blocksize
6865
self.daemon = True
@@ -121,7 +118,7 @@ def available():
121118
windows_error_mode_lock = threading.Lock()
122119

123120

124-
class FFmpegAudioFile(object):
121+
class FFmpegAudioFile:
125122
"""An audio file decoded by the ffmpeg command-line utility."""
126123
def __init__(self, filename, block_size=4096):
127124
# On Windows, we need to disable the subprocess's crash dialog
@@ -227,7 +224,7 @@ def _get_info(self):
227224
line = line.strip().lower()
228225

229226
if 'no such file' in line:
230-
raise IOError('file not found')
227+
raise OSError('file not found')
231228
elif 'invalid data found' in line:
232229
raise UnsupportedError()
233230
elif 'duration:' in line:

audioread/gstdec.py

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
>>> print f.channels
4646
>>> print f.duration
4747
"""
48-
from __future__ import with_statement
49-
from __future__ import division
5048

5149
import gi
5250
gi.require_version('Gst', '1.0')
@@ -55,20 +53,11 @@
5553
import sys
5654
import threading
5755
import os
56+
import queue
57+
from urllib.parse import quote
5858

5959
from .exceptions import DecodeError
6060

61-
try:
62-
import queue
63-
except ImportError:
64-
import Queue as queue
65-
66-
try:
67-
from urllib.parse import quote
68-
except ImportError:
69-
from urllib import quote
70-
71-
7261
QUEUE_SIZE = 10
7362
BUFFER_SIZE = 10
7463
SENTINEL = '__GSTDEC_SENTINEL__'
@@ -83,7 +72,7 @@ class GStreamerError(DecodeError):
8372
class UnknownTypeError(GStreamerError):
8473
"""Raised when Gstreamer can't decode the given file type."""
8574
def __init__(self, streaminfo):
86-
super(UnknownTypeError, self).__init__(
75+
super().__init__(
8776
"can't decode stream: " + streaminfo
8877
)
8978
self.streaminfo = streaminfo
@@ -99,7 +88,7 @@ class NoStreamError(GStreamerError):
9988
were found.
10089
"""
10190
def __init__(self):
102-
super(NoStreamError, self).__init__('no audio streams found')
91+
super().__init__('no audio streams found')
10392

10493

10594
class MetadataMissingError(GStreamerError):
@@ -114,7 +103,7 @@ class IncompleteGStreamerError(GStreamerError):
114103
principal plugin packages) are missing.
115104
"""
116105
def __init__(self):
117-
super(IncompleteGStreamerError, self).__init__(
106+
super().__init__(
118107
'missing GStreamer base plugins'
119108
)
120109

@@ -142,7 +131,7 @@ class MainLoopThread(threading.Thread):
142131
"""A daemon thread encapsulating a Gobject main loop.
143132
"""
144133
def __init__(self):
145-
super(MainLoopThread, self).__init__()
134+
super().__init__()
146135
self.loop = GLib.MainLoop.new(None, False)
147136
self.daemon = True
148137

@@ -152,7 +141,7 @@ def run(self):
152141

153142
# The decoder.
154143

155-
class GstAudioFile(object):
144+
class GstAudioFile:
156145
"""Reads raw audio data from any audio file that Gstreamer
157146
knows how to decode.
158147
@@ -373,17 +362,14 @@ def _message(self, bus, message):
373362

374363
# Iteration.
375364

376-
def next(self):
365+
def __next__(self):
377366
# Wait for data from the Gstreamer callbacks.
378367
val = self.queue.get()
379368
if val == SENTINEL:
380369
# End of stream.
381370
raise StopIteration
382371
return val
383372

384-
# For Python 3 compatibility.
385-
__next__ = next
386-
387373
def __iter__(self):
388374
return self
389375

@@ -418,11 +404,6 @@ def close(self, force=False):
418404
# Halt the pipeline (closing file).
419405
self.pipeline.set_state(Gst.State.NULL)
420406

421-
# Delete the pipeline object. This seems to be necessary on Python
422-
# 2, but not Python 3 for some reason: on 3.5, at least, the
423-
# pipeline gets dereferenced automatically.
424-
del self.pipeline
425-
426407
def __del__(self):
427408
self.close()
428409

audioread/macca.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
# included in all copies or substantial portions of the Software.
1414

1515
"""Read audio files using CoreAudio on Mac OS X."""
16-
import os
17-
import sys
16+
import copy
1817
import ctypes
1918
import ctypes.util
20-
import copy
19+
import os
20+
import sys
2121

2222
from .exceptions import DecodeError
2323

@@ -110,20 +110,20 @@ def __init__(self, code):
110110
msg = 'unsupported format'
111111
else:
112112
msg = 'error %i' % code
113-
super(MacError, self).__init__(msg)
113+
super().__init__(msg)
114114

115115

116116
def check(err):
117117
"""If err is nonzero, raise a MacError exception."""
118118
if err == ERROR_NOT_FOUND:
119-
raise IOError('file not found')
119+
raise OSError('file not found')
120120
elif err != 0:
121121
raise MacError(err)
122122

123123

124124
# CoreFoundation objects.
125125

126-
class CFObject(object):
126+
class CFObject:
127127
def __init__(self, obj):
128128
if obj == 0:
129129
raise ValueError('object is zero')
@@ -142,7 +142,7 @@ def __init__(self, filename):
142142
url = _corefoundation.CFURLCreateFromFileSystemRepresentation(
143143
0, filename, len(filename), False
144144
)
145-
super(CFURL, self).__init__(url)
145+
super().__init__(url)
146146

147147
def __str__(self):
148148
cfstr = _corefoundation.CFURLGetString(self._obj)
@@ -184,7 +184,7 @@ class AudioBufferList(ctypes.Structure):
184184

185185
# Main functionality.
186186

187-
class ExtAudioFile(object):
187+
class ExtAudioFile:
188188
"""A CoreAudio "extended audio file". Reads information and raw PCM
189189
audio data from any file that CoreAudio knows how to decode.
190190

audioread/maddec.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414

1515
"""Decode MPEG audio files with MAD (via pymad)."""
1616
import mad
17+
1718
from . import DecodeError
1819

1920

2021
class UnsupportedError(DecodeError):
2122
"""The file is not readable by MAD."""
2223

2324

24-
class MadAudioFile(object):
25+
class MadAudioFile:
2526
"""MPEG audio file decoder using the MAD library."""
2627
def __init__(self, filename):
2728
self.fp = open(filename, 'rb')

audioread/rawread.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,19 @@
1313
# included in all copies or substantial portions of the Software.
1414

1515
"""Uses standard-library modules to read AIFF, AIFF-C, and WAV files."""
16-
import wave
1716
import aifc
18-
import sunau
1917
import audioop
2018
import struct
21-
import sys
19+
import sunau
20+
import wave
2221

2322
from .exceptions import DecodeError
2423

2524
# Produce two-byte (16-bit) output samples.
2625
TARGET_WIDTH = 2
2726

2827
# Python 3.4 added support for 24-bit (3-byte) samples.
29-
if sys.version_info > (3, 4, 0):
30-
SUPPORTED_WIDTHS = (1, 2, 3, 4)
31-
else:
32-
SUPPORTED_WIDTHS = (1, 2, 4)
28+
SUPPORTED_WIDTHS = (1, 2, 3, 4)
3329

3430

3531
class UnsupportedError(DecodeError):
@@ -54,7 +50,7 @@ def byteswap(s):
5450
return b''.join(parts)
5551

5652

57-
class RawAudioFile(object):
53+
class RawAudioFile:
5854
"""An AIFF, WAV, or Au file that can be read by the Python standard
5955
library modules ``wave``, ``aifc``, and ``sunau``.
6056
"""

decode.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
# included in all copies or substantial portions of the Software.
1414

1515
"""Command-line tool to decode audio files to WAV files."""
16-
from __future__ import print_function
1716
import audioread
1817
import sys
1918
import os

setup.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)