Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[1/6] refactor: define resource paths (not contents) on XModule classes #32286

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions xmodule/annotatable_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import textwrap

from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import Scope, String
Expand Down Expand Up @@ -75,28 +75,28 @@ class AnnotatableBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/html/display.js'),
resource_string(__name__, 'js/src/annotatable/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/html/display.js'),
resource_filename(__name__, 'js/src/annotatable/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource_string loaded the contents of the resource. We change it to resource_filename, which just returns the absolute path to the resource.

We make this change uniformly across all XModule-like XBlocks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking note: It looks like pkg_resources is deprecated and we should be using importlib.resources.path(package, resource). But annoyingly even that new way will be deprecated in Python 3.11 and replaced with a different interface.

It may be fine to leave as is for now, I've asked the setuptools community what the timeline for this deprecation is so we can plan accordingly.

}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/annotatable/display.scss'),
resource_filename(__name__, 'css/annotatable/display.scss'),
],
}

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/raw/edit/xml.js'),
resource_filename(__name__, 'js/src/raw/edit/xml.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [
resource_string(__name__, 'css/codemirror/codemirror.scss'),
resource_filename(__name__, 'css/codemirror/codemirror.scss'),
],
}
studio_js_module_name = "XMLEditingDescriptor"
Expand Down
24 changes: 12 additions & 12 deletions xmodule/capa_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from django.utils.encoding import smart_str
from django.utils.functional import cached_property
from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import utc
from web_fragments.fragment import Fragment
from xblock.core import XBlock
Expand Down Expand Up @@ -168,32 +168,32 @@ class ProblemBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/capa/display.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_string(__name__, 'js/src/capa/imageinput.js'),
resource_string(__name__, 'js/src/capa/schematic.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/capa/display.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/capa/imageinput.js'),
resource_filename(__name__, 'js/src/capa/schematic.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

preview_view_css = {
'scss': [
resource_string(__name__, 'css/capa/display.scss'),
resource_filename(__name__, 'css/capa/display.scss'),
],
}

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/problem/edit.js'),
resource_filename(__name__, 'js/src/problem/edit.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}

studio_view_css = {
'scss': [
resource_string(__name__, 'css/editor/edit.scss'),
resource_string(__name__, 'css/problem/edit.scss'),
resource_filename(__name__, 'css/editor/edit.scss'),
resource_filename(__name__, 'css/problem/edit.scss'),
]
}

Expand Down
14 changes: 7 additions & 7 deletions xmodule/conditional_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from lazy import lazy
from lxml import etree
from opaque_keys.edx.locator import BlockUsageLocator
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from xblock.core import XBlock
from xblock.fields import ReferenceList, Scope, String
Expand Down Expand Up @@ -148,11 +148,11 @@ class ConditionalBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/conditional/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/conditional/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -161,8 +161,8 @@ class ConditionalBlock(
mako_template = 'widgets/metadata-edit.html'
studio_js_module_name = 'SequenceDescriptor'
studio_view_js = {
'js': [resource_string(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'js': [resource_filename(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
24 changes: 12 additions & 12 deletions xmodule/html_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import textwrap
from datetime import datetime

from pkg_resources import resource_string
from pkg_resources import resource_filename

from django.conf import settings
from fs.errors import ResourceNotFound
Expand Down Expand Up @@ -144,15 +144,15 @@ def studio_view(self, _context):

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/html/display.js'),
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/collapsible.js'),
resource_string(__name__, 'js/src/html/imageModal.js'),
resource_string(__name__, 'js/common_static/js/vendor/draggabilly.js'),
resource_filename(__name__, 'js/src/html/display.js'),
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/collapsible.js'),
resource_filename(__name__, 'js/src/html/imageModal.js'),
resource_filename(__name__, 'js/common_static/js/vendor/draggabilly.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {'scss': [resource_string(__name__, 'css/html/display.scss')]}
preview_view_css = {'scss': [resource_filename(__name__, 'css/html/display.scss')]}

uses_xmodule_styles_setup = True

Expand All @@ -164,14 +164,14 @@ def studio_view(self, _context):

studio_view_js = {
'js': [
resource_string(__name__, 'js/src/html/edit.js')
resource_filename(__name__, 'js/src/html/edit.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [
resource_string(__name__, 'css/editor/edit.scss'),
resource_string(__name__, 'css/html/edit.scss')
resource_filename(__name__, 'css/editor/edit.scss'),
resource_filename(__name__, 'css/html/edit.scss')
]
}

Expand Down
8 changes: 4 additions & 4 deletions xmodule/library_content_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from lxml import etree
from lxml.etree import XMLSyntaxError
from opaque_keys.edx.locator import LibraryLocator
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from webob import Response
from xblock.completable import XBlockCompletionMode
Expand Down Expand Up @@ -97,7 +97,7 @@ class LibraryContentBlock(

preview_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -107,9 +107,9 @@ class LibraryContentBlock(
studio_js_module_name = "VerticalDescriptor"
studio_view_js = {
'js': [
resource_string(__name__, 'js/src/vertical/edit.js'),
resource_filename(__name__, 'js/src/vertical/edit.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
12 changes: 6 additions & 6 deletions xmodule/lti_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
from django.conf import settings
from lxml import etree
from oauthlib.oauth1.rfc5849 import signature
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import UTC
from webob import Response
from web_fragments.fragment import Fragment
Expand Down Expand Up @@ -374,13 +374,13 @@ class LTIBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/lti/lti.js')
resource_filename(__name__, 'js/src/lti/lti.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/lti/lti.scss')
resource_filename(__name__, 'css/lti/lti.scss')
],
}

Expand All @@ -389,9 +389,9 @@ class LTIBlock(
studio_js_module_name = 'MetadataOnlyEditingDescriptor'
studio_view_js = {
'js': [
resource_string(__name__, 'js/src/raw/edit/metadata-only.js')
resource_filename(__name__, 'js/src/raw/edit/metadata-only.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
14 changes: 7 additions & 7 deletions xmodule/poll_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from collections import OrderedDict
from copy import deepcopy

from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment

from lxml import etree
Expand Down Expand Up @@ -86,23 +86,23 @@ class PollBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/javascript_loader.js'),
resource_string(__name__, 'js/src/poll/poll.js'),
resource_string(__name__, 'js/src/poll/poll_main.js')
resource_filename(__name__, 'js/src/javascript_loader.js'),
resource_filename(__name__, 'js/src/poll/poll.js'),
resource_filename(__name__, 'js/src/poll/poll_main.js')
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [
resource_string(__name__, 'css/poll/display.scss')
resource_filename(__name__, 'css/poll/display.scss')
],
}

# There is no studio_view() for this XBlock but this is needed to make the
# the static_content command happy.
studio_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

studio_view_css = {
Expand Down
10 changes: 5 additions & 5 deletions xmodule/seq_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from lxml import etree
from opaque_keys.edx.keys import UsageKey
from pkg_resources import resource_string
from pkg_resources import resource_filename
from pytz import UTC
from web_fragments.fragment import Fragment
from xblock.completable import XBlockCompletionMode
Expand Down Expand Up @@ -273,22 +273,22 @@ class SequenceBlock(

preview_view_js = {
'js': [
resource_string(__name__, 'js/src/sequence/display.js'),
resource_filename(__name__, 'js/src/sequence/display.js'),
],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

preview_view_css = {
'scss': [
resource_string(__name__, 'css/sequence/display.scss'),
resource_filename(__name__, 'css/sequence/display.scss'),
],
}

# There is no studio_view() for this XBlock but this is needed to make the
# the static_content command happy.
studio_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js')
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js')
}

studio_view_css = {
Expand Down
8 changes: 4 additions & 4 deletions xmodule/split_test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from django.utils.functional import cached_property
from lxml import etree
from pkg_resources import resource_string
from pkg_resources import resource_filename
from web_fragments.fragment import Fragment
from webob import Response
from xblock.core import XBlock
Expand Down Expand Up @@ -160,7 +160,7 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method

preview_view_js = {
'js': [],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
preview_view_css = {
'scss': [],
Expand All @@ -169,8 +169,8 @@ class SplitTestBlock( # lint-amnesty, pylint: disable=abstract-method
mako_template = "widgets/metadata-only-edit.html"
studio_js_module_name = 'SequenceDescriptor'
studio_view_js = {
'js': [resource_string(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_string(__name__, 'js/src/xmodule.js'),
'js': [resource_filename(__name__, 'js/src/sequence/edit.js')],
'xmodule_js': resource_filename(__name__, 'js/src/xmodule.js'),
}
studio_view_css = {
'scss': [],
Expand Down
Loading