Skip to content

Commit

Permalink
Return the absolute path from export() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrivenaes committed Oct 18, 2021
1 parent c824038 commit 639d4c3
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
3 changes: 2 additions & 1 deletion src/fmu/dataio/_export_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ def _item_to_file(self):

self._export_actual_object(outfile, metafile, relpath, abspath)

return fpath
return abspath

def _construct_filename_fmustandard1(self):
"""Construct filename stem according to datatype (class) and fmu style 1.
Expand Down Expand Up @@ -958,6 +958,7 @@ def _verify_path(

relpath = abspath.relative_to(useroot)

path = path.absolute() # may contain "../.." in path (not resolved)
logger.info("Full path to the actual file is: %s", path)
logger.info("Full path to the actual file is (resolved): %s", abspath)
logger.info("Full path to the metadata file (if used) is: %s", metapath)
Expand Down
11 changes: 3 additions & 8 deletions src/fmu/dataio/dataio.py
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ def export(
be included. For backward compatibilty, ``ìndex`` also supported.
Returns:
String path, relative to RUNPATH for exported file.
String: full path to exported item.
"""
if kwargs.get("index", False) is True: # backward compatibility
include_index = True
Expand All @@ -709,13 +709,8 @@ def export(
include_index=include_index,
)

filepath = pathlib.Path(exporter.save_to_file())
logger.info("Filepath (saving to file) is %s", filepath)
logger.info("Current PWD (dataio._pwd)is %s", self._pwd)
logger.info("Current RUNPATH is %s", self._runpath)
relpath = str(filepath.relative_to(self._runpath))
logger.info("Returning relative path as string: %s", relpath)
return relpath
# will return the absolute (resolved) path for exported file
return exporter.save_to_file()

@deprecation.deprecated(
deprecated_in="0.5",
Expand Down
34 changes: 16 additions & 18 deletions tests/test_fmu_dataio_cube.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test dataio for cube (most often seismic cube)."""

import json
import logging
import shutil
Expand Down Expand Up @@ -140,21 +139,20 @@ def test_cube_io_larger_case_ertrun(tmp_path):

metadataout = out / ".volantis--what_descr.segy.yml"

assert metadataout.is_file() is True

# assert metadataout.is_file() is True

# now read the metadata file and test some key entries:
# with open(metadataout, "r") as mstream:
# meta = yaml.safe_load(mstream)
# assert (
# meta["file"]["relative_path"]
# == "realization-0/iter-0/share/results/cubes/volantis--what_descr.segy"
# )
# assert meta["fmu"]["model"]["name"] == "ff"
# assert meta["fmu"]["iteration"]["name"] == "iter-0"
# assert meta["fmu"]["realization"]["name"] == "realization-0"
# assert meta["data"]["stratigraphic"] is False
# assert meta["data"]["bbox"]["xmin"] == 0.0
# assert meta["data"]["bbox"]["xmax"] == 550.0

# logger.info("\n%s", json.dumps(meta, indent=2))
# now read the metadata file and test some key entries:
with open(metadataout, "r") as mstream:
meta = yaml.safe_load(mstream)
assert (
meta["file"]["relative_path"]
== "realization-0/iter-0/share/results/cubes/volantis--what_descr.segy"
)
assert meta["fmu"]["model"]["name"] == "ff"
assert meta["fmu"]["iteration"]["name"] == "iter-0"
assert meta["fmu"]["realization"]["name"] == "realization-0"
assert meta["data"]["stratigraphic"] is False
assert meta["data"]["bbox"]["xmin"] == 0.0
assert meta["data"]["bbox"]["xmax"] == 550.0

logger.info("\n%s", json.dumps(meta, indent=2))
2 changes: 1 addition & 1 deletion tests/test_fmu_dataio_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def test_file_block(tmp_path):
values=0,
name="TopVolantis",
)
assert exp.export(srf, verbosity="INFO") == "share/results/maps"
assert exp.export(srf, verbosity="INFO") == str(out / "topvolantis--what_descr.gri")

metadataout = out / ".topvolantis--what_descr.gri.yml"
assert metadataout.is_file() is True
Expand Down

0 comments on commit 639d4c3

Please sign in to comment.