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.
This commit is contained in:
Kyle McCormick
2021-03-05 20:35:58 -05:00
committed by Kyle McCormick
parent e1614b5324
commit 2b5d916512
3 changed files with 9 additions and 69 deletions

View File

@@ -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

View File

@@ -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)

View File

@@ -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