Skip to content

Commit

Permalink
fix: done?
Browse files Browse the repository at this point in the history
  • Loading branch information
kdmccormick committed Jan 27, 2025
1 parent 64734b0 commit e88c7e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
13 changes: 11 additions & 2 deletions openedx/core/djangoapps/util/management/commands/dump_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import json
import re
import sys
from datetime import timedelta
from path import Path

from django.conf import settings
from django.core.management.base import BaseCommand
Expand Down Expand Up @@ -40,6 +38,9 @@ class Command(BaseCommand):
* "Path('my/path')" # a Path object
* "<lms.myapp.MyClass object at 0x704599fa2fd0>" # some random class instance
* "<_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>" # sys.stderr
and lambdas are printed by *roughly* printing out their source lines (it's impossible in Python to get the *exact*
source code, as it's been compiled into bytecode).
"""

def handle(self, *args, **kwargs):
Expand Down Expand Up @@ -81,5 +82,13 @@ def _to_json_friendly_repr(value: object, debug_key: str) -> object:
if len(proxy_args) == 1 and isinstance(proxy_args[0], str):
# Print gettext_lazy as simply the wrapped string
return proxy_args[0]
try:
qualname = value.__qualname__
except AttributeError:
pass
else:
if qualname == "<lambda>":
# Handle lambdas by printing the source lines
return "<lambda> defined with line(s): " + inspect.getsource(value).strip()
# For all other objects, print the repr
return repr(value)
16 changes: 8 additions & 8 deletions openedx/core/djangoapps/util/tests/test_dump_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def test_for_lms_settings(capsys):
# Check: tuples are converted to lists
assert isinstance(dump['XBLOCK_MIXINS'], list)

# Check: python references are converted to a dotted path
assert "xmodule.x_module.XModuleMixin" in dump['XBLOCK_MIXINS']
# Check: objects (like classes) are repr'd
assert "<class 'xmodule.x_module.XModuleMixin'>" in dump['XBLOCK_MIXINS']

# Check: nested dictionaries come through OK
assert dump['CODE_JAIL']['limit_overrides'] == {}
# Check: nested dictionaries come through OK, and int'l strings are just strings
assert dump['COURSE_ENROLLMENT_MODES']['audit']['display_name'] == "Audit"


@skip_unless_cms
Expand All @@ -46,11 +46,11 @@ def test_for_cms_settings(capsys):
# Check: tuples are converted to lists
assert isinstance(dump['XBLOCK_MIXINS'], list)

# Check: python references are converted to a dotted path
assert "xmodule.x_module.XModuleMixin" in dump['XBLOCK_MIXINS']
# Check: objects (like classes) are repr'd
assert "<class 'xmodule.x_module.XModuleMixin'>" in dump['XBLOCK_MIXINS']

# Check: nested dictionaries come through OK
assert dump['CODE_JAIL']['limit_overrides'] == {}
# Check: nested dictionaries come through OK, and int'l strings are just strings
assert dump['COURSE_ENROLLMENT_MODES']['audit']['display_name'] == "Audit"


def _get_settings_dump(captured_sys):
Expand Down

0 comments on commit e88c7e3

Please sign in to comment.