Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions launch/core/platforms/linux.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
BaseRuntime
)

import os, json
import json
import os
import posixpath
from typing import Any, Optional
import queue
import threading
Expand All @@ -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__(
Expand Down Expand Up @@ -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)
Expand Down
20 changes: 20 additions & 0 deletions tests/runtime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

import os
import platform as host_platform
from types import SimpleNamespace
import warnings

import docker
Expand Down Expand Up @@ -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":
Expand Down