Skip to content

Commit a653967

Browse files
author
Theofilos Manitaras
authored
Merge pull request #2930 from vkarak/bugfix/show-config-crash
[bugfix] Properly dump `json_formatter` with `--show-config` option
2 parents b890796 + 88e5de4 commit a653967

File tree

4 files changed

+12
-2
lines changed

4 files changed

+12
-2
lines changed

reframe/core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import reframe
1818
import reframe.core.settings as settings
1919
import reframe.utility as util
20+
import reframe.utility.jsonext as jsonext
2021
from reframe.core.environments import normalize_module_list
2122
from reframe.core.exceptions import ConfigError, ReframeFatalError
2223
from reframe.core.logging import getlogger
@@ -225,7 +226,7 @@ def __repr__(self):
225226
f'sources={self._sources!r})')
226227

227228
def __str__(self):
228-
return json.dumps(self._pick_config(), indent=2)
229+
return jsonext.dumps(self._pick_config(), indent=2)
229230

230231
# Delegate everything to either the original config or to the reduced one
231232
# if a system is selected

reframe/frontend/cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -831,7 +831,7 @@ def restrict_logging():
831831
f'no such configuration parameter found: {config_param}'
832832
)
833833
else:
834-
printer.info(json.dumps(value, indent=2))
834+
printer.info(jsonext.dumps(value, indent=2))
835835

836836
sys.exit(0)
837837

reframe/utility/jsonext.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def encode(obj, **kwargs):
6666
if inspect.istraceback(obj):
6767
return traceback.format_tb(obj)
6868

69+
if inspect.isfunction(obj):
70+
return f'py::{obj.__qualname__}'
71+
6972
newobj = encode_dict(obj)
7073
if newobj is not None:
7174
return newobj

unittests/test_utility.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,6 +1585,12 @@ def test_jsonext_dumps():
15851585
)
15861586
assert '{"(1, 2, 3)": 1}' == jsonext.dumps({(1, 2, 3): 1})
15871587

1588+
def foo():
1589+
pass
1590+
1591+
assert ('{"fn": "py::test_jsonext_dumps.<locals>.foo"}' ==
1592+
jsonext.dumps({'fn': foo}))
1593+
15881594

15891595
# Classes to test JSON deserialization
15901596

0 commit comments

Comments
 (0)