From 9c90edf1f357d8935c009b1a4a723eb21db55dfa Mon Sep 17 00:00:00 2001 From: JB Lovland Date: Tue, 30 Jan 2024 19:23:44 +0100 Subject: [PATCH] ENH: Add platform field to event-tracklog --- schema/definitions/0.8.0/schema/fmu_meta.json | 68 ++++++++++++++++--- src/fmu/dataio/_metadata.py | 8 +++ src/fmu/dataio/datastructure/meta/meta.py | 48 ++++++++++++- tests/test_units/test_metadata_class.py | 20 +++++- 4 files changed, 133 insertions(+), 11 deletions(-) diff --git a/schema/definitions/0.8.0/schema/fmu_meta.json b/schema/definitions/0.8.0/schema/fmu_meta.json index fa6b60f6c..f42074696 100644 --- a/schema/definitions/0.8.0/schema/fmu_meta.json +++ b/schema/definitions/0.8.0/schema/fmu_meta.json @@ -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": { @@ -7267,8 +7318,7 @@ { "type": "null" } - ], - "default": null + ] }, "user": { "$ref": "#/$defs/User" diff --git a/src/fmu/dataio/_metadata.py b/src/fmu/dataio/_metadata.py index 72d0ef02d..e0a2c0ce9 100644 --- a/src/fmu/dataio/_metadata.py +++ b/src/fmu/dataio/_metadata.py @@ -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 @@ -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", diff --git a/src/fmu/dataio/datastructure/meta/meta.py b/src/fmu/dataio/datastructure/meta/meta.py index 02041014b..8d0b77315 100644 --- a/src/fmu/dataio/datastructure/meta/meta.py +++ b/src/fmu/dataio/datastructure/meta/meta.py @@ -254,6 +254,48 @@ 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", @@ -261,9 +303,13 @@ class SystemInformation(BaseModel): 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): @@ -279,7 +325,7 @@ class TracklogEvent(BaseModel): ) user: User sysinfo: Optional[SystemInformation] = Field( - default=None, + default_factory=SystemInformation, ) diff --git a/tests/test_units/test_metadata_class.py b/tests/test_units/test_metadata_class.py index 9e38af2f8..63b970a20 100644 --- a/tests/test_units/test_metadata_class.py +++ b/tests/test_units/test_metadata_class.py @@ -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 @@ -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) # --------------------------------------------------------------------------------------