mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-12-02 23:10:25 +01:00
output: serialize 3.x hash name in 'hash' field
This commit is contained in:
committed by
Ruslan Kuprieiev
parent
603f5fdba1
commit
2cd33e10ac
@@ -51,6 +51,7 @@ def test_add(tmp_dir, dvc):
|
||||
"md5": "acbd18db4cc2f85cedef654fccc4a4d8",
|
||||
"path": "foo",
|
||||
"size": 3,
|
||||
"hash": "md5",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -70,6 +71,7 @@ def test_add_executable(tmp_dir, dvc):
|
||||
"path": "foo",
|
||||
"size": 3,
|
||||
"isexec": True,
|
||||
"hash": "md5",
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -258,6 +260,7 @@ def test_add_external_relpath(tmp_dir, dvc, local_cloud):
|
||||
"outs:\n"
|
||||
"- md5: 8c7dd922ad47494fc02c388e12c00eac\n"
|
||||
" size: 4\n"
|
||||
" hash: md5\n"
|
||||
f" path: {rel}\n"
|
||||
)
|
||||
assert fpath.read_text() == "file"
|
||||
|
||||
@@ -329,8 +329,8 @@ def test_checkout_moved_cache_dir_with_symlinks(tmp_dir, dvc):
|
||||
assert system.is_symlink(os.path.join("data", "file"))
|
||||
old_data_link = os.path.realpath(os.path.join("data", "file"))
|
||||
|
||||
old_cache_dir = dvc.cache.local.path
|
||||
new_cache_dir = old_cache_dir + "_new"
|
||||
old_cache_dir = str(tmp_dir / ".dvc" / "cache")
|
||||
new_cache_dir = str(tmp_dir / ".dvc" / "cache_new")
|
||||
os.rename(old_cache_dir, new_cache_dir)
|
||||
|
||||
ret = main(["cache", "dir", new_cache_dir])
|
||||
@@ -801,6 +801,7 @@ def test_checkout_dir_compat(tmp_dir, dvc):
|
||||
f"""\
|
||||
outs:
|
||||
- md5: {stage.outs[0].hash_info.value}
|
||||
hash: md5
|
||||
path: data
|
||||
"""
|
||||
),
|
||||
|
||||
@@ -56,6 +56,7 @@ def test_commit_preserve_fields(tmp_dir, dvc):
|
||||
key1: value1
|
||||
key2: value2
|
||||
remote: testremote
|
||||
hash: md5
|
||||
meta: some metadata
|
||||
"""
|
||||
)
|
||||
@@ -77,6 +78,7 @@ def test_commit_preserve_fields(tmp_dir, dvc):
|
||||
key1: value1
|
||||
key2: value2
|
||||
remote: testremote
|
||||
hash: md5
|
||||
md5: acbd18db4cc2f85cedef654fccc4a4d8
|
||||
size: 3
|
||||
meta: some metadata
|
||||
@@ -129,7 +131,10 @@ def test_commit_no_exec(tmp_dir, dvc):
|
||||
def test_commit_granular_output(tmp_dir, dvc):
|
||||
dvc.run(
|
||||
name="mystage",
|
||||
cmd=["echo foo>foo", "echo bar>bar"],
|
||||
cmd=[
|
||||
"python -c \"open('foo', 'wb').write(b'foo\\n')\"",
|
||||
"python -c \"open('bar', 'wb').write(b'bar\\n')\"",
|
||||
],
|
||||
outs=["foo", "bar"],
|
||||
no_commit=True,
|
||||
)
|
||||
@@ -248,6 +253,7 @@ def test_commit_updates_to_cloud_versioning_dir(tmp_dir, dvc):
|
||||
"outs": [
|
||||
{
|
||||
"path": "data",
|
||||
"hash": "md5",
|
||||
"files": [
|
||||
{
|
||||
"size": 3,
|
||||
@@ -280,6 +286,7 @@ def test_commit_updates_to_cloud_versioning_dir(tmp_dir, dvc):
|
||||
"outs": [
|
||||
{
|
||||
"path": "data",
|
||||
"hash": "md5",
|
||||
"files": [
|
||||
{
|
||||
"size": 4,
|
||||
@@ -297,3 +304,21 @@ def test_commit_updates_to_cloud_versioning_dir(tmp_dir, dvc):
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
def test_commit_dos2unix(tmp_dir, dvc):
|
||||
tmp_dir.gen("foo", "foo")
|
||||
(tmp_dir / "foo.dvc").dump(
|
||||
{
|
||||
"outs": [
|
||||
{"path": "foo", "md5": "acbd18db4cc2f85cedef654fccc4a4d8", "size": 3},
|
||||
]
|
||||
}
|
||||
)
|
||||
legacy_content = (tmp_dir / "foo.dvc").read_text()
|
||||
|
||||
dvc.commit("foo.dvc")
|
||||
assert (tmp_dir / "foo.dvc").read_text() == legacy_content
|
||||
dvc.commit("foo.dvc", force=True)
|
||||
content = (tmp_dir / "foo.dvc").read_text()
|
||||
assert "hash: md5" in content
|
||||
|
||||
@@ -402,3 +402,15 @@ def test_dvcfile_load_with_plots(tmp_dir, dvc):
|
||||
assert all(
|
||||
name in top_level_plots for name in ("path/to/plot", "path/to/another/plot")
|
||||
)
|
||||
|
||||
|
||||
def test_dvcfile_dos2unix(tmp_dir, dvc):
|
||||
from dvc_data.hashfile.hash import HashInfo
|
||||
|
||||
(tmp_dir / "foo.dvc").dump({"outs": [{"md5": "abc123", "size": 3, "path": "foo"}]})
|
||||
orig_content = (tmp_dir / "foo.dvc").read_text()
|
||||
stage = dvc.stage.load_one("foo.dvc")
|
||||
assert stage.outs[0].hash_name == "md5-dos2unix"
|
||||
assert stage.outs[0].hash_info == HashInfo("md5-dos2unix", "abc123")
|
||||
stage.dump()
|
||||
assert (tmp_dir / "foo.dvc").read_text() == orig_content
|
||||
|
||||
@@ -214,10 +214,20 @@ def test_subrepos_are_ignored(tmp_dir, erepo_dir):
|
||||
shallow=False,
|
||||
hardlink=True,
|
||||
)
|
||||
if os.name == "nt":
|
||||
expected_gitignore_path = (
|
||||
cache_dir / "d5" / "61e684092f0ff908aa82ee9cc1e594"
|
||||
)
|
||||
expected_dir_path = cache_dir / "0d" / "2086760aea091f1504eafc8843bb18.dir"
|
||||
else:
|
||||
expected_gitignore_path = (
|
||||
cache_dir / "94" / "7d2b84e5aa88170e80dff467a5bfb6"
|
||||
)
|
||||
expected_dir_path = cache_dir / "e1" / "d9e8eae5374860ae025ec84cfd85c7.dir"
|
||||
assert set(cache_dir.glob("??/*")) == {
|
||||
cache_dir / "e1" / "d9e8eae5374860ae025ec84cfd85c7.dir",
|
||||
expected_dir_path,
|
||||
expected_gitignore_path,
|
||||
cache_dir / "37" / "b51d194a7513e45b56f6524f2d51f2",
|
||||
cache_dir / "94" / "7d2b84e5aa88170e80dff467a5bfb6",
|
||||
cache_dir / "ac" / "bd18db4cc2f85cedef654fccc4a4d8",
|
||||
}
|
||||
|
||||
|
||||
@@ -428,6 +428,7 @@ def test_gc_not_in_remote_with_remote_field(
|
||||
outs:
|
||||
- path: foo
|
||||
remote: other_remote
|
||||
hash: md5
|
||||
"""
|
||||
)
|
||||
tmp_dir.gen("foo.dvc", text)
|
||||
@@ -459,6 +460,7 @@ def test_gc_cloud_remote_field(tmp_dir, scm, dvc, tmp_path_factory, mocker):
|
||||
outs:
|
||||
- path: foo
|
||||
remote: other_remote
|
||||
hash: md5
|
||||
"""
|
||||
)
|
||||
tmp_dir.gen("foo.dvc", text)
|
||||
|
||||
@@ -247,7 +247,11 @@ def test_pull_import_no_download(tmp_dir, scm, dvc, erepo_dir):
|
||||
|
||||
stage = load_file(dvc, "foo_imported.dvc").stage
|
||||
|
||||
assert stage.outs[0].hash_info.value == "bdb8641831d8fcb03939637e09011c21.dir"
|
||||
if os.name == "nt":
|
||||
expected_hash = "2e798234df5f782340ac3ce046f8dfae.dir"
|
||||
else:
|
||||
expected_hash = "bdb8641831d8fcb03939637e09011c21.dir"
|
||||
assert stage.outs[0].hash_info.value == expected_hash
|
||||
|
||||
assert stage.outs[0].meta.size == size
|
||||
assert stage.outs[0].meta.nfiles == 3
|
||||
|
||||
@@ -108,7 +108,7 @@ def test_import_url_with_no_exec(tmp_dir, dvc, erepo_dir):
|
||||
class TestImport(_TestImport):
|
||||
@pytest.fixture
|
||||
def stage_md5(self):
|
||||
return "dc24e1271084ee317ac3c2656fb8812b"
|
||||
return "7033ee831f78a4dfec2fc71405516067"
|
||||
|
||||
@pytest.fixture
|
||||
def dir_md5(self):
|
||||
@@ -150,6 +150,7 @@ def test_import_url_preserve_fields(tmp_dir, dvc):
|
||||
- path: foo # dep comment
|
||||
md5: acbd18db4cc2f85cedef654fccc4a4d8
|
||||
size: 3
|
||||
hash: md5
|
||||
outs:
|
||||
- path: bar # out comment
|
||||
desc: out desc
|
||||
@@ -161,8 +162,9 @@ def test_import_url_preserve_fields(tmp_dir, dvc):
|
||||
key: value
|
||||
md5: acbd18db4cc2f85cedef654fccc4a4d8
|
||||
size: 3
|
||||
hash: md5
|
||||
meta: some metadata
|
||||
md5: be7ade0aa89cc8d56e320867a9de9740
|
||||
md5: 8fc199641730e3f512deac0bd9a0e0b6
|
||||
frozen: true
|
||||
"""
|
||||
)
|
||||
|
||||
@@ -118,6 +118,7 @@ def test_merge_driver_no_ancestor(tmp_dir, scm, dvc):
|
||||
"- md5: 5ea40360f5b4ec688df672a4db9c17d1.dir\n"
|
||||
" size: 6\n"
|
||||
" nfiles: 2\n"
|
||||
" hash: md5\n"
|
||||
" path: data\n"
|
||||
)
|
||||
|
||||
@@ -153,6 +154,7 @@ def test_merge_driver(tmp_dir, scm, dvc):
|
||||
"- md5: 839ef9371606817569c1ee0e5f4ed233.dir\n"
|
||||
" size: 12\n"
|
||||
" nfiles: 3\n"
|
||||
" hash: md5\n"
|
||||
" path: data\n"
|
||||
)
|
||||
|
||||
|
||||
@@ -43,8 +43,12 @@ def test_deps_outs_are_sorted_by_path(tmp_dir, dvc, run_head):
|
||||
assert list(lock.keys()) == ["cmd", "deps", "outs"]
|
||||
|
||||
# `path` key appear first and then the `md5`
|
||||
assert all(list(dep.keys()) == ["path", "md5", "size"] for dep in lock["deps"])
|
||||
assert all(list(out.keys()) == ["path", "md5", "size"] for out in lock["outs"])
|
||||
assert all(
|
||||
list(dep.keys()) == ["path", "hash", "md5", "size"] for dep in lock["deps"]
|
||||
)
|
||||
assert all(
|
||||
list(out.keys()) == ["path", "hash", "md5", "size"] for out in lock["outs"]
|
||||
)
|
||||
|
||||
# deps are always sorted by the file path naming
|
||||
assert list(map(itemgetter("path"), lock["deps"])) == sorted(deps)
|
||||
|
||||
@@ -127,10 +127,16 @@ def test_merge_conflict(tmp_dir, dvc, ancestor, our, their, error, caplog):
|
||||
def test_merge_different_output_options(tmp_dir, dvc, caplog):
|
||||
(tmp_dir / "ancestor").touch()
|
||||
|
||||
(tmp_dir / "our").write_text("outs:\n- md5: f123456789.dir\n path: path\n")
|
||||
(tmp_dir / "our").write_text(
|
||||
"outs:\n- md5: f123456789.dir\n hash: md5\n path: path\n"
|
||||
)
|
||||
|
||||
(tmp_dir / "their").write_text(
|
||||
"outs:\n- md5: f987654321.dir\n path: path\n cache: false\n"
|
||||
"outs:\n"
|
||||
"- md5: f987654321.dir\n"
|
||||
" hash: md5\n"
|
||||
" path: path\n"
|
||||
" cache: false\n"
|
||||
)
|
||||
|
||||
assert (
|
||||
@@ -156,9 +162,13 @@ def test_merge_different_output_options(tmp_dir, dvc, caplog):
|
||||
def test_merge_file(tmp_dir, dvc, caplog):
|
||||
(tmp_dir / "ancestor").touch()
|
||||
|
||||
(tmp_dir / "our").write_text("outs:\n- md5: f123456789.dir\n path: path\n")
|
||||
(tmp_dir / "our").write_text(
|
||||
"outs:\n- md5: f123456789.dir\n hash: md5\n path: path\n"
|
||||
)
|
||||
|
||||
(tmp_dir / "their").write_text("outs:\n- md5: f987654321\n path: path\n")
|
||||
(tmp_dir / "their").write_text(
|
||||
"outs:\n- md5: f987654321\n hash: md5\n path: path\n"
|
||||
)
|
||||
|
||||
assert (
|
||||
main(
|
||||
@@ -186,12 +196,16 @@ def test_merge_non_dvc_add(tmp_dir, dvc, caplog):
|
||||
(tmp_dir / "our").write_text(
|
||||
"outs:\n"
|
||||
"- md5: f123456789.dir\n"
|
||||
" hash: md5\n"
|
||||
" path: path\n"
|
||||
"- md5: ff123456789.dir\n"
|
||||
" hash: md5\n"
|
||||
" path: another\n"
|
||||
)
|
||||
|
||||
(tmp_dir / "their").write_text("outs:\n- md5: f987654321\n path: path\n")
|
||||
(tmp_dir / "their").write_text(
|
||||
"outs:\n- md5: f987654321\n hash: md5\n path: path\n"
|
||||
)
|
||||
|
||||
assert (
|
||||
main(
|
||||
|
||||
@@ -194,6 +194,7 @@ def test_move_meta(tmp_dir, dvc):
|
||||
outs:
|
||||
- md5: acbd18db4cc2f85cedef654fccc4a4d8
|
||||
size: 3
|
||||
hash: md5
|
||||
path: bar
|
||||
meta:
|
||||
custom_key: 42
|
||||
|
||||
@@ -562,10 +562,12 @@ def test_run_external_outputs(
|
||||
" cmd: mycmd\n"
|
||||
" deps:\n"
|
||||
" - path: remote://workspace/foo\n"
|
||||
" hash: md5\n"
|
||||
f" {hash_name}: {foo_hash}\n"
|
||||
" size: 3\n"
|
||||
" outs:\n"
|
||||
" - path: remote://workspace/bar\n"
|
||||
" hash: md5\n"
|
||||
f" {hash_name}: {bar_hash}\n"
|
||||
" size: 3\n"
|
||||
)
|
||||
|
||||
@@ -139,6 +139,7 @@ def test_md5_ignores_annotations(tmp_dir, dvc):
|
||||
{
|
||||
"md5": "d3b07384d113edec49eaa6238ad5ff00",
|
||||
"size": 4,
|
||||
"hash": "md5",
|
||||
"path": "foo",
|
||||
"desc": "foo desc",
|
||||
"type": "mytype",
|
||||
@@ -149,10 +150,20 @@ def test_md5_ignores_annotations(tmp_dir, dvc):
|
||||
}
|
||||
(tmp_dir / "foo.dvc").dump(data)
|
||||
stage = dvc.stage.load_one("foo.dvc")
|
||||
assert compute_md5(stage) == "1822617147b53ae6f9eb4b3c87c0b6f3"
|
||||
assert compute_md5(stage) == "cde267b60ef5a00e9a35cc1999ab83a3"
|
||||
assert (
|
||||
dict_md5({"outs": [{"md5": "d3b07384d113edec49eaa6238ad5ff00", "path": "foo"}]})
|
||||
== "1822617147b53ae6f9eb4b3c87c0b6f3"
|
||||
dict_md5(
|
||||
{
|
||||
"outs": [
|
||||
{
|
||||
"md5": "d3b07384d113edec49eaa6238ad5ff00",
|
||||
"hash": "md5",
|
||||
"path": "foo",
|
||||
}
|
||||
]
|
||||
}
|
||||
)
|
||||
== "cde267b60ef5a00e9a35cc1999ab83a3"
|
||||
)
|
||||
|
||||
|
||||
@@ -164,6 +175,7 @@ def test_meta_desc_is_preserved(tmp_dir, dvc):
|
||||
{
|
||||
"md5": "d3b07384d113edec49eaa6238ad5ff00",
|
||||
"size": 4,
|
||||
"hash": "md5",
|
||||
"path": "foo",
|
||||
"desc": "foo desc",
|
||||
"type": "mytype",
|
||||
|
||||
Reference in New Issue
Block a user