Skip to content
Merged
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: 5 additions & 7 deletions src/experimaestro/scheduler/remote/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1533,21 +1533,19 @@ def is_remote(self) -> bool:
"""This is a remote provider"""
return True

def get_display_path(self, job: "BaseJob") -> str:
"""Get the remote path to display/copy for a job

Translates the local cache path back to the remote path.
def translate_path(self, path: "Path") -> str:
"""Translate the local cache path back to the remote path.

Args:
job: Job to get display path for
path: Local path to translate

Returns:
Remote path string
"""
if not job.path:
if not path:
return ""

path_str = str(job.path)
path_str = str(path)
local_cache_str = str(self.local_cache_dir)

# If path is in local cache, translate back to remote path
Expand Down
13 changes: 12 additions & 1 deletion src/experimaestro/scheduler/state_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,17 @@ def is_remote(self) -> bool:
"""
return False

def translate_path(self, path: Path) -> str:
"""Translate a local path to a display path (e.g. remote path)

Args:
path: Local path to translate

Returns:
Path string suitable for display and copying
"""
return str(path)

def get_display_path(self, job: BaseJob) -> str:
"""Get the path to display/copy for a job

Expand All @@ -611,7 +622,7 @@ def get_display_path(self, job: BaseJob) -> str:
Returns:
Path string suitable for display and copying
"""
return str(job.path) if job.path else ""
return self.translate_path(job.path) if job.path else ""


# =============================================================================
Expand Down
62 changes: 62 additions & 0 deletions src/experimaestro/tests/test_path_translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@

from pathlib import Path
from experimaestro.scheduler.state_provider import StateProvider
from experimaestro.scheduler.remote.client import SSHStateProviderClient
from experimaestro.scheduler.interfaces import BaseJob, BaseExperiment

class MockJob(BaseJob):
def __init__(self, path):
self.path = path

class MockExperiment(BaseExperiment):
def __init__(self, workdir):
self.workdir = workdir

class MockStateProvider(StateProvider):
def clean_job(self, *args, **kwargs): pass
def close(self, *args, **kwargs): pass
def get_all_jobs(self, *args, **kwargs): return []
def get_current_run(self, *args, **kwargs): return None
def get_dependencies_map(self, *args, **kwargs): return {}
def get_experiment(self, *args, **kwargs): return None
def get_experiment_job_info(self, *args, **kwargs): return None
def get_experiment_runs(self, *args, **kwargs): return []
def get_experiments(self, *args, **kwargs): return []
def get_job(self, *args, **kwargs): return None
def get_jobs(self, *args, **kwargs): return []
def get_services(self, *args, **kwargs): return []
def get_tags_map(self, *args, **kwargs): return {}
def kill_job(self, *args, **kwargs): pass

def test_state_provider_translate_path():
provider = MockStateProvider()
path = Path("/some/local/path")
assert provider.translate_path(path) == str(path)

job = MockJob(path)
assert provider.get_display_path(job) == str(path)

def test_ssh_state_provider_client_translate_path():
client = SSHStateProviderClient(
host="remote-host",
remote_workspace="/remote/workspace"
)
# Set local_cache_dir which is normally set during connect/init
client.local_cache_dir = Path("/tmp/local/cache")

# Path in local cache should be translated
local_path = Path("/tmp/local/cache/experiments/exp1/run1")
expected_remote = "/remote/workspace/experiments/exp1/run1"
assert client.translate_path(local_path) == expected_remote

# Path NOT in local cache should be returned as-is
other_path = Path("/some/other/path")
assert client.translate_path(other_path) == str(other_path)

# Test get_display_path (which now uses translate_path)
job = MockJob(local_path)
assert client.get_display_path(job) == expected_remote

# Test for experiments (direct use of translate_path as in experiments.py)
exp = MockExperiment(local_path)
assert client.translate_path(exp.workdir) == expected_remote
2 changes: 1 addition & 1 deletion src/experimaestro/tui/widgets/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def action_copy_path(self) -> None:
None,
)
if exp_info and exp_info.workdir:
path_str = str(exp_info.workdir)
path_str = self.state_provider.translate_path(exp_info.workdir)
if copy(path_str):
self.notify(f"Path copied: {path_str}", severity="information")
else:
Expand Down
Loading