Skip to content

Commit

Permalink
Add Python environment and version metadata to benchmark results
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianliebig committed Feb 5, 2025
1 parent daaf4d1 commit bf95854
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion benchmarks/result/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@

from __future__ import annotations

import sys

import importlib_metadata
from attrs import define, field
from attrs.validators import instance_of
from attrs.validators import deep_mapping, instance_of
from pandas import DataFrame

from benchmarks.result import ResultMetadata
Expand All @@ -22,3 +25,19 @@ class Result(BenchmarkSerialization):

metadata: ResultMetadata = field(validator=instance_of(ResultMetadata))
"""The metadata associated with the benchmark result."""

python_env: dict[str, str] = field(
validator=deep_mapping(instance_of(str), instance_of(str), instance_of(dict))
)
"""The Python environment in which the benchmark was executed."""

python_version: str = field(default=sys.version, validator=instance_of(str))
"""The Python version in which the benchmark was executed."""

@python_env.default
def _default_python_env(self) -> dict[str, str]:
installed_packages = importlib_metadata.distributions()
package_dict = {
dist.metadata["Name"]: dist.version for dist in installed_packages
}
return package_dict

0 comments on commit bf95854

Please sign in to comment.