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 ba9a028
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 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 @@ -81,9 +86,9 @@ def _resolve(exe_name):

# try adding/removing .exe suffix
if on_windows and exe_name.lower().endswith(".exe"):
return _resolve(exe_name[:-4])
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 ba9a028

Please sign in to comment.