Skip to content

Commit 718c9c9

Browse files
authored
serialization: dont rely on the default hash type (#4466)
Prerequisite for #4144 and #3069
1 parent fcca636 commit 718c9c9

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

dvc/output/base.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -172,18 +172,10 @@ def supported(cls, url):
172172
def cache_path(self):
173173
return self.cache.tree.hash_to_path_info(self.checksum).url
174174

175-
@property
176-
def checksum_type(self):
177-
return self.tree.PARAM_CHECKSUM
178-
179175
@property
180176
def checksum(self):
181177
return self.info.get(self.tree.PARAM_CHECKSUM)
182178

183-
@checksum.setter
184-
def checksum(self, checksum):
185-
self.info[self.tree.PARAM_CHECKSUM] = checksum
186-
187179
def get_checksum(self):
188180
return self.tree.get_hash(self.path_info)[1]
189181

dvc/stage/loader.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ def fill_from_lock(stage, lock_data=None):
4242
if isinstance(item, dependency.ParamsDependency):
4343
item.fill_values(get_in(lock_data, [stage.PARAM_PARAMS, path]))
4444
continue
45-
item.checksum = get_in(checksums, [key, path, item.checksum_type])
45+
item.info = get_in(checksums, [key, path], {})
46+
item.info = item.info.copy()
47+
item.info.pop("path", None)
4648

4749
@classmethod
4850
def load_stage(cls, dvcfile, name, stage_data, lock_data=None):

dvc/stage/serialize.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ def to_single_stage_lockfile(stage: "Stage") -> dict:
138138
params, deps = split_params_deps(stage)
139139
deps, outs = [
140140
[
141-
OrderedDict(
142-
[
143-
(PARAM_PATH, item.def_path),
144-
(item.checksum_type, item.checksum),
145-
]
146-
)
141+
OrderedDict([(PARAM_PATH, item.def_path), *item.info.items()])
147142
for item in sort_by_path(items)
148143
]
149144
for items in [deps, stage.outs]

tests/func/test_run_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ def test_uncached_outs_are_cached(tmp_dir, dvc, run_copy):
7676
name="copy-foo-bar",
7777
)
7878
with dvc.state:
79-
stage.outs[0].checksum = stage.outs[0].get_checksum()
79+
stage.outs[0].info = stage.outs[0].save_info()
8080
assert os.path.exists(relpath(stage.outs[0].cache_path))
8181

8282

tests/unit/stage/test_serialize_pipeline_lock.py

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,31 @@ def test_lock_outs_order(dvc, typ):
144144
)
145145

146146

147-
def test_dump_appropriate_checksums(dvc):
147+
def test_dump_nondefault_hash(dvc):
148148
stage = create_stage(
149149
PipelineStage, dvc, deps=["s3://dvc-temp/file"], **kwargs
150150
)
151-
stage.deps[0].info = {"etag": "is-it-etag", "md5": "or-md5?"}
151+
stage.deps[0].info = {"md5": "value"}
152+
assert to_single_stage_lockfile(stage) == OrderedDict(
153+
[
154+
("cmd", "command"),
155+
(
156+
"deps",
157+
[
158+
OrderedDict(
159+
[("path", "s3://dvc-temp/file"), ("md5", "value")]
160+
)
161+
],
162+
),
163+
]
164+
)
165+
166+
167+
def test_dump_multiple_hashes(dvc):
168+
stage = create_stage(
169+
PipelineStage, dvc, deps=["s3://dvc-temp/file"], **kwargs
170+
)
171+
stage.deps[0].info = {"etag": "etag-value", "md5": "md5-value"}
152172
assert to_single_stage_lockfile(stage) == OrderedDict(
153173
[
154174
("cmd", "command"),
@@ -158,7 +178,8 @@ def test_dump_appropriate_checksums(dvc):
158178
OrderedDict(
159179
[
160180
("path", "s3://dvc-temp/file"),
161-
("etag", "is-it-etag"),
181+
("etag", "etag-value"),
182+
("md5", "md5-value"),
162183
]
163184
)
164185
],

0 commit comments

Comments
 (0)