Skip to content

Commit

Permalink
index: mark remote as read_only for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
efiop committed Dec 28, 2023
1 parent 73820cc commit f2e4794
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion dvc/repo/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def _load_storage_from_out(storage_map, key, out):
),
)
)
storage_map.add_remote(FileStorage(key, dep.fs, dep.fs_path))
storage_map.add_remote(FileStorage(key, dep.fs, dep.fs_path, read_only=True))


class Index:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies = [
"configobj>=5.0.6",
"distro>=1.3",
"dpath<3,>=2.1.0",
"dvc-data>=3.4,<3.5",
"dvc-data>=3.5,<3.6",
"dvc-http>=2.29.0",
"dvc-render>=1.0.0,<2",
"dvc-studio-client>=0.17.1,<1",
Expand Down
51 changes: 51 additions & 0 deletions tests/func/test_repo_index.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from itertools import chain

import pytest
Expand Down Expand Up @@ -338,3 +339,53 @@ def test_param_keys_top_level_params(tmp_dir, dvc):
tmp_dir.gen("dvc.yaml", top_level_params)
index = Index.from_repo(dvc)
assert index.param_keys == {"repo": {("classifier", "custom_params_file.yaml")}}


def test_data_index(tmp_dir, dvc, local_cloud, erepo_dir):
tmp_dir.dvc_gen(
{
"foo": b"foo",
"dir": {"bar": b"bar", "subdir": {"baz": b"baz"}},
}
)

with erepo_dir.chdir():
erepo_dir.dvc_gen("efoo", b"efoo", commit="create efoo")
erepo_dir.dvc_gen(
"edir",
{"ebar": b"ebar", "esubdir": {"ebaz": b"ebaz"}},
commit="create edir",
)

dvc.imp(os.fspath(erepo_dir), "efoo")
dvc.imp(os.fspath(erepo_dir), "edir")

local_cloud.gen("ifoo", b"ifoo")
local_cloud.gen("idir", {"ibar": b"ibar", "isubdir": {"ibaz": b"ibaz"}})

dvc.imp_url(str(local_cloud / "ifoo"))
dvc.imp_url(str(local_cloud / "idir"))

index = Index.from_repo(dvc)
assert index.data_keys == {
"local": set(),
"repo": {("dir",), ("edir",), ("efoo",), ("foo",), ("idir",), ("ifoo",)},
}

data = index.data["repo"]
assert set(data.keys()) == {
("dir",),
("edir",),
("efoo",),
("foo",),
("idir",),
("ifoo",),
}

assert not data.storage_map[("foo",)].remote
assert not data.storage_map[("dir",)].remote

assert data.storage_map[("efoo",)].remote.read_only
assert data.storage_map[("edir",)].remote.read_only
assert data.storage_map[("ifoo",)].remote.read_only
assert data.storage_map[("idir",)].remote.read_only

0 comments on commit f2e4794

Please sign in to comment.