Files
edx-platform/import_shims/warn.py
Kyle McCormick 2b5d916512 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.
2021-03-08 12:49:31 -05:00

38 lines
1.2 KiB
Python

"""
Utilities for warning about deprecated imports temporarily supported by
the import_shim/ system.
See /docs/decisions/0007-sys-path-modification-removal.rst for details.
"""
class DeprecatedEdxPlatformImportError(Exception):
"""
Error: An edx-platform module is being imported from an unsupported location.
See `DeprecatedEdxPlatformImportWarning` above for context.
"""
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)
def warn_deprecated_import(old_import, new_import):
"""
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.
"""
raise DeprecatedEdxPlatformImportError(old_import, new_import)