diff --git a/src/fmu/dataio/_filedata_provider.py b/src/fmu/dataio/_filedata_provider.py index feb38cb69..9cd527c70 100644 --- a/src/fmu/dataio/_filedata_provider.py +++ b/src/fmu/dataio/_filedata_provider.py @@ -42,10 +42,12 @@ class FileDataProvider: realname: str = "" # storing results in these variables - relative_path: Optional[str] = field(default="", init=False) + relative_path: str = field(default="", init=False) relative_path_symlink: Optional[str] = field(default="", init=False) - absolute_path: Optional[str] = field(default="", init=False) + + absolute_path: str = field(default="", init=False) absolute_path_symlink: Optional[str] = field(default="", init=False) + checksum_md5: Optional[str] = field(default="", init=False) def __post_init__(self) -> None: diff --git a/src/fmu/dataio/_metadata.py b/src/fmu/dataio/_metadata.py index 1502640ed..d3d0ee7c7 100644 --- a/src/fmu/dataio/_metadata.py +++ b/src/fmu/dataio/_metadata.py @@ -342,12 +342,6 @@ def _populate_meta_file(self) -> None: ) fdata.derive_filedata() - self.meta_file["relative_path"] = fdata.relative_path - self.meta_file["absolute_path"] = fdata.absolute_path - if fdata.absolute_path_symlink: - self.meta_file["relative_path_symlink"] = fdata.relative_path_symlink - self.meta_file["absolute_path_symlink"] = fdata.absolute_path_symlink - if self.compute_md5: if not self.objdata.extension.startswith("."): raise ValueError("A extension must start with '.'") @@ -356,14 +350,30 @@ def _populate_meta_file(self) -> None: suffix=self.objdata.extension, ) as tf: logger.info("Compute MD5 sum for tmp file...: %s", tf.name) - self.meta_file["checksum_md5"] = export_file_compute_checksum_md5( + checksum_md5 = export_file_compute_checksum_md5( self.obj, Path(tf.name), flag=self.dataio._usefmtflag, ) else: logger.info("Do not compute MD5 sum at this stage!") - self.meta_file["checksum_md5"] = None + checksum_md5 = None + + self.meta_file = meta.File( + absolute_path=Path(fdata.absolute_path), + relative_path=Path(fdata.relative_path), + checksum_md5=checksum_md5, + relative_path_symlink=Path(fdata.relative_path_symlink) + if fdata.relative_path_symlink + else None, + absolute_path_symlink=Path(fdata.absolute_path_symlink) + if fdata.absolute_path_symlink + else None, + ).model_dump( + mode="json", + exclude_none=True, + by_alias=True, + ) def _populate_meta_class(self) -> None: """Get the general class which is a simple string."""