Skip to content

Commit

Permalink
Serialize python env and version data (#478)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AdrianSosic authored Feb 7, 2025
2 parents 55425de + 8f0d60f commit ac8c518
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion benchmarks/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
import importlib_metadata
from attrs import define, field
from attrs.validators import deep_mapping, instance_of
from cattrs.gen import make_dict_unstructure_fn
from pandas import DataFrame

from benchmarks.result import ResultMetadata
from benchmarks.serialization import BenchmarkSerialization
from benchmarks.serialization import BenchmarkSerialization, converter


@define(frozen=True)
Expand Down Expand Up @@ -41,3 +42,9 @@ class Result(BenchmarkSerialization):
def _default_python_env(self) -> dict[str, str]:
installed_packages = importlib_metadata.distributions()
return {dist.metadata["Name"]: dist.version for dist in installed_packages}


converter.register_unstructure_hook(
Result,
make_dict_unstructure_fn(Result, converter, _cattrs_include_init_false=True),
)

0 comments on commit ac8c518

Please sign in to comment.