(data, stream)
| 39 | |
| 40 | |
| 41 | def _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 | |
| 78 | def dump_py(path, data, fs=None): |
nothing calls this directly
no test coverage detected