Skip to content

Commit fce940b

Browse files
authored
Merge pull request #279 from JdeRobot/python-ros-project-support
Add compilation for python packages
2 parents 85ea0ea + 21e38b4 commit fce940b

5 files changed

Lines changed: 60 additions & 32 deletions

File tree

robotics_application_manager/manager/launcher/launcher_o3de.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from robotics_application_manager import LogManager
1515

1616

17-
1817
class LauncherO3de(ILauncher):
1918
running: bool = False
2019
threads: List[Any] = []

robotics_application_manager/manager/manager.py

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -686,13 +686,13 @@ def on_change_style(self, event):
686686
lxde_conf_dir = os.path.expanduser("~/.config/lxsession/LXDE")
687687
lxde_conf_path = os.path.join(lxde_conf_dir, "desktop.conf")
688688
os.makedirs(lxde_conf_dir, exist_ok=True)
689-
689+
690690
# Read existing or create new
691691
conf_lines = []
692692
if os.path.exists(lxde_conf_path):
693693
with open(lxde_conf_path, "r") as f:
694694
conf_lines = f.readlines()
695-
695+
696696
# Ensure GTK section exists and update theme name
697697
gtk_section_found = False
698698
for i, line in enumerate(conf_lines):
@@ -705,20 +705,23 @@ def on_change_style(self, event):
705705
if not gtk_section_found:
706706
conf_lines.append("[GTK]\\n")
707707
conf_lines.append(f"sNet/ThemeName={gtk_theme}\\n")
708-
708+
709709
with open(lxde_conf_path, "w") as f:
710710
f.writelines(conf_lines)
711711

712712
# Reload window manager (Openbox) and LXPanel
713713
subprocess.run(
714-
["bash", "-c", "export DISPLAY=:1; lxpanelctl restart; openbox --reconfigure"],
714+
[
715+
"bash",
716+
"-c",
717+
"export DISPLAY=:1; lxpanelctl restart; openbox --reconfigure",
718+
],
715719
stdout=subprocess.DEVNULL,
716-
stderr=subprocess.DEVNULL
720+
stderr=subprocess.DEVNULL,
717721
)
718722
except Exception as e:
719723
LogManager.logger.exception(f"Error refreshing GTK applications: {e}")
720724

721-
722725
def on_run_application(self, event):
723726
"""
724727
Handle the 'run_application' event.
@@ -763,7 +766,7 @@ def on_run_application(self, event):
763766

764767
_, file_extension = os.path.splitext(entrypoint)
765768

766-
if file_extension == ".cpp":
769+
if file_extension == ".cpp" or entrypoint.endswith(".launch.py"):
767770
fds = os.listdir("/dev/pts/")
768771
console_fd = str(max(map(int, fds[:-1])))
769772

@@ -780,23 +783,37 @@ def on_run_application(self, event):
780783
executable="/bin/bash",
781784
)
782785
returncode = compile_process.wait()
783-
print(returncode)
784786
if returncode != 0:
785787
raise Exception("Failed to compile")
786788

787789
self.unpause_sim()
788-
self.application_process = subprocess.Popen(
789-
[
790-
"source /workspace/code/install/setup.bash && ros2 run academy academyCode"
791-
],
792-
stdin=open("/dev/pts/" + console_fd, "r"),
793-
stdout=open("/dev/pts/" + console_fd, "w"),
794-
stderr=sys.stdout,
795-
bufsize=1024,
796-
universal_newlines=True,
797-
shell=True,
798-
executable="/bin/bash",
799-
)
790+
if entrypoint.endswith(".launch.py"):
791+
self.application_process = subprocess.Popen(
792+
[
793+
f"source /workspace/code/install/setup.bash && ros2 launch {entrypoint}"
794+
],
795+
stdin=open("/dev/pts/" + console_fd, "r"),
796+
stdout=open("/dev/pts/" + console_fd, "w"),
797+
stderr=sys.stdout,
798+
bufsize=1024,
799+
universal_newlines=True,
800+
shell=True,
801+
executable="/bin/bash",
802+
)
803+
else:
804+
805+
self.application_process = subprocess.Popen(
806+
[
807+
"source /workspace/code/install/setup.bash && ros2 run academy academyCode"
808+
],
809+
stdin=open("/dev/pts/" + console_fd, "r"),
810+
stdout=open("/dev/pts/" + console_fd, "w"),
811+
stderr=sys.stdout,
812+
bufsize=1024,
813+
universal_newlines=True,
814+
shell=True,
815+
executable="/bin/bash",
816+
)
800817
return
801818

802819
# Pass the linter

test/conftest.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,13 @@ def stop(self):
7676
def manager(monkeypatch):
7777
"""Fixture to provide a Manager instance with patched dependencies for testing."""
7878

79-
monkeypatch.setattr("robotics_application_manager.comms.websocket_server.WebsocketServer", DummyServer)
80-
monkeypatch.setattr("robotics_application_manager.manager.manager.ManagerConsumer", DummyConsumer)
79+
monkeypatch.setattr(
80+
"robotics_application_manager.comms.websocket_server.WebsocketServer",
81+
DummyServer,
82+
)
83+
monkeypatch.setattr(
84+
"robotics_application_manager.manager.manager.ManagerConsumer", DummyConsumer
85+
)
8186

8287
# Patch subprocess.check_output for ROS_DISTRO and IMAGE_TAG
8388
def fake_check_output(cmd, *a, **k):
@@ -91,14 +96,16 @@ def fake_check_output(cmd, *a, **k):
9196

9297
# Patch check_gpu_acceleration where it is used
9398
monkeypatch.setattr(
94-
"robotics_application_manager.manager.manager.check_gpu_acceleration", lambda x=None: "OFF"
99+
"robotics_application_manager.manager.manager.check_gpu_acceleration",
100+
lambda x=None: "OFF",
95101
)
96102

97103
def dummy_run(self, start_pose=None):
98104
print("run around")
99105

100106
monkeypatch.setattr(
101-
"robotics_application_manager.manager.launcher.launcher_robot.LauncherRobot.run", dummy_run
107+
"robotics_application_manager.manager.launcher.launcher_robot.LauncherRobot.run",
108+
dummy_run,
102109
)
103110

104111
# Patch os.makedirs and os.path.isdir to avoid real FS operations
@@ -121,7 +128,9 @@ def run(self):
121128
def terminate(self):
122129
pass
123130

124-
monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherWorld", DummyLauncherWorld)
131+
monkeypatch.setattr(
132+
"robotics_application_manager.manager.manager.LauncherWorld", DummyLauncherWorld
133+
)
125134

126135
class DummyFileWatchdog:
127136
def __init__(self, path, update_callback):
@@ -146,7 +155,9 @@ def run(self, consumer):
146155
def terminate(self):
147156
pass
148157

149-
monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher)
158+
monkeypatch.setattr(
159+
"robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher
160+
)
150161
# Deprecated
151162
# monkeypatch.setattr("robotics_application_manager.manager.manager.Server", DummyServer)
152163
# monkeypatch.setattr("robotics_application_manager.manager.manager.FileWatchdog", DummyFileWatchdog)

test/test_terminate_transitions.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,7 @@ def test_terminate_tools_invalid_machine_error(manager, monkeypatch):
105105
106106
Ensure that the transition raises an error when executed from an invalid state.
107107
"""
108-
monkeypatch.setattr(
109-
"robotics_application_manager.libs.server.Server", DummyServer
110-
)
108+
monkeypatch.setattr("robotics_application_manager.libs.server.Server", DummyServer)
111109
# Ensure the manager is in a state where it can stop
112110
setup_manager_to_application_running(manager, monkeypatch)
113111

test/test_utils.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ def run(self, consumer=None):
7070
def terminate(self):
7171
pass
7272

73-
monkeypatch.setattr("robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher)
73+
monkeypatch.setattr(
74+
"robotics_application_manager.manager.manager.LauncherTools", DummyToolsLauncher
75+
)
7476

7577
# Trigger visualization ready state
7678
manager.trigger(
@@ -129,7 +131,8 @@ def fake_open(file, mode="r", *args, **kwargs):
129131
)
130132
monkeypatch.setattr("base64.b64decode", lambda s: b"print('hello')")
131133
monkeypatch.setattr(
132-
"robotics_application_manager.manager.manager.Manager.unpause_sim", lambda self: None
134+
"robotics_application_manager.manager.manager.Manager.unpause_sim",
135+
lambda self: None,
133136
)
134137
# Mock linter to return no errors
135138
manager.linter.evaluate_code = lambda code, ros_version: ""

0 commit comments

Comments
 (0)