diff --git a/src/fmu/dataio/_metadata.py b/src/fmu/dataio/_metadata.py index 806feb013..2c618c9be 100644 --- a/src/fmu/dataio/_metadata.py +++ b/src/fmu/dataio/_metadata.py @@ -139,10 +139,9 @@ class MetaData: def __post_init__(self) -> None: logger.info("Initialize _MetaData instance.") - # one special case is that obj is a file path, and dataio.reuse_metadata_rule is - # active. In this case we read the existing metadata here and reuse parts - # according to rule described in string self.reuse_metadata_rule! - if isinstance(self.obj, (str, Path)) and self.dataio.reuse_metadata_rule: + # one special case is that obj is a file path. + # In this case we read the existing metadata here and reuse parts + if isinstance(self.obj, (str, Path)) and self.dataio._reuse_metadata: logger.info("Partially reuse existing metadata from %s", self.obj) self.meta_existing = read_metadata_from_file(self.obj) @@ -300,15 +299,10 @@ def _populate_meta_xpreprocessed(self) -> None: self.meta_xpreprocessed["subfolder"] = self.dataio.subfolder def _reuse_existing_metadata(self, meta: dict) -> dict: - """Perform a merge procedure if the key `reuse_metadata_rule` is active.""" - if self.dataio and self.dataio.reuse_metadata_rule: - oldmeta = self.meta_existing - newmeta = meta.copy() - if self.dataio.reuse_metadata_rule == "preprocessed": - return glue_metadata_preprocessed(oldmeta, newmeta) - raise ValueError( - f"The reuse_metadata_rule {self.dataio.reuse_metadata_rule} is not " - "supported." + """Perform a merge procedure if input is a file i.e. `_reuse_metadata=True`""" + if self.dataio._reuse_metadata: + return glue_metadata_preprocessed( + oldmeta=self.meta_existing, newmeta=meta.copy() ) return meta diff --git a/src/fmu/dataio/dataio.py b/src/fmu/dataio/dataio.py index 9829f45cb..897cb71c8 100644 --- a/src/fmu/dataio/dataio.py +++ b/src/fmu/dataio/dataio.py @@ -279,8 +279,7 @@ class ExportData: "preprocessed" folder instead, and metadata will be partially re-used in an ERT model run. If a non-FMU run is detected (e.g. you run from project), fmu-dataio will detect that and set actual context to None as fall-back - (unless preprocessed is specified). If value is "preprocessed", see also - ``reuse_metadata`` key. + (unless preprocessed is specified). description: A multiline description of the data either as a string or a list of strings. @@ -323,11 +322,6 @@ class ExportData: detected automatically from the FMU run. Can be used to override in rare cases. If so, numbers must be >= 0 - reuse_metadata_rule: This input is None or a string describing rule for reusing - metadata. Default is None, but if the input is a file string or object with - already valid metadata, then it is assumed to be "preprocessed", which - merges the metadata after predefined rules. - runpath: TODO! Optional and deprecated. The relative location of the current run root. Optional and will in most cases be auto-detected, assuming that FMU folder conventions are followed. For an ERT run e.g. @@ -427,7 +421,7 @@ class ExportData: undef_is_zero: bool = False parent: str = "" realization: int = -999 - reuse_metadata_rule: Optional[str] = None + reuse_metadata_rule: Optional[str] = None # deprecated runpath: Optional[Union[str, Path]] = None subfolder: str = "" tagname: str = "" @@ -447,11 +441,18 @@ class ExportData: _pwd: Path = field(default_factory=Path, init=False) _config_is_valid: bool = field(default=True, init=False) _fmurun: bool = field(default=False, init=False) + _reuse_metadata: bool = field(default=False, init=False) # << NB! storing ACTUAL casepath: _rootpath: Path = field(default_factory=Path, init=False) def __post_init__(self) -> None: + if self.reuse_metadata_rule: + warn( + "The 'reuse_metadata_rule' key is deprecated and has no effect. " + "Please remove it from the argument list.", + UserWarning, + ) if self.verbosity != "DEPRECATED": warn( "Using the 'verbosity' key is now deprecated and will have no " @@ -627,12 +628,11 @@ def _check_obj_if_file(self, obj: types.Inferrable) -> types.Inferrable: """ if isinstance(obj, (str, Path)): - if isinstance(obj, str): - obj = Path(obj) + obj = Path(obj) if not obj.exists(): raise ValidationError(f"The file {obj} does not exist.") - if not self.reuse_metadata_rule: - self.reuse_metadata_rule = "preprocessed" + + self._reuse_metadata = True currentmeta = read_metadata(obj) if "_preprocessed" not in currentmeta: @@ -671,9 +671,6 @@ def generate_metadata( Examples of such known types are XTGeo objects (e.g. a RegularSurface), a Pandas Dataframe, a PyArrow table, etc. - If the key ``reuse_metadata_rule`` is applied with legal value, the object may - also be a reference to a file with existing metadata which then will be re-used. - Args: obj: XTGeo instance, a Pandas Dataframe instance or other supported object. compute_md5: If True, compute a MD5 checksum for the exported file. diff --git a/src/fmu/dataio/providers/objectdata/_base.py b/src/fmu/dataio/providers/objectdata/_base.py index 8617df105..94d5e8e1a 100644 --- a/src/fmu/dataio/providers/objectdata/_base.py +++ b/src/fmu/dataio/providers/objectdata/_base.py @@ -194,10 +194,7 @@ def _process_content(self) -> tuple[str | dict, dict | None]: # content == "unset" is not wanted, but in case metadata has been produced while # doing a preprocessing step first, and this step is re-using metadata, the # check is not done. - if self.dataio._usecontent == "unset" and ( - self.dataio.reuse_metadata_rule is None - or self.dataio.reuse_metadata_rule != "preprocessed" - ): + if self.dataio._usecontent == "unset" and not self.dataio._reuse_metadata: allowed_fields = ", ".join(AllowedContent.model_fields.keys()) warn( "The is not provided which defaults to 'unset'. "