Skip to content
This repository has been archived by the owner on Oct 5, 2023. It is now read-only.

Commit

Permalink
chore: add deprecation warnings on use of deprecated package import
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan committed Oct 2, 2023
1 parent ca4dd44 commit 497dfe8
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 8 deletions.
2 changes: 1 addition & 1 deletion xblockutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Useful classes and functionality for building and testing XBlocks
"""

__version__ = '3.4.1'
__version__ = '4.0.0'
Empty file.
34 changes: 34 additions & 0 deletions xblockutils/deprecation/warn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""
Utilities for warning about the use of deprecated package
See https://github.com/openedx/xblock-utils/issues/197 for details.
"""

import warnings


class DeprecatedPackageWarning(DeprecationWarning):
"""
A warning that a deprecated package is being used.
"""

def __init__(self, old_import, new_import):
super().__init__()
self.old_import = old_import
self.new_import = new_import

def __str__(self):
return (
"Please use import {self.new_import} instead of {self.old_import} as "
"'xblock-utils' package has been deprecated and migrated within 'xblock' package. "
).format(self=self)


def warn_deprecated_package(old_import, new_import):
"""
Warn that a package has been deprecated
"""
warnings.warn(
DeprecatedPackageWarning(old_import, new_import),
stacklevel=3, # Should surface the line that is doing the importing.
)
7 changes: 7 additions & 0 deletions xblockutils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
Useful helper methods
"""

from xblockutils.deprecation.warn import warn_deprecated_package

warn_deprecated_package(
'xblockutils.helpers',
'xblock.utils.helpers'
)


def child_isinstance(block, child_id, block_class_or_mixin):
"""
Expand Down
7 changes: 7 additions & 0 deletions xblockutils/publish_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@

from xblock.core import XBlock

from xblockutils.deprecation.warn import warn_deprecated_package

warn_deprecated_package(
'xblockutils.publish_event',
'xblock.utils.publish_event'
)


class PublishEventMixin:
"""
Expand Down
11 changes: 8 additions & 3 deletions xblockutils/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,17 @@
import warnings

import pkg_resources

from django.template import Context, Template, Engine
from django.template.backends.django import get_installed_libraries

from mako.template import Template as MakoTemplate
from mako.lookup import TemplateLookup as MakoTemplateLookup
from mako.template import Template as MakoTemplate

from xblockutils.deprecation.warn import warn_deprecated_package

warn_deprecated_package(
'xblockutils.resources',
'xblock.utils.resources'
)


class ResourceLoader:
Expand Down
6 changes: 6 additions & 0 deletions xblockutils/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@
This module contains a mixins that allows third party XBlocks to access Settings Service in edX LMS.
"""

from xblockutils.deprecation.warn import warn_deprecated_package
from xblockutils.resources import ResourceLoader

warn_deprecated_package(
'xblockutils.settings',
'xblock.utils.settings'
)


class XBlockWithSettingsMixin:
"""
Expand Down
14 changes: 10 additions & 4 deletions xblockutils/studio_editable.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,29 @@


import logging
import simplejson as json

import simplejson as json
from web_fragments.fragment import Fragment
from xblock.core import XBlock, XBlockMixin
from xblock.fields import Scope, JSONField, List, Integer, Float, Boolean, String, DateTime
from xblock.exceptions import JsonHandlerError, NoSuchViewError
from web_fragments.fragment import Fragment
from xblock.fields import Scope, JSONField, List, Integer, Float, Boolean, String, DateTime
from xblock.validation import Validation

from xblockutils.deprecation.warn import warn_deprecated_package
from xblockutils.resources import ResourceLoader

warn_deprecated_package(
'xblockutils.studio_editable',
'xblock.utils.studio_editable'
)

# Globals ###########################################################

log = logging.getLogger(__name__)
loader = ResourceLoader(__name__)

# Classes ###########################################################

# Classes ###########################################################

class FutureFields:
"""
Expand Down
6 changes: 6 additions & 0 deletions xblockutils/templatetags/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
from django.templatetags import i18n
from django.utils.translation import get_language, trans_real

from xblockutils.deprecation.warn import warn_deprecated_package

warn_deprecated_package(
'xblockutils.templatetags.i18n',
'xblock.utils.templatetags.i18n'
)

register = Library()

Expand Down

0 comments on commit 497dfe8

Please sign in to comment.