Quiet deprecation warnings from imp module

The "imp" module is deprecated and should be replaced by "importlib". As
a consequence, loading the django settings used to raise deprecation
warnings:

    DeprecationWarning: the imp module is deprecated in favour of
    importlib; see the module's documentation for alternative uses

It should be noted that python 3.5.1 ships with an older release of
distutils which still relies on the imp module. Thus, users of python
3.5.1 (for instance: edx.org developers) will continue to see the
deprecation warning for some time, despite this patch. We suggest
upgrading to python 3.5.9.

This addresses part of CRI-196.
This commit is contained in:
Régis Behmo
2020-04-30 23:41:40 +02:00
parent 8ed8d1ed9f
commit cfe311be0f
2 changed files with 6 additions and 10 deletions

View File

@@ -40,7 +40,7 @@ When refering to XBlocks, we use the entry-point name. For example,
# pylint: disable=unused-import, useless-suppression, wrong-import-order, wrong-import-position
import imp
import importlib.util
import os
import sys
from datetime import timedelta
@@ -1623,10 +1623,8 @@ OPTIONAL_APPS = (
for app_name, insert_before in OPTIONAL_APPS:
# First attempt to only find the module rather than actually importing it,
# to avoid circular references - only try to import if it can't be found
# by find_module, which doesn't work with import hooks
try:
imp.find_module(app_name)
except ImportError:
# by find_spec, which doesn't work with import hooks
if importlib.util.find_spec(app_name) is None:
try:
__import__(app_name)
except ImportError:

View File

@@ -29,7 +29,7 @@ Longer TODO:
# pylint: disable=invalid-name, wrong-import-position
import imp
import importlib.util
import sys
import os
@@ -3181,10 +3181,8 @@ OPTIONAL_APPS = [
for app_name, insert_before in OPTIONAL_APPS:
# First attempt to only find the module rather than actually importing it,
# to avoid circular references - only try to import if it can't be found
# by find_module, which doesn't work with import hooks
try:
imp.find_module(app_name)
except ImportError:
# by find_spec, which doesn't work with import hooks
if importlib.util.find_spec(app_name) is None:
try:
__import__(app_name)
except ImportError: