Skip to content

Commit

Permalink
prevent infinite recursion in removing/adding .exe suffix on windows
Browse files Browse the repository at this point in the history
  • Loading branch information
martclanor committed Dec 27, 2024
1 parent 910ab3b commit 1ea2e19
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions flopy/mbase.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def resolve_exe(exe_name: Union[str, os.PathLike], forgive: bool = False) -> str
str: absolute path to the executable
"""

def _resolve(exe_name):
def _resolve(exe_name, checked=set()):
# Prevent infinite recursion by checking if exe_name has been checked
if exe_name in checked:
return None
checked.add(exe_name)

# exe_name is found (not None), ensure absolute path is returned
if exe := which(exe_name):
return which(Path(exe).resolve())
Expand All @@ -80,10 +85,10 @@ def _resolve(exe_name):
return exe

# try adding/removing .exe suffix
if on_windows and exe_name.lower().endswith(".exe"):
return _resolve(exe_name[:-4])
if exe_name.lower().endswith(".exe"):
return _resolve(exe_name[:-4], checked)
elif on_windows and "." not in Path(exe_name).stem:
return _resolve(f"{exe_name}.exe")
return _resolve(f"{exe_name}.exe", checked)

exe_path = _resolve(exe_name)

Expand Down

0 comments on commit 1ea2e19

Please sign in to comment.