Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0a0cd9e

Browse files
Issue #1528 Failing usage of relative paths for extra MetaSWAP files in iMOD projectfile (#1529)
Fixes #1528 # Description <!--- Thanks for opening a PR! Please add your description here of changes made and how they are going to resolve the linked issue --> Fixes the issue of using relative paths for the extra MetaSWAP files in the iMOD project file. # Checklist <!--- Before requesting review, please go through this checklist: --> - [x] Links to correct issue - [x] Update changelog, if changes affect users - [x] PR title starts with ``Issue #nr``, e.g. ``Issue #737`` - [x] Unit tests were added - [ ] **If feature added**: Added/extended example --------- Co-authored-by: JoerivanEngelen <[email protected]>
1 parent 87285fb commit 0a0cd9e

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

docs/api/changelog.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ Fixed
3636
version of iMOD Python or newer.
3737
- :meth:`imod.mf6.Modflow6Simulation.split` supports label array with a
3838
different name than ``"idomain"``.
39+
- :func:`imod.msw.MetaSwapModel.from_imod5_data` now supports the usage of
40+
relative paths for the extra files block.
3941

4042
Changed
4143
~~~~~~~

imod/formats/prj/prj.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,9 @@ def _parse_capblock(
330330

331331
def _parse_extrablock(lines: _LineIterator, n: int) -> Dict[str, List[str]]:
332332
"""Parse the MetaSWAP "extra files" block"""
333-
return {"paths": [next(lines) for _ in range(n)]}
333+
content = {"paths": [next(lines) for _ in range(n)]}
334+
content["paths"] = [[Path(x[0]).resolve()] for x in content["paths"]]
335+
return content
334336

335337

336338
def _parse_timeblock(

imod/tests/test_formats/test_prj.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ def test_parse_pcgblock():
399399
prj._parse_pcgblock(lines)
400400

401401

402-
def test__parse_block():
402+
def test__parse_block__header_error():
403403
lines = prj._LineIterator([["1", "(bla)", "1"]])
404404
content = {}
405405
with pytest.raises(
@@ -408,6 +408,23 @@ def test__parse_block():
408408
prj._parse_block(lines, content)
409409

410410

411+
def test__parse_blockline__path_resolved():
412+
lines = prj._LineIterator(
413+
[["1", "2", "1", "1.0", "0.0", "-999.99", "./ibound.idf"]]
414+
)
415+
parsed = prj._parse_blockline(lines, "2000-01-01 00:00:00")
416+
# Resolved paths are always absolute
417+
assert parsed["path"].is_absolute()
418+
419+
420+
def test__parse_extrablock__path_resolved():
421+
lines = prj._LineIterator(["./ibound.idf", "./para_sim.inp"])
422+
n = 2
423+
parsed = prj._parse_extrablock(lines, n)
424+
# Resolved paths are always absolute
425+
assert all(i.is_absolute() for i in parsed["paths"][0])
426+
427+
411428
def test__parse_periodsblock():
412429
lines = prj._LineIterator(
413430
[

0 commit comments

Comments
 (0)