Skip to content

Commit 76fbeaf

Browse files
committed
Improve workspace fallback
1 parent c2d895f commit 76fbeaf

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

robot_upstart/job.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,13 +82,18 @@ def __init__(self, name="ros", rmw=None, rmw_config=None, interface=None,
8282
# Fall back on current user as the user to run ROS as.
8383
self.user = user or getpass.getuser()
8484

85-
# Fall back on current workspace setup file if not explicitly specified.
86-
self.workspace_setup = workspace_setup or \
87-
os.environ['CMAKE_PREFIX_PATH'].split(':')[0] + '/../setup.bash'
88-
8985
# Fall back on current distro if not otherwise specified.
9086
self.rosdistro = rosdistro or os.environ['ROS_DISTRO']
9187

88+
# Prioritize specified workspace, falling back to current workspace if possible, or
89+
# system workspace as a last-resort
90+
if workspace_setup:
91+
self.workspace_setup = workspace_setup
92+
elif 'CMAKE_PREFIX_PATH' in os.environ.keys():
93+
self.workspace_setup = os.environ['CMAKE_PREFIX_PATH'].split(':')[0] + '/../setup.bash'
94+
else:
95+
self.workspace_setup = f'/opt/ros/{self.rosdistro}/setup.bash'
96+
9297
self.rmw = rmw or "rmw_fastrtps_cpp"
9398

9499
self.rmw_config = rmw_config or ""

0 commit comments

Comments
 (0)