Skip to content

Commit 15921f4

Browse files
committed
fix: test finder changes
1 parent 182bfc4 commit 15921f4

File tree

31 files changed

+273
-314
lines changed

31 files changed

+273
-314
lines changed

cms/djangoapps/contentstore/tasks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from tempfile import NamedTemporaryFile, mkdtemp
1212

1313
import olxcleaner
14-
import pkg_resources
14+
from importlib.metadata import entry_points
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 pkg_resources.iter_entry_points("xblock.v1")]
88+
[entry_point.name for entry_point in entry_points(group="xblock.v1")]
8989
)
9090

9191

cms/envs/common.py

Lines changed: 41 additions & 14 deletions
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
147+
from openedx.core.lib.derived import derived, derived_collection_entry
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': Derived(_make_mako_template_dirs),
743+
'DIRS': _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': Derived(_make_mako_template_dirs),
762+
'DIRS': _make_mako_template_dirs,
763763
'OPTIONS': {
764764
'context_processors': CONTEXT_PROCESSORS,
765765
'debug': False,
@@ -778,6 +778,8 @@
778778
}
779779
},
780780
]
781+
derived_collection_entry('TEMPLATES', 0, 'DIRS')
782+
derived_collection_entry('TEMPLATES', 1, 'DIRS')
781783
DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0]
782784

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

828831
LMS_ENROLLMENT_API_PATH = "/api/enrollment/v1/"
829832
ENTERPRISE_API_URL = LMS_INTERNAL_ROOT_URL + '/enterprise/api/v1/'
@@ -1313,7 +1316,8 @@
13131316
STATICI18N_FILENAME_FUNCTION = 'statici18n.utils.legacy_filename'
13141317
STATICI18N_ROOT = PROJECT_ROOT / "static"
13151318

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

13181322
# Messages
13191323
MESSAGE_STORAGE = 'django.contrib.messages.storage.session.SessionStorage'
@@ -2083,9 +2087,10 @@
20832087
# See annotations in lms/envs/common.py for details.
20842088
RETIRED_EMAIL_DOMAIN = 'retired.invalid'
20852089
# See annotations in lms/envs/common.py for details.
2086-
RETIRED_USERNAME_FMT = Derived(lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}')
2090+
RETIRED_USERNAME_FMT = lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}'
20872091
# See annotations in lms/envs/common.py for details.
2088-
RETIRED_EMAIL_FMT = Derived(lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN)
2092+
RETIRED_EMAIL_FMT = lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN
2093+
derived('RETIRED_USERNAME_FMT', 'RETIRED_EMAIL_FMT')
20892094
# See annotations in lms/envs/common.py for details.
20902095
RETIRED_USER_SALTS = ['abc', '123']
20912096
# See annotations in lms/envs/common.py for details.
@@ -2362,12 +2367,13 @@
23622367
############## Settings for Studio Context Sensitive Help ##############
23632368

23642369
HELP_TOKENS_INI_FILE = REPO_ROOT / "cms" / "envs" / "help_tokens.ini"
2365-
HELP_TOKENS_LANGUAGE_CODE = Derived(lambda settings: settings.LANGUAGE_CODE)
2366-
HELP_TOKENS_VERSION = Derived(lambda settings: doc_version())
2370+
HELP_TOKENS_LANGUAGE_CODE = lambda settings: settings.LANGUAGE_CODE
2371+
HELP_TOKENS_VERSION = lambda settings: doc_version()
23672372
HELP_TOKENS_BOOKS = {
23682373
'learner': 'https://edx.readthedocs.io/projects/open-edx-learner-guide',
23692374
'course_author': 'https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course',
23702375
}
2376+
derived('HELP_TOKENS_LANGUAGE_CODE', 'HELP_TOKENS_VERSION')
23712377

23722378
# Used with Email sending
23732379
RETRY_ACTIVATION_EMAIL_MAX_ATTEMPTS = 5
@@ -2870,15 +2876,15 @@ def _should_send_learning_badge_events(settings):
28702876
},
28712877
'org.openedx.content_authoring.xblock.published.v1': {
28722878
'course-authoring-xblock-lifecycle':
2873-
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
2879+
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
28742880
},
28752881
'org.openedx.content_authoring.xblock.deleted.v1': {
28762882
'course-authoring-xblock-lifecycle':
2877-
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
2883+
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
28782884
},
28792885
'org.openedx.content_authoring.xblock.duplicated.v1': {
28802886
'course-authoring-xblock-lifecycle':
2881-
{'event_key_field': 'xblock_info.usage_key', 'enabled': Derived(_should_send_xblock_events)},
2887+
{'event_key_field': 'xblock_info.usage_key', 'enabled': _should_send_xblock_events},
28822888
},
28832889
# LMS events. These have to be copied over here because lms.common adds some derived entries as well,
28842890
# and the derivation fails if the keys are missing. If we ever remove the import of lms.common, we can remove these.
@@ -2893,17 +2899,38 @@ def _should_send_learning_badge_events(settings):
28932899
"org.openedx.learning.course.passing.status.updated.v1": {
28942900
"learning-badges-lifecycle": {
28952901
"event_key_field": "course_passing_status.course.course_key",
2896-
"enabled": Derived(_should_send_learning_badge_events),
2902+
"enabled": _should_send_learning_badge_events,
28972903
},
28982904
},
28992905
"org.openedx.learning.ccx.course.passing.status.updated.v1": {
29002906
"learning-badges-lifecycle": {
29012907
"event_key_field": "course_passing_status.course.ccx_course_key",
2902-
"enabled": Derived(_should_send_learning_badge_events),
2908+
"enabled": _should_send_learning_badge_events,
29032909
},
29042910
},
29052911
}
29062912

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+
29072934
################### Authoring API ######################
29082935

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

cms/pytest.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ 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
2319
ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki
2420

2521
norecursedirs = envs

common/djangoapps/edxmako/paths.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
import hashlib
66
import os
77

8-
import pkg_resources
8+
from importlib.resources import files
9+
from pathlib import Path
910
from django.conf import settings
1011
from mako.exceptions import TopLevelLookupException
1112
from mako.lookup import TemplateLookup
@@ -122,7 +123,7 @@ def add_lookup(namespace, directory, package=None, prepend=False):
122123
"""
123124
Adds a new mako template lookup directory to the given namespace.
124125
125-
If `package` is specified, `pkg_resources` is used to look up the directory
126+
If `package` is specified, `importlib.resources` is used to look up the directory
126127
inside the given package. Otherwise `directory` is assumed to be a path
127128
in the filesystem.
128129
"""
@@ -136,8 +137,11 @@ def add_lookup(namespace, directory, package=None, prepend=False):
136137
encoding_errors='replace',
137138
)
138139
if package:
139-
directory = pkg_resources.resource_filename(package, directory)
140-
templates.add_directory(directory, prepend=prepend)
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)
141145

142146

143147
@request_cached()

common/test/pytest.ini

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ 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
2218
ignore:'etree' is deprecated. Use 'xml.etree.ElementTree' instead.:DeprecationWarning:wiki
2319

2420
norecursedirs = .cache

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

Lines changed: 1 addition & 1 deletion
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-
``pkg_resources``.
87+
``importlib.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

Lines changed: 3 additions & 3 deletions
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-
`pkg_resources`
308+
`importlib.resources.files`
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 pkg_resources.resource_exists(loader.module_name, text_js.format(lang_code=code)):
324-
return text_js.format(lang_code=code)
323+
if files(loader.module_name).joinpath(text_js.format(lang_code=code)).is_file():
324+
return text_js.format(lang_code=code)
325325
return None
326326
327327

lms/envs/common.py

Lines changed: 34 additions & 13 deletions
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
72+
from openedx.core.lib.derived import derived, derived_collection_entry
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': Derived(_make_mako_template_dirs),
1398+
'DIRS': _make_mako_template_dirs,
13991399
# Options specific to this backend.
14001400
'OPTIONS': {
14011401
'context_processors': CONTEXT_PROCESSORS,
@@ -1404,6 +1404,7 @@ def _make_mako_template_dirs(settings):
14041404
}
14051405
},
14061406
]
1407+
derived_collection_entry('TEMPLATES', 1, 'DIRS')
14071408
DEFAULT_TEMPLATE_ENGINE = TEMPLATES[0]
14081409
DEFAULT_TEMPLATE_ENGINE_DIRS = DEFAULT_TEMPLATE_ENGINE['DIRS'][:]
14091410

@@ -1733,7 +1734,7 @@ def _make_mako_template_dirs(settings):
17331734
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
17341735
'OPTIONS': {
17351736
'default_class': 'xmodule.hidden_block.HiddenBlock',
1736-
'fs_root': Derived(lambda settings: settings.DATA_DIR),
1737+
'fs_root': lambda settings: settings.DATA_DIR,
17371738
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string',
17381739
}
17391740
},
@@ -1743,7 +1744,7 @@ def _make_mako_template_dirs(settings):
17431744
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
17441745
'OPTIONS': {
17451746
'default_class': 'xmodule.hidden_block.HiddenBlock',
1746-
'fs_root': Derived(lambda settings: settings.DATA_DIR),
1747+
'fs_root': lambda settings: settings.DATA_DIR,
17471748
'render_template': 'common.djangoapps.edxmako.shortcuts.render_to_string',
17481749
}
17491750
}
@@ -2053,7 +2054,8 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
20532054
for locale_path in settings.COMPREHENSIVE_THEME_LOCALE_PATHS:
20542055
locale_paths += (path(locale_path), )
20552056
return locale_paths
2056-
LOCALE_PATHS = Derived(_make_locale_paths)
2057+
LOCALE_PATHS = _make_locale_paths
2058+
derived('LOCALE_PATHS')
20572059

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

46584660
HELP_TOKENS_INI_FILE = REPO_ROOT / "lms" / "envs" / "help_tokens.ini"
4659-
HELP_TOKENS_LANGUAGE_CODE = Derived(lambda settings: settings.LANGUAGE_CODE)
4660-
HELP_TOKENS_VERSION = Derived(lambda settings: doc_version())
4661+
HELP_TOKENS_LANGUAGE_CODE = lambda settings: settings.LANGUAGE_CODE
4662+
HELP_TOKENS_VERSION = lambda settings: doc_version()
46614663
HELP_TOKENS_BOOKS = {
46624664
'learner': 'https://edx.readthedocs.io/projects/open-edx-learner-guide',
46634665
'course_author': 'https://edx.readthedocs.io/projects/open-edx-building-and-running-a-course',
46644666
}
4667+
derived('HELP_TOKENS_LANGUAGE_CODE', 'HELP_TOKENS_VERSION')
46654668

46664669
############## OPEN EDX ENTERPRISE SERVICE CONFIGURATION ######################
46674670
# The Open edX Enterprise service is currently hosted via the LMS container/process.
@@ -4949,13 +4952,14 @@ def _make_locale_paths(settings): # pylint: disable=missing-function-docstring
49494952
# .. setting_description: Set the format a retired user username field gets transformed into, where {}
49504953
# is replaced with the hash of the original username. This is a derived setting that depends on
49514954
# RETIRED_USERNAME_PREFIX value.
4952-
RETIRED_USERNAME_FMT = Derived(lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}')
4955+
RETIRED_USERNAME_FMT = lambda settings: settings.RETIRED_USERNAME_PREFIX + '{}'
49534956
# .. setting_name: RETIRED_EMAIL_FMT
49544957
# .. setting_default: retired__user_{}@retired.invalid
49554958
# .. setting_description: Set the format a retired user email field gets transformed into, where {} is
49564959
# replaced with the hash of the original email. This is a derived setting that depends on
49574960
# RETIRED_EMAIL_PREFIX and RETIRED_EMAIL_DOMAIN values.
4958-
RETIRED_EMAIL_FMT = Derived(lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN)
4961+
RETIRED_EMAIL_FMT = lambda settings: settings.RETIRED_EMAIL_PREFIX + '{}@' + settings.RETIRED_EMAIL_DOMAIN
4962+
derived('RETIRED_USERNAME_FMT', 'RETIRED_EMAIL_FMT')
49594963
# .. setting_name: RETIRED_USER_SALTS
49604964
# .. setting_default: ['abc', '123']
49614965
# .. setting_description: Set a list of salts used for hashing usernames and emails on users retirement.
@@ -5443,11 +5447,11 @@ def _should_send_learning_badge_events(settings):
54435447
EVENT_BUS_PRODUCER_CONFIG = {
54445448
'org.openedx.learning.certificate.created.v1': {
54455449
'learning-certificate-lifecycle':
5446-
{'event_key_field': 'certificate.course.course_key', 'enabled': Derived(_should_send_certificate_events)},
5450+
{'event_key_field': 'certificate.course.course_key', 'enabled': _should_send_certificate_events},
54475451
},
54485452
'org.openedx.learning.certificate.revoked.v1': {
54495453
'learning-certificate-lifecycle':
5450-
{'event_key_field': 'certificate.course.course_key', 'enabled': Derived(_should_send_certificate_events)},
5454+
{'event_key_field': 'certificate.course.course_key', 'enabled': _should_send_certificate_events},
54515455
},
54525456
'org.openedx.learning.course.unenrollment.completed.v1': {
54535457
'course-unenrollment-lifecycle':
@@ -5509,16 +5513,33 @@ def _should_send_learning_badge_events(settings):
55095513
"org.openedx.learning.course.passing.status.updated.v1": {
55105514
"learning-badges-lifecycle": {
55115515
"event_key_field": "course_passing_status.course.course_key",
5512-
"enabled": Derived(_should_send_learning_badge_events),
5516+
"enabled": _should_send_learning_badge_events,
55135517
},
55145518
},
55155519
"org.openedx.learning.ccx.course.passing.status.updated.v1": {
55165520
"learning-badges-lifecycle": {
55175521
"event_key_field": "course_passing_status.course.ccx_course_key",
5518-
"enabled": Derived(_should_send_learning_badge_events),
5522+
"enabled": _should_send_learning_badge_events,
55195523
},
55205524
},
55215525
}
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+
)
55225543

55235544
BEAMER_PRODUCT_ID = ""
55245545

0 commit comments

Comments
 (0)