Unverified Commit b56a27b5 authored by moto's avatar moto Committed by GitHub
Browse files

Remove Py2 code from common_utils (#691)

parent 87ca9e99
import sys
PY3 = sys.version_info > (3, 0)
PY34 = sys.version_info >= (3, 4)
import importlib.util
def _check_module_exists(name: str) -> bool:
......@@ -11,28 +8,10 @@ def _check_module_exists(name: str) -> bool:
our tests, e.g., setting multiprocessing start method when imported
(see librosa/#747, torchvision/#544).
"""
if not PY3: # Python 2
import imp
try:
imp.find_module(name)
return True
except ImportError:
return False
elif not PY34: # Python [3, 3.4)
import importlib
loader = importlib.find_loader(name)
return loader is not None
else: # Python >= 3.4
import importlib
import importlib.util
spec = importlib.util.find_spec(name)
return spec is not None
spec = importlib.util.find_spec(name)
return spec is not None
IMPORT_NUMPY = _check_module_exists('numpy')
IMPORT_KALDI_IO = _check_module_exists('kaldi_io')
IMPORT_SCIPY = _check_module_exists('scipy')
# On Py2, importing librosa 0.6.1 triggers a TypeError (if using newest joblib)
# see librosa/librosa#729.
# TODO: allow Py2 when librosa 0.6.2 releases
IMPORT_LIBROSA = _check_module_exists('librosa') and PY3
IMPORT_LIBROSA = _check_module_exists('librosa')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment