Skip to content

Commit 80f048e

Browse files
committed
Rework run_simulator to use a unified list of search paths
Expand locations searched on Windows
1 parent a49149a commit 80f048e

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

scripts/run_simulator.py

+20-28
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
55
Largely just a shortcut to running the arena world in Webots.
66
"""
7+
# ruff: noqa: E501
78
from __future__ import annotations
89

910
import sys
@@ -24,6 +25,17 @@
2425
# Assume the script is in the scripts directory
2526
SIM_BASE = Path(__file__).parents[1]
2627

28+
POSSIBLE_WEBOTS_PATHS = [
29+
("darwin", "/Applications/Webots.app/Contents/MacOS/webots"),
30+
("win32", "C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"),
31+
("win32", expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe")),
32+
# Attempt to use the start menu shortcut
33+
("win32", expandvars("%ProgramData%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")),
34+
("win32", expandvars("%APPDATA%\\Microsoft\\Windows\\Start Menu\\Programs\\Cyberbotics\\Webots.lnk")),
35+
("linux", "/usr/local/bin/webots"),
36+
("linux", "/usr/bin/webots"),
37+
]
38+
2739

2840
def get_webots_parameters() -> tuple[Path, Path]:
2941
"""
@@ -36,46 +48,26 @@ def get_webots_parameters() -> tuple[Path, Path]:
3648
if not world_file.exists():
3749
raise RuntimeError("World file not found.")
3850

51+
if not (SIM_BASE / "venv").exists():
52+
print("Please run the setup.py script before running the simulator.")
53+
raise RuntimeError
54+
3955
# Check if Webots is in the PATH
4056
webots = which("webots")
4157

4258
# Find the webots executable, if it is not in the PATH
4359
if webots is None:
44-
if sys.platform == "darwin":
45-
webots = "/Applications/Webots.app/Contents/MacOS/webots"
46-
elif sys.platform == "win32":
47-
possible_paths = [
48-
"C:\\Program Files\\Webots\\msys64\\mingw64\\bin\\webotsw.exe",
49-
expandvars("%LOCALAPPDATA%\\Programs\\Webots\\msys64\\mingw64\\bin\\webotsw.exe"),
50-
]
51-
for path in possible_paths:
60+
for system_filter, path in POSSIBLE_WEBOTS_PATHS:
61+
if sys.platform.startswith(system_filter):
62+
print(f"Checking {path}")
5263
if Path(path).exists():
5364
webots = path
5465
break
55-
else:
56-
print("Webots executable not found.")
57-
raise RuntimeError
58-
elif sys.platform.startswith("linux"):
59-
possible_paths = ["/usr/local/bin/webots", "/usr/bin/webots"]
60-
for path in possible_paths:
61-
if Path(path).exists():
62-
webots = path
63-
break
64-
else:
65-
print("Webots executable not found.")
66-
raise RuntimeError
67-
else:
68-
print("Unsupported platform.")
69-
raise RuntimeError
7066

71-
if not Path(webots).exists():
67+
if webots is None or not Path(webots).exists():
7268
print("Webots executable not found.")
7369
raise RuntimeError
7470

75-
if not (SIM_BASE / "venv").exists():
76-
print("Please run the setup.py script before running the simulator.")
77-
raise RuntimeError
78-
7971
return Path(webots), world_file
8072

8173

0 commit comments

Comments
 (0)