Skip to content

Commit

Permalink
refactor(MFFileMgmt): convert to posix path in strip_model_relative_path
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Apr 15, 2023
1 parent ec65d0c commit de8efdf
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion autotest/test_mf6.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ def test_basic_gwf(function_tmpdir, filename):
tdis_name = f"{name}.tdis"
tdis_path = innerdir / tdis_name
tdis_path.touch()
tdis_relpath = tdis_path.relative_to(ws)
tdis_relpath = tdis_path.relative_to(ws).as_posix()
tdis_relpath_win = str(tdis_relpath).replace("/", "\\")

if filename == "name":
Expand Down
10 changes: 8 additions & 2 deletions flopy/mf6/mfbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path
from shutil import copyfile
from typing import Union
from warnings import warn


# internal handled exceptions
Expand Down Expand Up @@ -289,9 +290,14 @@ def strip_model_relative_path(self, model_name, path) -> str:
return path

try:
return str(Path(path).relative_to(model_rel_path))
ret_path = Path(path).relative_to(model_rel_path)
except ValueError:
return str(Path(model_rel_path) / path)
warnings.warn(
f"Could not strip model relative path from {path}: {traceback.format_exc()}"
)
ret_path = Path(path)

return str(ret_path.as_posix())

@staticmethod
def unique_file_name(file_name, lookup):
Expand Down

0 comments on commit de8efdf

Please sign in to comment.