Skip to content

Commit ac8c518

Browse files
authoredFeb 7, 2025··
Serialize python env and version data (#478)
This PR adds an unstructure hook to the `Result` class to include the `init=False` attributes in the JSON. The current setting ignores these attributes so that the environment and version information is collected but won't become part of the stored file.
2 parents 55425de + 8f0d60f commit ac8c518

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed
 

‎benchmarks/result/result.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@
77
import importlib_metadata
88
from attrs import define, field
99
from attrs.validators import deep_mapping, instance_of
10+
from cattrs.gen import make_dict_unstructure_fn
1011
from pandas import DataFrame
1112

1213
from benchmarks.result import ResultMetadata
13-
from benchmarks.serialization import BenchmarkSerialization
14+
from benchmarks.serialization import BenchmarkSerialization, converter
1415

1516

1617
@define(frozen=True)
@@ -41,3 +42,9 @@ class Result(BenchmarkSerialization):
4142
def _default_python_env(self) -> dict[str, str]:
4243
installed_packages = importlib_metadata.distributions()
4344
return {dist.metadata["Name"]: dist.version for dist in installed_packages}
45+
46+
47+
converter.register_unstructure_hook(
48+
Result,
49+
make_dict_unstructure_fn(Result, converter, _cattrs_include_init_false=True),
50+
)

0 commit comments

Comments
 (0)
Please sign in to comment.