diff --git a/launch/core/platforms/linux.py b/launch/core/platforms/linux.py index bd87786..9706370 100644 --- a/launch/core/platforms/linux.py +++ b/launch/core/platforms/linux.py @@ -16,7 +16,9 @@ BaseRuntime ) -import os, json +import json +import os +import posixpath from typing import Any, Optional import queue import threading @@ -26,6 +28,12 @@ import docker from docker.models.containers import Container + +def _container_mount_path(mount_path: str, filename: str) -> str: + """Build a path for a Linux container regardless of the host platform.""" + return posixpath.join(mount_path, filename) + + class LinuxRuntime(BaseRuntime): def __init__( @@ -207,7 +215,7 @@ def apply_patch(self, patch: str, verbose: bool = False) -> bool: hostpath = os.path.join(self.mnt_host, filename) with open(hostpath, "w") as f: f.write(patch) - containerpath = os.path.join(self.mnt_container, filename) + containerpath = _container_mount_path(self.mnt_container, filename) cmd = f"""git apply --reject --whitespace=nowarn {containerpath} """ res = self.send_command(cmd) diff --git a/tests/runtime_test.py b/tests/runtime_test.py index 809ec3d..f291e54 100644 --- a/tests/runtime_test.py +++ b/tests/runtime_test.py @@ -41,6 +41,7 @@ import os import platform as host_platform +from types import SimpleNamespace import warnings import docker @@ -170,6 +171,25 @@ def test_runtime_constructor_attributes(runtime_cls, expected_attrs, patch_runti +def test_linux_runtime_uses_posix_path_for_mounted_patch(monkeypatch, tmp_path): + runtime = LinuxRuntime.__new__(LinuxRuntime) + runtime.stopped = True + runtime.mnt_host = str(tmp_path) + runtime.mnt_container = "/mnt_tmp" + commands = [] + + def send_command(command, timeout=None): + commands.append(command) + return SimpleNamespace(metadata=SimpleNamespace(exit_code=0), output="") + + monkeypatch.setattr(runtime, "send_command", send_command) + assert runtime.apply_patch("diff --git a/a b/a\n") is True + assert commands[0].startswith("git apply") + assert "/mnt_tmp/" in commands[0] + assert "\\" not in commands[0] + assert commands[1].startswith("rm /mnt_tmp/") + + def supported_integration_platforms() -> set[str]: system = host_platform.system().lower() if system == "windows":