From cfe311be0f9c7079d31afb94bdd6fa8c70cec211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Thu, 30 Apr 2020 23:41:40 +0200 Subject: [PATCH 1/2] 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. --- cms/envs/common.py | 8 +++----- lms/envs/common.py | 8 +++----- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index 206182b89e..99d7a3102c 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -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: diff --git a/lms/envs/common.py b/lms/envs/common.py index 4cfa792cdd..220a988a22 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -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: From cc6e823fe6a9bde88e5625b3876ae424e1591372 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Fri, 1 May 2020 00:03:07 +0200 Subject: [PATCH 2/2] Quiet courseware import warnings As it is explained in courseware/__init__.py: Importing 'lms.djangoapps.courseware' as 'courseware' is no longer supported This warning, while relevant, decreased the signal/noise ratio when investigating the lms logs. The "bulk_email" app was the only remaining app importing the courseware module incorrectly. All edx-platform modules and dependencies now follow the new convention. This is in part for CRI-196. --- lms/djangoapps/bulk_email/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lms/djangoapps/bulk_email/views.py b/lms/djangoapps/bulk_email/views.py index 5879b7411e..c3e5344f9f 100644 --- a/lms/djangoapps/bulk_email/views.py +++ b/lms/djangoapps/bulk_email/views.py @@ -11,7 +11,7 @@ from django.contrib.auth.models import User from django.http import Http404 from bulk_email.models import Optout -from courseware.courses import get_course_by_id +from lms.djangoapps.courseware.courses import get_course_by_id from edxmako.shortcuts import render_to_response from lms.djangoapps.discussion.notification_prefs.views import ( UsernameCipher,