Skip to content

Commit 391e0d8

Browse files
authored
Merge branch 'master' into hraza/add_embargo_restricted_country
2 parents f09759a + 182bfc4 commit 391e0d8

31 files changed

+316
-274
lines changed

cms/djangoapps/contentstore/tasks.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from tempfile import NamedTemporaryFile, mkdtemp
1212

1313
import olxcleaner
14-
from importlib.metadata import entry_points
14+
import pkg_resources
1515
from ccx_keys.locator import CCXLocator
1616
from celery import shared_task
1717
from celery.utils.log import get_task_logger
@@ -85,7 +85,7 @@
8585
FILE_READ_CHUNK = 1024 # bytes
8686
FULL_COURSE_REINDEX_THRESHOLD = 1
8787
ALL_ALLOWED_XBLOCKS = frozenset(
88-
[entry_point.name for entry_point in entry_points(group="xblock.v1")]
88+
[entry_point.name for entry_point in pkg_resources.iter_entry_points("xblock.v1")]
8989
)
9090

9191

cms/envs/common.py

+14-41
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@
144144
get_theme_base_dirs_from_settings
145145
)
146146
from openedx.core.lib.license import LicenseMixin
147-
from openedx.core.lib.derived import derived, derived_collection_entry
147+
from openedx.core.lib.derived import Derived
148148
from openedx.core.release import doc_version
149149

150150
# pylint: enable=useless-suppression
@@ -740,7 +740,7 @@
740740
# Don't look for template source files inside installed applications.
741741
'APP_DIRS': False,
742742
# Instead, look for template source files in these dirs.
743-
'DIRS': _make_mako_template_dirs,
743+
'DIRS': Derived(_make_mako_template_dirs),
744744
# Options specific to this backend.
745745
'OPTIONS': {
746746
'loaders': (
@@ -759,7 +759,7 @@
759759
'NAME': 'mako',
760760
'BACKEND': 'common.djangoapps.edxmako.backend.Mako',
761761
'APP_DIRS': False,
762-
'DIRS': _make_mako_template_dirs,
762+
'DIRS': Derived(_make_mako_template_dirs),
763763
'OPTIONS': {
764764
'context_processors': CONTEXT_PROCESSORS,
765765
'debug': False,
@@ -778,8 +778,6 @@
778778
}
779779
},
780780
]
781-
derived_collection_entry('TEMPLATES', 0, 'DIRS')
782-
derived_collection_entry('TEMPLATES', 1, 'DIRS')
783781
DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0]
784782

785783
#################################### AWS #######################################
@@ -825,8 +823,7 @@
825823
# Warning: Must have trailing slash to activate correct logout view
826824
# (auth_backends, not LMS user_authn)
827825
FRONTEND_LOGOUT_URL = '/logout/'
828-
FRONTEND_REGISTER_URL = lambda settings: settings.LMS_ROOT_URL + '/register'
829-
derived('FRONTEND_REGISTER_URL')
826+
FRONTEND_REGISTER_URL = Derived(lambda settings: settings.LMS_ROOT_URL + '/register')
830827

831828
LMS_ENROLLMENT_API_PATH = "/api/enrollment/v1/"
832829
ENTERPRISE_API_URL = LMS_INTERNAL_ROOT_URL + '/enterprise/api/v1/'
@@ -1316,8 +1313,7 @@
13161313
STATICI18N_FILENAME_FUNCTION = 'statici18n.utils.legacy_filename'
13171314
STATICI18N_ROOT = PROJECT_ROOT / "static"
13181315

1319-
LOCALE_PATHS = _make_locale_paths
1320-
derived('LOCALE_PATHS')
1316+
LOCALE_PATHS = Derived(_make_locale_paths)
13211317

13221318
# Messages
13231319
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
@@ -2087,10 +2083,9 @@
20872083
# See annotations in lms/envs/common.py for details.
20882084
RETIRED_EMAIL_DOMAIN = 'retired.invalid'
20892085
# See annotations in lms/envs/common.py for details.
2090-
RETIRED_USERNAME_FMT = lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}'
2086+
RETIRED_USERNAME_FMT = Derived(lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}')
20912087
# See annotations in lms/envs/common.py for details.
2092-
RETIRED_EMAIL_FMT = lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN
2093-
derived('RETIRED_USERNAME_FMT', 'RETIRED_EMAIL_FMT')
2088+
RETIRED_EMAIL_FMT = Derived(lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN)
20942089
# See annotations in lms/envs/common.py for details.
20952090
RETIRED_USER_SALTS = ['abc', '123']
20962091
# See annotations in lms/envs/common.py for details.
@@ -2367,13 +2362,12 @@
23672362
############## Settings for Studio Context Sensitive Help ##############
23682363

23692364
HELP_TOKENS_INI_FILE = REPO_ROOT / "cms" / "envs" / "help_tokens.ini"
2370-
HELP_TOKENS_LANGUAGE_CODE = lambda settings: settings.LANGUAGE_CODE
2371-
HELP_TOKENS_VERSION = lambda settings: doc_version()
2365+
HELP_TOKENS_LANGUAGE_CODE = Derived(lambda settings: settings.LANGUAGE_CODE)
2366+
HELP_TOKENS_VERSION = Derived(lambda settings: doc_version())
23722367
HELP_TOKENS_BOOKS = {
23732368
'learner': 'https://edx.readthedocs.io/projects/open-edx-learner-guide',
23742369
'course_author': 'https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course',
23752370
}
2376-
derived('HELP_TOKENS_LANGUAGE_CODE', 'HELP_TOKENS_VERSION')
23772371

23782372
# Used with Email sending
23792373
RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS = 5
@@ -2876,15 +2870,15 @@ def _should_send_learning_badge_events(settings):
28762870
},
28772871
'org.openedx.content_authoring.xblock.published.v1': {
28782872
'course-authoring-xblock-lifecycle':
2879-
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
2873+
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
28802874
},
28812875
'org.openedx.content_authoring.xblock.deleted.v1': {
28822876
'course-authoring-xblock-lifecycle':
2883-
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
2877+
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
28842878
},
28852879
'org.openedx.content_authoring.xblock.duplicated.v1': {
28862880
'course-authoring-xblock-lifecycle':
2887-
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
2881+
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
28882882
},
28892883
# LMS events. These have to be copied over here because lms.common adds some derived entries as well,
28902884
# and the derivation fails if the keys are missing. If we ever remove the import of lms.common, we can remove these.
@@ -2899,38 +2893,17 @@ def _should_send_learning_badge_events(settings):
28992893
"org.openedx.learning.course.passing.status.updated.v1": {
29002894
"learning-badges-lifecycle": {
29012895
"event_key_field": "course_passing_status.course.course_key",
2902-
"enabled": _should_send_learning_badge_events,
2896+
"enabled": Derived(_should_send_learning_badge_events),
29032897
},
29042898
},
29052899
"org.openedx.learning.ccx.course.passing.status.updated.v1": {
29062900
"learning-badges-lifecycle": {
29072901
"event_key_field": "course_passing_status.course.ccx_course_key",
2908-
"enabled": _should_send_learning_badge_events,
2902+
"enabled": Derived(_should_send_learning_badge_events),
29092903
},
29102904
},
29112905
}
29122906

2913-
2914-
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.content_authoring.xblock.published.v1',
2915-
'course-authoring-xblock-lifecycle', 'enabled')
2916-
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.content_authoring.xblock.duplicated.v1',
2917-
'course-authoring-xblock-lifecycle', 'enabled')
2918-
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.content_authoring.xblock.deleted.v1',
2919-
'course-authoring-xblock-lifecycle', 'enabled')
2920-
2921-
derived_collection_entry(
2922-
"EVENT_BUS_PRODUCER_CONFIG",
2923-
"org.openedx.learning.course.passing.status.updated.v1",
2924-
"learning-badges-lifecycle",
2925-
"enabled",
2926-
)
2927-
derived_collection_entry(
2928-
"EVENT_BUS_PRODUCER_CONFIG",
2929-
"org.openedx.learning.ccx.course.passing.status.updated.v1",
2930-
"learning-badges-lifecycle",
2931-
"enabled",
2932-
)
2933-
29342907
################### Authoring API ######################
29352908

29362909
# This affects the Authoring API swagger docs but not the legacy swagger docs under /api-docs/.

cms/pytest.ini

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ filterwarnings =
1616
ignore:.*You can remove default_app_config.*:PendingDeprecationWarning
1717
# ABC deprecation Warning comes from libsass
1818
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated.*:DeprecationWarning:sass
19+
# declare_namespace Warning comes from XBlock https://github.com/openedx/XBlock/issues/641
20+
# and also due to dependency: https://github.com/PyFilesystem/pyfilesystem2
21+
ignore:Deprecated call to `pkg_resources.declare_namespace.*:DeprecationWarning
22+
ignore:.*pkg_resources is deprecated as an API.*:DeprecationWarning
1923
ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki
2024

2125
norecursedirs = envs

common/djangoapps/edxmako/paths.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
import hashlib
66
import os
77

8-
from importlib.resources import files
9-
from pathlib import Path
8+
import pkg_resources
109
from django.conf import settings
1110
from mako.exceptions import TopLevelLookupException
1211
from mako.lookup import TemplateLookup
@@ -123,7 +122,7 @@ def add_lookup(namespace, directory, package=None, prepend=False):
123122
"""
124123
Adds a new mako template lookup directory to the given namespace.
125124
126-
If `package` is specified, `importlib.resources` is used to look up the directory
125+
If `package` is specified, `pkg_resources` is used to look up the directory
127126
inside the given package. Otherwise `directory` is assumed to be a path
128127
in the filesystem.
129128
"""
@@ -137,11 +136,8 @@ def add_lookup(namespace, directory, package=None, prepend=False):
137136
encoding_errors='replace',
138137
)
139138
if package:
140-
package, module_path = package.split('.', 1)
141-
module_dir = str(Path(module_path).parent)
142-
directory = files(package).joinpath(module_dir, directory)
143-
144-
templates.add_directory(str(directory), prepend=prepend)
139+
directory = pkg_resources.resource_filename(package, directory)
140+
templates.add_directory(directory, prepend=prepend)
145141

146142

147143
@request_cached()

common/test/pytest.ini

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ filterwarnings =
1515
ignore:.*You can remove default_app_config.*:PendingDeprecationWarning
1616
# ABC deprecation Warning comes from libsass
1717
ignore:Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated.*:DeprecationWarning:sass
18+
# declare_namespace Warning comes from XBlock https://github.com/openedx/XBlock/issues/641
19+
# and also due to dependency: https://github.com/PyFilesystem/pyfilesystem2
20+
ignore:Deprecated call to `pkg_resources.declare_namespace.*:DeprecationWarning
21+
ignore:.*pkg_resources is deprecated as an API.*:DeprecationWarning
1822
ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki
1923

2024
norecursedirs = .cache

docs/decisions/0000-static-asset-plan.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ mechanism:
8484

8585
``openedx.core.lib.xblock_pipeline.finder.XBlockPipelineFinder``
8686
Custom finder that accesses and extracts assets from pip-installed XBlocks via
87-
``importlib.resources``.
87+
``pkg_resources``.
8888

8989
``openedx.core.storage.DevelopmentStorage/ProductionStorage``
9090
Custom ``FileStorage`` classes that mostly exist for theme-awareness.

docs/decisions/0019-oep-58-atlas-translations-design.rst

+3-3
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ be updated to support the new ``XBlockI18nService``
305305
def _get_statici18n_js_url():
306306
"""
307307
Returns the Javascript translation file for the currently selected language, if any found by
308-
`importlib.resources.files`
308+
`pkg_resources`
309309
"""
310310
lang_code = translation.get_language()
311311
if not lang_code:
@@ -320,8 +320,8 @@ be updated to support the new ``XBlockI18nService``
320320
text_js = 'public/js/translations/{lang_code}/text.js'
321321
country_code = lang_code.split('-')[0]
322322
for code in (translation.to_locale(lang_code), lang_code, country_code):
323-
if files(loader.module_name).joinpath(text_js.format(lang_code=code)).is_file():
324-
return text_js.format(lang_code=code)
323+
if pkg_resources.resource_exists(loader.module_name, text_js.format(lang_code=code)):
324+
return text_js.format(lang_code=code)
325325
return None
326326
327327

lms/envs/common.py

+13-34
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
get_themes_unchecked,
7070
get_theme_base_dirs_from_settings
7171
)
72-
from openedx.core.lib.derived import derived, derived_collection_entry
72+
from openedx.core.lib.derived import Derived
7373
from openedx.core.release import doc_version
7474
from lms.djangoapps.lms_xblock.mixin import LmsBlockMixin
7575

@@ -1395,7 +1395,7 @@ def _make_mako_template_dirs(settings):
13951395
# Don't look for template source files inside installed applications.
13961396
'APP_DIRS': False,
13971397
# Instead, look for template source files in these dirs.
1398-
'DIRS': _make_mako_template_dirs,
1398+
'DIRS': Derived(_make_mako_template_dirs),
13991399
# Options specific to this backend.
14001400
'OPTIONS': {
14011401
'context_processors': CONTEXT_PROCESSORS,
@@ -1404,7 +1404,6 @@ def _make_mako_template_dirs(settings):
14041404
}
14051405
},
14061406
]
1407-
derived_collection_entry('TEMPLATES', 1, 'DIRS')
14081407
DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0]
14091408
DEFAULT_TEMPLATE_ENGINE_DIRS = DEFAULT_TEMPLATE_ENGINE['DIRS'][:]
14101409

@@ -1734,7 +1733,7 @@ def _make_mako_template_dirs(settings):
17341733
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
17351734
'OPTIONS': {
17361735
'default_class': 'xmodule.hidden_block.HiddenBlock',
1737-
'fs_root': lambda settings: settings.DATA_DIR,
1736+
'fs_root': Derived(lambda settings: settings.DATA_DIR),
17381737
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string',
17391738
}
17401739
},
@@ -1744,7 +1743,7 @@ def _make_mako_template_dirs(settings):
17441743
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
17451744
'OPTIONS': {
17461745
'default_class': 'xmodule.hidden_block.HiddenBlock',
1747-
'fs_root': lambda settings: settings.DATA_DIR,
1746+
'fs_root': Derived(lambda settings: settings.DATA_DIR),
17481747
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string',
17491748
}
17501749
}
@@ -2054,8 +2053,7 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
20542053
for locale_path in settings.COMPREHENSIVE_THEME_LOCALE_PATHS:
20552054
locale_paths += (path(locale_path), )
20562055
return locale_paths
2057-
LOCALE_PATHS = _make_locale_paths
2058-
derived('LOCALE_PATHS')
2056+
LOCALE_PATHS = Derived(_make_locale_paths)
20592057

20602058
# Messages
20612059
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
@@ -4658,13 +4656,12 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
46584656
############## Settings for LMS Context Sensitive Help ##############
46594657

46604658
HELP_TOKENS_INI_FILE = REPO_ROOT / "lms" / "envs" / "help_tokens.ini"
4661-
HELP_TOKENS_LANGUAGE_CODE = lambda settings: settings.LANGUAGE_CODE
4662-
HELP_TOKENS_VERSION = lambda settings: doc_version()
4659+
HELP_TOKENS_LANGUAGE_CODE = Derived(lambda settings: settings.LANGUAGE_CODE)
4660+
HELP_TOKENS_VERSION = Derived(lambda settings: doc_version())
46634661
HELP_TOKENS_BOOKS = {
46644662
'learner': 'https://edx.readthedocs.io/projects/open-edx-learner-guide',
46654663
'course_author': 'https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course',
46664664
}
4667-
derived('HELP_TOKENS_LANGUAGE_CODE', 'HELP_TOKENS_VERSION')
46684665

46694666
############## OPEN EDX ENTERPRISE SERVICE CONFIGURATION ######################
46704667
# The Open edX Enterprise service is currently hosted via the LMS container/process.
@@ -4952,14 +4949,13 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
49524949
# .. setting_description: Set the format a retired user username field gets transformed into, where {}
49534950
# is replaced with the hash of the original username. This is a derived setting that depends on
49544951
# RETIRED_USERNAME_PREFIX value.
4955-
RETIRED_USERNAME_FMT = lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}'
4952+
RETIRED_USERNAME_FMT = Derived(lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}')
49564953
# .. setting_name: RETIRED_EMAIL_FMT
49574954
# .. setting_default: retired__user_{}@retired.invalid
49584955
# .. setting_description: Set the format a retired user email field gets transformed into, where {} is
49594956
# replaced with the hash of the original email. This is a derived setting that depends on
49604957
# RETIRED_EMAIL_PREFIX and RETIRED_EMAIL_DOMAIN values.
4961-
RETIRED_EMAIL_FMT = lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN
4962-
derived('RETIRED_USERNAME_FMT', 'RETIRED_EMAIL_FMT')
4958+
RETIRED_EMAIL_FMT = Derived(lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN)
49634959
# .. setting_name: RETIRED_USER_SALTS
49644960
# .. setting_default: ['abc', '123']
49654961
# .. setting_description: Set a list of salts used for hashing usernames and emails on users retirement.
@@ -5447,11 +5443,11 @@ def _should_send_learning_badge_events(settings):
54475443
EVENT_BUS_PRODUCER_CONFIG = {
54485444
'org.openedx.learning.certificate.created.v1': {
54495445
'learning-certificate-lifecycle':
5450-
{'event_key_field': 'certificate.course.course_key', 'enabled': _should_send_certificate_events},
5446+
{'event_key_field': 'certificate.course.course_key', 'enabled': Derived(_should_send_certificate_events)},
54515447
},
54525448
'org.openedx.learning.certificate.revoked.v1': {
54535449
'learning-certificate-lifecycle':
5454-
{'event_key_field': 'certificate.course.course_key', 'enabled': _should_send_certificate_events},
5450+
{'event_key_field': 'certificate.course.course_key', 'enabled': Derived(_should_send_certificate_events)},
54555451
},
54565452
'org.openedx.learning.course.unenrollment.completed.v1': {
54575453
'course-unenrollment-lifecycle':
@@ -5513,33 +5509,16 @@ def _should_send_learning_badge_events(settings):
55135509
"org.openedx.learning.course.passing.status.updated.v1": {
55145510
"learning-badges-lifecycle": {
55155511
"event_key_field": "course_passing_status.course.course_key",
5516-
"enabled": _should_send_learning_badge_events,
5512+
"enabled": Derived(_should_send_learning_badge_events),
55175513
},
55185514
},
55195515
"org.openedx.learning.ccx.course.passing.status.updated.v1": {
55205516
"learning-badges-lifecycle": {
55215517
"event_key_field": "course_passing_status.course.ccx_course_key",
5522-
"enabled": _should_send_learning_badge_events,
5518+
"enabled": Derived(_should_send_learning_badge_events),
55235519
},
55245520
},
55255521
}
5526-
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.created.v1',
5527-
'learning-certificate-lifecycle', 'enabled')
5528-
derived_collection_entry('EVENT_BUS_PRODUCER_CONFIG', 'org.openedx.learning.certificate.revoked.v1',
5529-
'learning-certificate-lifecycle', 'enabled')
5530-
5531-
derived_collection_entry(
5532-
"EVENT_BUS_PRODUCER_CONFIG",
5533-
"org.openedx.learning.course.passing.status.updated.v1",
5534-
"learning-badges-lifecycle",
5535-
"enabled",
5536-
)
5537-
derived_collection_entry(
5538-
"EVENT_BUS_PRODUCER_CONFIG",
5539-
"org.openedx.learning.ccx.course.passing.status.updated.v1",
5540-
"learning-badges-lifecycle",
5541-
"enabled",
5542-
)
55435522

55445523
BEAMER_PRODUCT_ID = ""
55455524

0 commit comments

Comments
 (0)