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
10 changes: 8 additions & 2 deletions dvc/repo/experiments/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,18 @@ def from_repo(

params = _gather_params(repo, deps_only=param_deps, on_error="return")
metrics = _gather_metrics(repo, on_error="return")

def _get_path(item) -> str:
if item.is_in_repo:
return relpath(item.fs_path, repo.root_dir)
return item.fs.unstrip_protocol(item.fs_path)

return cls(
rev=rev,
params=params,
metrics=metrics,
deps={
relpath(dep.fs_path, repo.root_dir): ExpDep(
_get_path(dep): ExpDep(
hash=dep.hash_info.value if dep.hash_info else None,
size=dep.meta.size if dep.meta else None,
nfiles=dep.meta.nfiles if dep.meta else None,
Expand All @@ -79,7 +85,7 @@ def from_repo(
)
},
outs={
relpath(out.fs_path, repo.root_dir): ExpOut(
_get_path(out): ExpOut(
hash=out.hash_info.value if out.hash_info else None,
size=out.meta.size if out.meta else None,
nfiles=out.meta.nfiles if out.meta else None,
Expand Down
25 changes: 25 additions & 0 deletions tests/unit/repo/experiments/test_serialize.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from dvc.repo.experiments.serialize import SerializableExp


def test_serialize_external_paths_include_protocol(dvc, mocker):
"""External paths should include protocol prefix (e.g. s3://)."""
mock_dep = mocker.MagicMock(fs_path="bucket/data.csv", is_in_repo=False)
mock_dep.fs.unstrip_protocol.return_value = "s3://bucket/data.csv"

mock_out = mocker.MagicMock(
fs_path="bucket/model.pkl", is_in_repo=False, is_metric=False, is_plot=False
)
mock_out.fs.unstrip_protocol.return_value = "s3://bucket/model.pkl"

mocker.patch.object(
type(dvc.index), "deps", mocker.PropertyMock(return_value=[mock_dep])
)
mocker.patch.object(
type(dvc.index), "outs", mocker.PropertyMock(return_value=[mock_out])
)
mocker.patch.object(dvc, "get_rev", return_value="abc123")

result = SerializableExp.from_repo(dvc)

assert "s3://bucket/data.csv" in result.deps
assert "s3://bucket/model.pkl" in result.outs