@@ -23,9 +23,9 @@ def write_provider_preset(provider_directory: Path, data: CMakeSyncData) -> None
23
23
24
24
json_path = provider_directory / f'{ data .provider_name } .json'
25
25
26
- serialized = json . loads ( presets .model_dump_json (exclude_none = True , by_alias = False ) )
26
+ serialized = presets .model_dump_json (exclude_none = True , by_alias = False , indent = 4 )
27
27
with open (json_path , 'w' , encoding = 'utf8' ) as file :
28
- json . dump (serialized , file , ensure_ascii = False , indent = 4 )
28
+ file . write (serialized )
29
29
30
30
@staticmethod
31
31
def write_cppython_preset (
@@ -44,9 +44,9 @@ def write_cppython_preset(
44
44
45
45
cppython_json_path = cppython_preset_directory / 'cppython.json'
46
46
47
- serialized = json . loads ( presets .model_dump_json (exclude_none = True , by_alias = False ) )
47
+ serialized = presets .model_dump_json (exclude_none = True , by_alias = False , indent = 4 )
48
48
with open (cppython_json_path , 'w' , encoding = 'utf8' ) as file :
49
- json . dump (serialized , file , ensure_ascii = False , indent = 4 )
49
+ file . write (serialized )
50
50
51
51
return cppython_json_path
52
52
@@ -63,8 +63,12 @@ def write_root_presets(preset_file: Path, _: Path) -> None:
63
63
preset_file: Preset file to modify
64
64
"""
65
65
with open (preset_file , encoding = 'utf-8' ) as file :
66
- initial_root_preset = json . load ( file )
66
+ initial_json = file . read ( )
67
67
68
+ initial_root_preset = CMakePresets .model_validate_json (initial_json )
69
+
70
+ # Only write the file if the contents have changed
68
71
if (root_preset := deepcopy (initial_root_preset )) != initial_root_preset :
69
72
with open (preset_file , 'w' , encoding = 'utf-8' ) as file :
70
- json .dump (root_preset , file , ensure_ascii = False , indent = 4 )
73
+ preset = root_preset .model_dump_json (exclude_none = True , indent = 4 )
74
+ file .write (preset )
0 commit comments