Skip to content

Commit 1910ea4

Browse files
authored
Merge pull request SCons#4480 from Repiteo/non-serializable
Explicitly wrap non-serializable values in json dump
2 parents 8edf57f + eb93cd5 commit 1910ea4

File tree

4 files changed

+6
-2
lines changed

4 files changed

+6
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ RELEASE VERSION/DATE TO BE FILLED IN LATER
4444
prototype when including a header file.
4545

4646
From Thaddeus Crews:
47+
- Explicitly wrap non-serializable values in json dump
4748
- Implemented SCons.Util.sctyping as a safe means of hinting complex types. Currently
4849
only implemented for `Executor` as a proof-of-concept.
4950

RELEASE.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ IMPROVEMENTS
8080
- The NewParallel scheduler now only adds threads as new work requiring execution
8181
is discovered, up to the limit set by -j. This should reduce resource utilization
8282
when the achievable parallelism in the DAG is less than the -j limit.
83+
- Dumping an environment with `json` formatting will now explicitly specify if a given
84+
value cannot be serialized.
8385

8486

8587
PACKAGING

SCons/Environment.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1720,7 +1720,7 @@ def Dump(self, key=None, format: str='pretty'):
17201720
elif fmt == 'json':
17211721
import json
17221722
def non_serializable(obj):
1723-
return str(type(obj).__qualname__)
1723+
return '<<non-serializable: %s>>' % type(obj).__qualname__
17241724
return json.dumps(cvars, indent=4, default=non_serializable)
17251725
else:
17261726
raise ValueError("Unsupported serialization format: %s." % fmt)

SCons/EnvironmentTests.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3177,11 +3177,12 @@ def test_NoClean(self) -> None:
31773177
def test_Dump(self) -> None:
31783178
"""Test the Dump() method"""
31793179

3180-
env = self.TestEnvironment(FOO = 'foo')
3180+
env = self.TestEnvironment(FOO='foo', FOOFLAGS=CLVar('--bar --baz'))
31813181
assert env.Dump('FOO') == "'foo'", env.Dump('FOO')
31823182
assert len(env.Dump()) > 200, env.Dump() # no args version
31833183

31843184
assert env.Dump('FOO', 'json') == '"foo"' # JSON key version
3185+
self.assertEqual(env.Dump('FOOFLAGS', 'json'), '"<<non-serializable: CLVar>>"')
31853186
import json
31863187
env_dict = json.loads(env.Dump(format = 'json'))
31873188
assert env_dict['FOO'] == 'foo' # full JSON version

0 commit comments

Comments
 (0)