Skip to content

Commit

Permalink
ENH: Add platform field to event-tracklog
Browse files Browse the repository at this point in the history
  • Loading branch information
JB Lovland committed Feb 13, 2024
1 parent 72ce0ed commit 9c90edf
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 11 deletions.
68 changes: 59 additions & 9 deletions schema/definitions/0.8.0/schema/fmu_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -6396,27 +6396,78 @@
],
"default": null,
"examples": [
"1.2.3"
"2023.12.05-py38"
]
},
"komodo": {
"operating_system": {
"anyOf": [
{
"$ref": "#/$defs/VersionInformation"
"$ref": "#/$defs/SystemInformationOperatingSystem"
},
{
"type": "null"
}
],
"default": null,
"examples": [
"2023.12.05-py38"
]
"default": null
}
},
"title": "SystemInformation",
"type": "object"
},
"SystemInformationOperatingSystem": {
"description": "This model encapsulates various pieces of\nsystem-related information using Python's platform module. It provides a\nstructured way to access details about the system's hardware, operating\nsystem, and interpreter version information.",
"properties": {
"hostname": {
"description": "The network name of the computer, possibly not fully qualified.",
"examples": [
"Johns-MacBook-Pro.local"
],
"title": "Hostname",
"type": "string"
},
"operating_system": {
"description": "A detailed string identifying the underlying platform with as much useful information as possible.",
"examples": [
"Darwin-18.7.0-x86_64-i386-64bit"
],
"title": "Platform",
"type": "string"
},
"release": {
"description": "The system's release version, such as a version number or a name.",
"examples": [
"18.7.0"
],
"title": "Release",
"type": "string"
},
"system": {
"description": "The name of the operating system.",
"examples": [
"Darwin"
],
"title": "System",
"type": "string"
},
"version": {
"description": "The specific release version of the system.",
"examples": [
"#1 SMP Tue Aug 27 21:37:59 PDT 2019"
],
"title": "Version",
"type": "string"
}
},
"required": [
"hostname",
"operating_system",
"release",
"system",
"version"
],
"title": "SystemInformationOperatingSystem",
"type": "object"
},
"TableSpecification": {
"properties": {
"columns": {
Expand Down Expand Up @@ -7267,8 +7318,7 @@
{
"type": "null"
}
],
"default": null
]
},
"user": {
"$ref": "#/$defs/User"
Expand Down
8 changes: 8 additions & 0 deletions src/fmu/dataio/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import datetime
import getpass
import os
import platform
from dataclasses import dataclass, field
from datetime import timezone
from pathlib import Path
Expand Down Expand Up @@ -64,6 +65,13 @@ def generate_meta_tracklog() -> list[dict]:
komodo=meta.VersionInformation.model_construct(version=kr)
if (kr := os.environ.get("KOMODO_RELEASE"))
else None,
operating_system=meta.SystemInformationOperatingSystem.model_construct(
hostname=platform.node(),
operating_system=platform.platform(),
release=platform.release(),
system=platform.system(),
version=platform.version(),
),
),
).model_dump(
mode="json",
Expand Down
48 changes: 47 additions & 1 deletion src/fmu/dataio/datastructure/meta/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,62 @@ class VersionInformation(BaseModel):
version: str


class SystemInformationOperatingSystem(BaseModel):
"""
This model encapsulates various pieces of
system-related information using Python's platform module. It provides a
structured way to access details about the system's hardware, operating
system, and interpreter version information.
"""

hostname: str = Field(
title="Hostname",
description="The network name of the computer, possibly not fully qualified.",
examples=["Johns-MacBook-Pro.local"],
)

operating_system: str = Field(
title="Platform",
description=(
"A detailed string identifying the underlying platform "
"with as much useful information as possible."
),
examples=["Darwin-18.7.0-x86_64-i386-64bit"],
)

release: str = Field(
title="Release",
description="The system's release version, such as a version number or a name.",
examples=["18.7.0"],
)

system: str = Field(
title="System",
description="The name of the operating system.",
examples=["Darwin"],
)

version: str = Field(
title="Version",
description="The specific release version of the system.",
examples=["#1 SMP Tue Aug 27 21:37:59 PDT 2019"],
)


class SystemInformation(BaseModel):
fmu_dataio: Optional[VersionInformation] = Field(
alias="fmu-dataio",
default=None,
examples=["1.2.3"],
)
komodo: Optional[VersionInformation] = Field(
alias="fmu-dataio",
default=None,
examples=["2023.12.05-py38"],
)
operating_system: Optional[SystemInformationOperatingSystem] = Field(
default=None,
)


class TracklogEvent(BaseModel):
Expand All @@ -279,7 +325,7 @@ class TracklogEvent(BaseModel):
)
user: User
sysinfo: Optional[SystemInformation] = Field(
default=None,
default_factory=SystemInformation,
)


Expand Down
20 changes: 19 additions & 1 deletion tests/test_units/test_metadata_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import pytest
from fmu.dataio._metadata import SCHEMA, SOURCE, VERSION, ConfigurationError, _MetaData
from fmu.dataio._utils import prettyprint_dict
from fmu.dataio.datastructure.meta.meta import TracklogEvent
from fmu.dataio.datastructure.meta.meta import (
SystemInformationOperatingSystem,
TracklogEvent,
)

# pylint: disable=no-member

Expand Down Expand Up @@ -77,6 +80,21 @@ def test_generate_meta_tracklog_komodo_version(edataobj1, monkeypatch):
assert parsed.sysinfo.komodo.version == fake_komodo_release


def test_generate_meta_tracklog_operating_system(edataobj1):
mymeta = _MetaData("dummy", edataobj1)
mymeta._populate_meta_tracklog()
tracklog = mymeta.meta_tracklog

assert isinstance(tracklog, list)
assert len(tracklog) == 1 # assume "created"

parsed = TracklogEvent.model_validate(tracklog[0])
assert isinstance(
parsed.sysinfo.operating_system,
SystemInformationOperatingSystem,
)


# --------------------------------------------------------------------------------------
# DATA block (ObjectData)
# --------------------------------------------------------------------------------------
Expand Down

0 comments on commit 9c90edf

Please sign in to comment.