MCPcopy
hub / github.com/treeverse/dvc / _dump

Function _dump

dvc/utils/serialize/_py.py:41–75  ·  view source on GitHub ↗
(data, stream)

Source from the content-addressed store, hash-verified

39
40
41def _dump(data, stream):
42 old_params = data[_PARAMS_KEY]
43 new_params = {
44 key: value
45 for key, value in data.items()
46 if key not in [_PARAMS_KEY, _PARAMS_TEXT_KEY]
47 }
48 old_lines = data[_PARAMS_TEXT_KEY].splitlines(True)
49
50 def _update_lines(lines, old_dct, new_dct):
51 for key, value in new_dct.items():
52 if isinstance(value, dict):
53 lines = _update_lines(lines, old_dct[key], value)
54 elif value != old_dct[key]["value"]:
55 lineno = old_dct[key]["lineno"]
56 lines[lineno] = lines[lineno].replace(
57 f" = {old_dct[key]['value']}", f" = {value}"
58 )
59 else:
60 continue
61 return lines
62
63 new_lines = _update_lines(old_lines, old_params, new_params)
64 new_text = "".join(new_lines)
65
66 try:
67 ast.parse(new_text)
68 except SyntaxError:
69 raise PythonFileCorruptedError( # noqa: B904
70 stream.name,
71 "Python file structure is corrupted after update params",
72 )
73
74 stream.write(new_text)
75 stream.close()
76
77
78def dump_py(path, data, fs=None):

Callers

nothing calls this directly

Calls 7

_update_linesFunction · 0.85
itemsMethod · 0.80
joinMethod · 0.80
parseMethod · 0.80
writeMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected