Skip to content
Merged
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
64 changes: 42 additions & 22 deletions flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import threading
import warnings
from datetime import datetime
from pathlib import Path
from shutil import which
from subprocess import PIPE, STDOUT, Popen

Expand Down Expand Up @@ -432,7 +433,7 @@ def namefile(self, namefile):

@property
def model_ws(self):
return self._model_ws
return copy.deepcopy(self._model_ws)

@model_ws.setter
def model_ws(self, model_ws):
Expand Down Expand Up @@ -1282,10 +1283,6 @@ def _reset_external(self, pth, old_pth):
new_ext_fnames.append(new_ext_file)
self.external_fnames = new_ext_fnames

@property
def model_ws(self):
return copy.deepcopy(self._model_ws)

def _set_name(self, value):
"""
Set model name
Expand Down Expand Up @@ -1637,6 +1634,45 @@ def to_shapefile(self, filename, package_names=None, **kwargs):
return


def resolve_exe_name(model_ws, exe_name, silent):
exe_name = Path(exe_name)
if str(exe_name.parent) == ".":
exe = which(str(exe_name))
if exe is None:
if exe_name.suffix.lower() == ".exe":
# try removing .exe suffix
exe = which(str(exe_name)[:-4])
if exe is not None:
exe_name = str(exe_name)[:-4]
if exe is None:
raise Exception(
f"The program "
f"{flopy_io.relpath_safe(exe_name, model_ws)} "
f"does not exist or is not executable."
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the "
f"model: {flopy_io.relpath_safe(exe_name, model_ws)}"
)
else:
# make relative path into absolute path
exe_name = exe_name.absolute()
if not exe_name.exists() and not Path(f"{str(exe_name)}.exe").exists():
raise Exception(
f"The program {flopy_io.relpath_safe(exe_name, model_ws)} "
f"does not exist or is not executable."
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the "
f"model: {flopy_io.relpath_safe(exe_name, model_ws)}"
)
return exe_name


def run_model(
exe_name,
namefile,
Expand Down Expand Up @@ -1701,23 +1737,7 @@ def run_model(
normal_msg[idx] = s.lower()

# Check to make sure that program and namefile exist
exe = which(exe_name)
if exe is None:
if exe_name.lower().endswith(".exe"):
# try removing .exe suffix
exe = which(exe_name[:-4])
if exe is None:
# try abspath
exe = which(os.path.abspath(exe_name))
if exe is None:
raise Exception(
f"The program {exe_name} does not exist or is not executable."
)
else:
if not silent:
print(
f"FloPy is using the following executable to run the model: {flopy_io.relpath_safe(exe, model_ws)}"
)
exe_name = resolve_exe_name(model_ws, exe_name, silent)

if namefile is not None:
if not os.path.isfile(os.path.join(model_ws, namefile)):
Expand Down