Skip to content

Commit b56a27b

Browse files
authored
Remove Py2 code from common_utils (#691)
1 parent 87ca9e9 commit b56a27b

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

torchaudio/common_utils.py

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
import sys
2-
3-
PY3 = sys.version_info > (3, 0)
4-
PY34 = sys.version_info >= (3, 4)
1+
import importlib.util
52

63

74
def _check_module_exists(name: str) -> bool:
@@ -11,28 +8,10 @@ def _check_module_exists(name: str) -> bool:
118
our tests, e.g., setting multiprocessing start method when imported
129
(see librosa/#747, torchvision/#544).
1310
"""
14-
if not PY3: # Python 2
15-
import imp
16-
try:
17-
imp.find_module(name)
18-
return True
19-
except ImportError:
20-
return False
21-
elif not PY34: # Python [3, 3.4)
22-
import importlib
23-
loader = importlib.find_loader(name)
24-
return loader is not None
25-
else: # Python >= 3.4
26-
import importlib
27-
import importlib.util
28-
spec = importlib.util.find_spec(name)
29-
return spec is not None
11+
spec = importlib.util.find_spec(name)
12+
return spec is not None
3013

3114
IMPORT_NUMPY = _check_module_exists('numpy')
3215
IMPORT_KALDI_IO = _check_module_exists('kaldi_io')
3316
IMPORT_SCIPY = _check_module_exists('scipy')
34-
35-
# On Py2, importing librosa 0.6.1 triggers a TypeError (if using newest joblib)
36-
# see librosa/librosa#729.
37-
# TODO: allow Py2 when librosa 0.6.2 releases
38-
IMPORT_LIBROSA = _check_module_exists('librosa') and PY3
17+
IMPORT_LIBROSA = _check_module_exists('librosa')

0 commit comments

Comments
 (0)