From 2b5d916512fc5af8a838a1f05ebf890a4703f19f Mon Sep 17 00:00:00 2001 From: Kyle McCormick Date: Fri, 5 Mar 2021 20:35:58 -0500 Subject: [PATCH] refactor!: deprecated import paths now always raise Previously, deprecated [lms|cms|common]/djangoapps import paths would only raise errors if the ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS flag, which defaulted to False (but is overriden to True for Devstack and *.edx.org), was enabled. This change removes that setting and always raises on use those deprecated import paths. --- cms/envs/common.py | 14 ------------- import_shims/warn.py | 50 ++++++++------------------------------------ lms/envs/common.py | 14 ------------- 3 files changed, 9 insertions(+), 69 deletions(-) diff --git a/cms/envs/common.py b/cms/envs/common.py index bbddc17434..98c99d224a 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -2393,17 +2393,3 @@ LOGO_URL_PNG = None LOGO_TRADEMARK_URL = None FAVICON_URL = None DEFAULT_EMAIL_LOGO_URL = 'https://edx-cdn.org/v3/default/logo.png' - -# .. toggle_name: ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS -# .. toggle_implementation: DjangoSetting -# .. toggle_default: False -# .. toggle_use_cases: temporary -# .. toggle_creation_date: 2021-01-20 -# .. toggle_target_removal_date: 2021-01-27 -# .. toggle_tickets: https://github.com/edx/edx-platform/pull/25932 -# .. toggle_description: Whether to raise an exception where, -# normally, a DeprecatedEdxPlatformImportWarning would be raised. -# This will allow us to test dropping support for the deprecated -# import paths without yet removing all of the import_shims -# machinery. -ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS = False diff --git a/import_shims/warn.py b/import_shims/warn.py index 92a25b2a53..5adbe8be61 100644 --- a/import_shims/warn.py +++ b/import_shims/warn.py @@ -1,42 +1,10 @@ -""" # lint-amnesty, pylint: disable=django-not-configured +""" Utilities for warning about deprecated imports temporarily supported by the import_shim/ system. See /docs/decisions/0007-sys-path-modification-removal.rst for details. """ -import warnings - -from django.conf import settings -from edx_django_utils.monitoring import set_custom_attribute - - -class DeprecatedEdxPlatformImportWarning(DeprecationWarning): - """ - A warning that a module is being imported from an unsupported location. - - Example use case: - edx-platform modules should be imported from the root of the repository. - - For example, `from lms.djangoapps.course_wiki import views` is good. - - However, we historically modify `sys.path` to allow importing relative to - certain subdirectories. For example, `from course_wiki ipmort views` currently - works. - - We want to stardize on the prefixed version for a few different reasons. - """ - - def __init__(self, old_import, new_import): - super().__init__() - self.old_import = old_import - self.new_import = new_import - - def __str__(self): - return ( - "Importing {self.old_import} instead of {self.new_import} is deprecated" - ).format(self=self) - class DeprecatedEdxPlatformImportError(Exception): """ @@ -58,12 +26,12 @@ class DeprecatedEdxPlatformImportError(Exception): def warn_deprecated_import(old_import, new_import): """ - Warn that a module is being imported from its old location. + Raise an error that a module is being imported from an unsupported location. + + The function is named "warn_deprecated_import" because importing + from these locations used to raise warnings instead of errors, + but updating all references to the old function name did not seem + worth it, especially since this function will be removed soon after + the Lilac release is cut. """ - if settings.ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS: - raise DeprecatedEdxPlatformImportError(old_import, new_import) - set_custom_attribute("deprecated_edx_platform_import", old_import) - warnings.warn( - DeprecatedEdxPlatformImportWarning(old_import, new_import), - stacklevel=3, # Should surface the line that is doing the importing. - ) + raise DeprecatedEdxPlatformImportError(old_import, new_import) diff --git a/lms/envs/common.py b/lms/envs/common.py index b3de500e2f..624f7070d3 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -4662,17 +4662,3 @@ LOGO_URL_PNG = None LOGO_TRADEMARK_URL = None FAVICON_URL = None DEFAULT_EMAIL_LOGO_URL = 'https://edx-cdn.org/v3/default/logo.png' - -# .. toggle_name: ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS -# .. toggle_implementation: DjangoSetting -# .. toggle_default: False -# .. toggle_use_cases: rollout -# .. toggle_creation_date: 2021-01-20 -# .. toggle_target_removal_date: 2021-01-27 -# .. toggle_tickets: https://github.com/edx/edx-platform/pull/25932 -# .. toggle_description: Whether to raise an exception where, -# normally, a DeprecatedEdxPlatformImportWarning would be raised. -# This will allow us to test dropping support for the deprecated -# import paths without yet removing all of the import_shims -# machinery. -ERROR_ON_DEPRECATED_EDX_PLATFORM_IMPORTS = False