4
4
5
5
Largely just a shortcut to running the arena world in Webots.
6
6
"""
7
+ # ruff: noqa: E501
7
8
from __future__ import annotations
8
9
9
10
import sys
24
25
# Assume the script is in the scripts directory
25
26
SIM_BASE = Path (__file__ ).parents [1 ]
26
27
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
+
27
39
28
40
def get_webots_parameters () -> tuple [Path , Path ]:
29
41
"""
@@ -36,46 +48,26 @@ def get_webots_parameters() -> tuple[Path, Path]:
36
48
if not world_file .exists ():
37
49
raise RuntimeError ("World file not found." )
38
50
51
+ if not (SIM_BASE / "venv" ).exists ():
52
+ print ("Please run the setup.py script before running the simulator." )
53
+ raise RuntimeError
54
+
39
55
# Check if Webots is in the PATH
40
56
webots = which ("webots" )
41
57
42
58
# Find the webots executable, if it is not in the PATH
43
59
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 } " )
52
63
if Path (path ).exists ():
53
64
webots = path
54
65
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
70
66
71
- if not Path (webots ).exists ():
67
+ if webots is None or not Path (webots ).exists ():
72
68
print ("Webots executable not found." )
73
69
raise RuntimeError
74
70
75
- if not (SIM_BASE / "venv" ).exists ():
76
- print ("Please run the setup.py script before running the simulator." )
77
- raise RuntimeError
78
-
79
71
return Path (webots ), world_file
80
72
81
73
0 commit comments