Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLN: Use File pydantic to build file-object #508

Merged
merged 1 commit into from
Mar 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/fmu/dataio/_filedata_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
26 changes: 18 additions & 8 deletions src/fmu/dataio/_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '.'")
Expand All @@ -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."""
Expand Down
Loading